public void Event_WhenMigrationCompletesAndNoMigrationRequired_OnMigrationCompletedEventNotRaised() { //---------------Set up test pack------------------- itsDbMigrator.SetSettingsStorer(_itsSettings); _itsSettings.GetString(DBMigrator.DatabaseVersionSetting).Returns("2"); DBMigrator eventMigrator = null; DBMigratorEventArgs eventArgs = null; var onDbMigrationCompletedCalled = false; itsDbMigrator.OnDbMigrationCompleted += (s, e) => { onDbMigrationCompletedCalled = true; eventMigrator = s as DBMigrator; eventArgs = e; }; //---------------Assert Precondition---------------- Assert.IsNull(eventMigrator); Assert.IsNull(eventArgs); Assert.IsFalse(onDbMigrationCompletedCalled); //---------------Execute Test ---------------------- itsDbMigrator.MigrateTo(2); //---------------Test Result ----------------------- Assert.IsFalse(onDbMigrationCompletedCalled); Assert.IsNull(eventMigrator); Assert.IsNull(eventArgs); _itsSettings.DidNotReceive().SetString(DBMigrator.DatabaseVersionSetting, Arg.Any <string>()); }
public void Event_WhenMigrationCompletesAndMigrationIsRequired_OnMigrationCompletedEventRaised() { //---------------Set up test pack------------------- itsDbMigrator.SetSettingsStorer(_itsSettings); _itsSettings.GetString(DBMigrator.DatabaseVersionSetting).Returns("1"); DBMigrator eventMigrator = null; DBMigratorEventArgs eventArgs = null; itsDbMigrator.OnDbMigrationCompleted += (s, e) => { eventMigrator = s as DBMigrator; eventArgs = e; }; //---------------Assert Precondition---------------- Assert.IsNull(eventMigrator); Assert.IsNull(eventArgs); //---------------Execute Test ---------------------- itsDbMigrator.MigrateTo(2); //---------------Test Result ----------------------- Assert.IsNotNull(eventMigrator); Assert.AreEqual(itsDbMigrator, eventMigrator); Assert.IsNotNull(eventArgs); Assert.AreEqual(2, eventArgs.CurrentStep); _itsSettings.Received().SetString(DBMigrator.DatabaseVersionSetting, "2"); itsConn.Received().ExecuteSql(new SqlStatement(itsConn, "migration2;")); }
public void Constructor_SetsPercentageCompleteToCorrectValue(int start, int step, int total, decimal expectedPercentage) { //---------------Set up test pack------------------- var conn = Substitute.For <IDatabaseConnection>(); var migrator = new DBMigrator(conn); //---------------Assert Precondition---------------- Assert.IsNotNull(migrator); //---------------Execute Test ---------------------- var e = new DBMigratorEventArgs((uint)start, (uint)step, (uint)total); var propVal = e.PercentageComplete; //---------------Test Result ----------------------- Assert.AreEqual(expectedPercentage, propVal); }
public void Constructor_SetsCurrentStepToSpecifiedStep() { //---------------Set up test pack------------------- var conn = Substitute.For <IDatabaseConnection>(); var migrator = new DBMigrator(conn); var step = (uint)TestUtil.GetRandomInt(1, 50); var totalSteps = (uint)TestUtil.GetRandomInt((int)step, (int)step + 50); //---------------Assert Precondition---------------- Assert.AreNotEqual(0, step); Assert.IsNotNull(migrator); //---------------Execute Test ---------------------- var e = new DBMigratorEventArgs(1, step, totalSteps); var propVal = e.CurrentStep; //---------------Test Result ----------------------- Assert.AreEqual(step, propVal); }