Index: Migration/Core/src/Migration.Core.Storage/VersionedFileMigrator.cs
===================================================================
diff -u -r56e690b056dd0901609e651f6ac3c010d3d002b7 -ra0ba05cc7fe3a39771fd92e49299c5359b43e755
--- Migration/Core/src/Migration.Core.Storage/VersionedFileMigrator.cs (.../VersionedFileMigrator.cs) (revision 56e690b056dd0901609e651f6ac3c010d3d002b7)
+++ Migration/Core/src/Migration.Core.Storage/VersionedFileMigrator.cs (.../VersionedFileMigrator.cs) (revision a0ba05cc7fe3a39771fd92e49299c5359b43e755)
@@ -74,8 +74,17 @@
/// The version to upgrade to.
/// true if needs to be upgraded to ,
/// false otherwise.
+ /// Thrown when any of the input parameters is null.
public bool NeedsMigrate(IVersionedFile versionedFile, string toVersion)
{
+ if (versionedFile == null)
+ {
+ throw new ArgumentNullException(nameof(versionedFile));
+ }
+ if (toVersion == null)
+ {
+ throw new ArgumentNullException(nameof(toVersion));
+ }
return versionedFileComparer.Compare(versionedFile.GetVersion(), toVersion) < 0;
}
Index: Migration/Core/test/Migration.Core.Storage.Test/Migration.Core.Storage.Test.csproj
===================================================================
diff -u -rb8840cf07edde26dd418270ae5547976d7e85d03 -ra0ba05cc7fe3a39771fd92e49299c5359b43e755
--- Migration/Core/test/Migration.Core.Storage.Test/Migration.Core.Storage.Test.csproj (.../Migration.Core.Storage.Test.csproj) (revision b8840cf07edde26dd418270ae5547976d7e85d03)
+++ Migration/Core/test/Migration.Core.Storage.Test/Migration.Core.Storage.Test.csproj (.../Migration.Core.Storage.Test.csproj) (revision a0ba05cc7fe3a39771fd92e49299c5359b43e755)
@@ -74,6 +74,10 @@
{D08DB9E2-6861-44C8-A725-71A70274CC77}
Migration.Scripts.Data
+
+ {E4B36055-A984-4D40-9A70-34354054FE46}
+ Migration.Scripts.Data.TestUtil
+
{EFD7E662-5B69-4B71-A448-565B64E9C033}
Migration.Core.Storage
Index: Migration/Core/test/Migration.Core.Storage.Test/VersionedFileMigratorTest.cs
===================================================================
diff -u -rb8840cf07edde26dd418270ae5547976d7e85d03 -ra0ba05cc7fe3a39771fd92e49299c5359b43e755
--- Migration/Core/test/Migration.Core.Storage.Test/VersionedFileMigratorTest.cs (.../VersionedFileMigratorTest.cs) (revision b8840cf07edde26dd418270ae5547976d7e85d03)
+++ Migration/Core/test/Migration.Core.Storage.Test/VersionedFileMigratorTest.cs (.../VersionedFileMigratorTest.cs) (revision a0ba05cc7fe3a39771fd92e49299c5359b43e755)
@@ -19,10 +19,11 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections;
-using System.Linq;
-using Migration.Core.Storage.TestUtil;
+using System.Collections.Generic;
using Migration.Scripts.Data;
+using Migration.Scripts.Data.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
@@ -32,23 +33,123 @@
public class VersionedFileMigratorTest
{
[Test]
+ public void Constructor_ComparerNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new SimpleVersionedFileMigrator(null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("comparer", paramName);
+ }
+
+ [Test]
[TestCase("")]
[TestCase(null)]
- public void IsVersionSupported_ToVersionIsNullOrWhiteSpace_ReturnsFalse(string toVersion)
+ public void IsVersionSupported_FromVersionIsNullOrWhiteSpace_ReturnsFalse(string fromVersion)
{
// Setup
var mockRepository = new MockRepository();
var comparer = mockRepository.Stub();
mockRepository.ReplayAll();
- var migrator = new TestVersionedFileMigrator(comparer, Enumerable.Empty(),
- Enumerable.Empty());
+ var migrator = new SimpleVersionedFileMigrator(comparer);
// Call
- bool isSupported = migrator.IsVersionSupported(toVersion);
+ bool isSupported = migrator.IsVersionSupported(fromVersion);
// Assert
Assert.IsFalse(isSupported);
mockRepository.VerifyAll();
}
+
+ [Test]
+ [TestCase("true", true)]
+ [TestCase("false", false)]
+ public void IsVersionSupported_ValidFromVersion_ReturnsIfSupported(string fromVersion, bool shouldSupport)
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var comparer = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ string toVersion = "1";
+ var migrator = new SimpleVersionedFileMigrator(comparer)
+ {
+ CreateScripts =
+ {
+ new TestCreateScript(toVersion)
+ },
+ UpgradeScripts =
+ {
+ new TestUpgradeScript("true", toVersion)
+ }
+ };
+
+ // Call
+ bool isSupported = migrator.IsVersionSupported(fromVersion);
+
+ // Assert
+ Assert.AreEqual(shouldSupport, isSupported);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void NeedsMigrate_VersionedFileNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var comparer = mockRepository.Stub();
+ mockRepository.ReplayAll();
+ var migrator = new SimpleVersionedFileMigrator(comparer);
+
+ // Call
+ TestDelegate call = () => migrator.NeedsMigrate(null, "");
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("versionedFile", paramName);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void NeedsMigrate_ToVersionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var comparer = mockRepository.Stub();
+ var versionedFile = mockRepository.Stub();
+ mockRepository.ReplayAll();
+ var migrator = new SimpleVersionedFileMigrator(comparer);
+
+ // Call
+ TestDelegate call = () => migrator.NeedsMigrate(versionedFile, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("toVersion", paramName);
+ mockRepository.VerifyAll();
+ }
+
+ private class SimpleVersionedFileMigrator : VersionedFileMigrator
+ {
+ public SimpleVersionedFileMigrator(IComparer comparer) : base(comparer)
+ {
+ UpgradeScripts = new List();
+ CreateScripts = new List();
+ }
+
+ public List UpgradeScripts { get; }
+ public List CreateScripts { get; }
+
+ protected override IEnumerable GetAvailableUpgradeScripts()
+ {
+ return UpgradeScripts;
+ }
+
+ protected override IEnumerable GetAvailableCreateScripts()
+ {
+ return CreateScripts;
+ }
+ }
}
}
\ No newline at end of file