public void ShouldNotDetectChange_OriginalAndUpdatedNull() { var detector = new TestEntityChangeDetector(); TestEntity original = null; TestEntity updated = null; Assert.IsFalse(detector.HasChange(a => a.StringValue, original, updated), "Change detected for the property."); var changes = detector.GetChanges(original, updated); Assert.AreEqual(0, changes.Count(), "The wrong number of changes were detected."); }
public void ShouldDetectChange_UpdatedNull() { var detector = new TestEntityChangeDetector(); TestEntity original = new TestEntity() { StringValue = "After" }; TestEntity updated = null; Assert.IsTrue(detector.HasChange(a => a.StringValue, original, updated), "No change detected for the property."); var changes = detector.GetChanges(original, updated); Assert.AreEqual(1, changes.Count(), "The wrong number of changes were detected."); IPropertyChange change = changes.Single(); Assert.AreEqual(TestEntityChangeDetector.StringDescription, change.DisplayName, "The wrong property was recorded."); Assert.AreEqual(Formatters.FormatString(original.StringValue), change.FormatOriginalValue(), "The old value was not recorded."); Assert.AreEqual(null, change.FormatUpdatedValue(), "The new value was not recorded."); }
public void ShouldDetectAllChanges() { var detector = new TestEntityChangeDetector(); TestEntity original = new TestEntity() { BooleanValue = false, DateTimeValue = new DateTime(2015, 07, 29), GuidValue = Guid.NewGuid(), IntValue = 123, MoneyValue = 12.34m, PercentValue = 12.5m, StringValue = "Hello" }; TestEntity updated = new TestEntity() { BooleanValue = true, DateTimeValue = new DateTime(2015, 07, 30), GuidValue = Guid.NewGuid(), IntValue = 234, MoneyValue = 10m, PercentValue = 15m, StringValue = "Goodbye" }; Assert.IsTrue(detector.HasChange(e => e.BooleanValue, original, updated), "Boolean value should be changed."); Assert.IsTrue(detector.HasChange(e => e.DateTimeValue, original, updated), "DateTime value should be changed."); Assert.IsTrue(detector.HasChange(e => e.GuidValue, original, updated), "Guid value should be changed."); Assert.IsTrue(detector.HasChange(e => e.IntValue, original, updated), "Int value should be changed."); Assert.IsTrue(detector.HasChange(e => e.MoneyValue, original, updated), "Money value should be changed."); Assert.IsTrue(detector.HasChange(e => e.PercentValue, original, updated), "Percent value should be changed."); Assert.IsTrue(detector.HasChange(e => e.StringValue, original, updated), "String value should be changed."); var changes = detector.GetChanges(original, updated); Assert.AreEqual(7, changes.Count(), "The wrong number of changes were detected."); }