Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsUpgradeScriptTest.cs =================================================================== diff -u -r090bf03ca13a96b9e7c0a71b89f6853c303f7c02 -r5c75bf291d688c7af57455794b412b8b35aeb03b --- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsUpgradeScriptTest.cs (.../RingtoetsUpgradeScriptTest.cs) (revision 090bf03ca13a96b9e7c0a71b89f6853c303f7c02) +++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsUpgradeScriptTest.cs (.../RingtoetsUpgradeScriptTest.cs) (revision 5c75bf291d688c7af57455794b412b8b35aeb03b) @@ -20,8 +20,10 @@ // All rights reserved. using System; +using System.Data; using System.Data.SQLite; using System.IO; +using Core.Common.IO.Readers; using Core.Common.TestUtil; using Migration.Scripts.Data; using NUnit.Framework; @@ -102,19 +104,37 @@ } [Test] + public void Upgrade_ActualQueries_ExpectedProperties() + { + // Setup + var createScript = new RingtoetsCreateScript("2", "CREATE TABLE 'MigrationScript' ('Field' TEXT NOT NULL);"); + var upgradeScript = new RingtoetsUpgradeScript("1", "2", "INSERT INTO 'MigrationScript' SELECT '{0}';"); + var migrationScript = new FileMigrationScript(createScript, upgradeScript); + var versionedFile = new RingtoetsVersionedFile("c:\\file.ext"); + + // Call + IVersionedFile upgradedFile = migrationScript.Upgrade(versionedFile); + + // Assert + Assert.IsNotNull(upgradedFile); + + Assert.IsTrue(File.Exists(upgradedFile.Location)); + using (var msdr = new MigrationScriptDatabaseReader(upgradedFile.Location)) + { + Assert.IsTrue(msdr.IsValueInserted(versionedFile.Location)); + } + using (new FileDisposeHelper(upgradedFile.Location)) {} + } + + [Test] public void Upgrade_UpgradeFails_ThrowsSQLiteException() { // Setup string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, filename); - var mockRepository = new MockRepository(); - var sourceVersionedFile = mockRepository.Stub(); - sourceVersionedFile.Expect(tvf => tvf.Location).Return("c:\\file.ext"); - var targetVersionedFile = mockRepository.Stub(); - targetVersionedFile.Expect(tvf => tvf.Location).Return(filePath); - mockRepository.ReplayAll(); - + var sourceVersionedFile = new RingtoetsVersionedFile("c:\\file.ext"); + var targetVersionedFile = new RingtoetsVersionedFile("c:\\file.ext"); var upgradeScript = new RingtoetsUpgradeScript("1", "2", "THIS WILL FAIL"); // Call @@ -125,7 +145,6 @@ { Assert.Throws(call); } - mockRepository.VerifyAll(); } [Test] @@ -155,5 +174,31 @@ } mockRepository.VerifyAll(); } + + private class MigrationScriptDatabaseReader : SqLiteDatabaseReaderBase + { + public MigrationScriptDatabaseReader(string filePath) : base(filePath) {} + + public bool IsValueInserted(string value) + { + const string query = "SELECT FIELD FROM 'MigrationScript';"; + try + { + using (IDataReader dataReader = CreateDataReader(query, null)) + { + if (!dataReader.Read()) + { + return false; + } + + return dataReader.Read("Field").Equals(value); + } + } + catch + { + return false; + } + } + } } } \ No newline at end of file