Index: Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsUpgradeScript.cs =================================================================== diff -u -r74c998ad1d6edfc4fff8872438a84a5bd9cb0d98 -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsUpgradeScript.cs (.../RingtoetsUpgradeScript.cs) (revision 74c998ad1d6edfc4fff8872438a84a5bd9cb0d98) +++ Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsUpgradeScript.cs (.../RingtoetsUpgradeScript.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -56,12 +56,12 @@ upgradeQuery = query; } - protected override void PerformUpgrade(IVersionedFile source, IVersionedFile target) + protected override void PerformUpgrade(string sourceLocation, string targetLocation) { try { - var query = string.Format(upgradeQuery, source.Location); - using (var databaseFile = new RingtoetsDatabaseFile(target.Location)) + var query = string.Format(upgradeQuery, sourceLocation); + using (var databaseFile = new RingtoetsDatabaseFile(targetLocation)) { databaseFile.OpenDatabaseConnection(); databaseFile.ExecuteQuery(query); Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsUpgradeScriptTest.cs =================================================================== diff -u -rc0840b3d3dbdbfdcad2a6f55c117ac22ae95b365 -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsUpgradeScriptTest.cs (.../RingtoetsUpgradeScriptTest.cs) (revision c0840b3d3dbdbfdcad2a6f55c117ac22ae95b365) +++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsUpgradeScriptTest.cs (.../RingtoetsUpgradeScriptTest.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -134,12 +134,10 @@ string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, filename); - var sourceVersionedFile = new RingtoetsVersionedFile("c:\\file.ext"); - var targetVersionedFile = new RingtoetsVersionedFile("c:\\file.ext"); var upgradeScript = new RingtoetsUpgradeScript("1", "2", "THIS WILL FAIL"); // Call - TestDelegate call = () => upgradeScript.Upgrade(sourceVersionedFile, targetVersionedFile); + TestDelegate call = () => upgradeScript.Upgrade("c:\\file.ext", "c:\\file.ext"); // Assert using (new FileDisposeHelper(filePath)) @@ -158,25 +156,16 @@ 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 upgradeScript = new RingtoetsUpgradeScript("1", "2", ";"); // Call - upgradeScript.Upgrade(sourceVersionedFile, targetVersionedFile); + upgradeScript.Upgrade("c:\\file.ext", filePath); // Assert - Assert.IsNotNull(targetVersionedFile); using (new FileDisposeHelper(filePath)) { Assert.IsTrue(File.Exists(filePath)); } - mockRepository.VerifyAll(); } private class MigrationScriptDatabaseReader : SqLiteDatabaseReaderBase Index: Migration/Scripts/src/Migration.Scripts.Data/FileMigrationScript.cs =================================================================== diff -u -r74c998ad1d6edfc4fff8872438a84a5bd9cb0d98 -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Migration/Scripts/src/Migration.Scripts.Data/FileMigrationScript.cs (.../FileMigrationScript.cs) (revision 74c998ad1d6edfc4fff8872438a84a5bd9cb0d98) +++ Migration/Scripts/src/Migration.Scripts.Data/FileMigrationScript.cs (.../FileMigrationScript.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -87,7 +87,7 @@ var newLocation = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); IVersionedFile newVersionedFile = createScript.CreateEmptyVersionedFile(newLocation); - upgradeScript.Upgrade(sourceVersionedFile, newVersionedFile); + upgradeScript.Upgrade(sourceVersionedFile.Location, newVersionedFile.Location); return newVersionedFile; } } Index: Migration/Scripts/src/Migration.Scripts.Data/UpgradeScript.cs =================================================================== diff -u -r74c998ad1d6edfc4fff8872438a84a5bd9cb0d98 -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Migration/Scripts/src/Migration.Scripts.Data/UpgradeScript.cs (.../UpgradeScript.cs) (revision 74c998ad1d6edfc4fff8872438a84a5bd9cb0d98) +++ Migration/Scripts/src/Migration.Scripts.Data/UpgradeScript.cs (.../UpgradeScript.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Core.Common.Utils; using Migration.Scripts.Data.Exceptions; namespace Migration.Scripts.Data @@ -76,36 +77,34 @@ } /// - /// Uses to upgrade to . + /// Uses to upgrade to . /// - /// The source file to upgrade from. - /// The target file to upgrade to. - /// Thrown when: + /// The source file to upgrade from. + /// The target file to upgrade to. + /// Thrown when or + /// is invalid. + /// A valid path: /// - /// is null, - /// is null. - /// + /// is not empty or null, + /// does not consist out of only whitespace characters, + /// does not contain an invalid character, + /// does not end with a directory or path separator (empty file name). + /// /// Thrown when upgrading failed. - public void Upgrade(IVersionedFile source, IVersionedFile target) + public void Upgrade(string sourceLocation, string targetLocation) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (target == null) - { - throw new ArgumentNullException(nameof(target)); - } - PerformUpgrade(source, target); + IOUtils.ValidateFilePath(sourceLocation); + IOUtils.ValidateFilePath(targetLocation); + PerformUpgrade(sourceLocation, targetLocation); } /// - /// Performs the upgrade on . + /// Performs the upgrade on . /// - /// The source file to upgrade from. - /// The target file to upgrade to. - /// The and has been verified in . + /// The source file to upgrade from. + /// The target file to upgrade to. + /// The and has been verified in . /// Thrown when upgrading failed. - protected abstract void PerformUpgrade(IVersionedFile source, IVersionedFile target); + protected abstract void PerformUpgrade(string sourceLocation, string targetLocation); } } \ No newline at end of file Index: Migration/Scripts/test/Migration.Scripts.Data.Test/FileMigrationScriptTest.cs =================================================================== diff -u -rf21480a6b28a6637ecab0e2dd3e75240cabd9c9a -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Migration/Scripts/test/Migration.Scripts.Data.Test/FileMigrationScriptTest.cs (.../FileMigrationScriptTest.cs) (revision f21480a6b28a6637ecab0e2dd3e75240cabd9c9a) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/FileMigrationScriptTest.cs (.../FileMigrationScriptTest.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -20,6 +20,8 @@ // All rights reserved. using System; +using System.IO; +using Core.Common.TestUtil; using Migration.Scripts.Data.TestUtil; using NUnit.Framework; using Rhino.Mocks; @@ -92,8 +94,12 @@ public void Upgrade_ValidParameters_ExpectedProperties() { // Setup + string targetFilename = Path.GetRandomFileName(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, targetFilename); + var mockRepository = new MockRepository(); var versionedFile = mockRepository.Stub(); + versionedFile.Expect(vf => vf.Location).Return(filePath); mockRepository.ReplayAll(); var createScript = new TestCreateScript("2"); Index: Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs =================================================================== diff -u -r26906345dc00fdf928cf38a1356bd1b251c79422 -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs (.../UpgradeScriptTest.cs) (revision 26906345dc00fdf928cf38a1356bd1b251c79422) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs (.../UpgradeScriptTest.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -22,7 +22,6 @@ using System; using Migration.Scripts.Data.TestUtil; using NUnit.Framework; -using Rhino.Mocks; namespace Migration.Scripts.Data.Test { @@ -77,45 +76,39 @@ } [Test] - public void Upgrade_SourceNull_ThrowsArgumentNullException() + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Upgrade_SourceNull_ThrowsArgumentException(string sourceFilePath) { // Setup - var mockRepository = new MockRepository(); - var targetVersionedFile = mockRepository.Stub(); - mockRepository.ReplayAll(); - const string fromVersion = "fromVersion"; const string toVersion = "toVersion"; var upgradeScript = new TestUpgradeScript(fromVersion, toVersion); // Call - TestDelegate call = () => upgradeScript.Upgrade(null, targetVersionedFile); + TestDelegate call = () => upgradeScript.Upgrade(sourceFilePath, "Filepath.ext"); // Assert - string paramName = Assert.Throws(call).ParamName; - Assert.AreEqual("source", paramName); - mockRepository.VerifyAll(); + Assert.Throws(call); } [Test] - public void Upgrade_TargetNull_ThrowsArgumentNullException() + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Upgrade_TargetNull_ThrowsArgumentException(string targetFilePath) { // Setup - var mockRepository = new MockRepository(); - var sourceVersionedFile = mockRepository.Stub(); - mockRepository.ReplayAll(); - const string fromVersion = "fromVersion"; const string toVersion = "toVersion"; var upgradeScript = new TestUpgradeScript(fromVersion, toVersion); // Call - TestDelegate call = () => upgradeScript.Upgrade(sourceVersionedFile, null); + TestDelegate call = () => upgradeScript.Upgrade("Filepath.ext", targetFilePath); // Assert - string paramName = Assert.Throws(call).ParamName; - Assert.AreEqual("target", paramName); - mockRepository.VerifyAll(); + Assert.Throws(call); } } } \ No newline at end of file Index: Migration/Scripts/test/Migration.Scripts.Data.TestUtil/TestUpgradeScript.cs =================================================================== diff -u -r26906345dc00fdf928cf38a1356bd1b251c79422 -r59e7b9604b09b292bf3b76c729751e7622d36bce --- Migration/Scripts/test/Migration.Scripts.Data.TestUtil/TestUpgradeScript.cs (.../TestUpgradeScript.cs) (revision 26906345dc00fdf928cf38a1356bd1b251c79422) +++ Migration/Scripts/test/Migration.Scripts.Data.TestUtil/TestUpgradeScript.cs (.../TestUpgradeScript.cs) (revision 59e7b9604b09b292bf3b76c729751e7622d36bce) @@ -38,9 +38,9 @@ /// is empty or null, /// is empty or null, /// - public TestUpgradeScript(string fromVersion, string toVersion) + public TestUpgradeScript(string fromVersion, string toVersion) : base(fromVersion, toVersion) {} - protected override void PerformUpgrade(IVersionedFile source, IVersionedFile target) {} + protected override void PerformUpgrade(string sourceLocation, string targetLocation) {} } } \ No newline at end of file