Esempio n. 1
0
        public void ShouldThrowExceptionIfAccessorRefersToNonProperty_HasChanges()
        {
            var        detector = new TestEntityChangeDetector();
            TestEntity original = new TestEntity();
            TestEntity updated  = new TestEntity();

            detector.HasChange(e => e.Field, original, updated);
        }
Esempio n. 2
0
        public void ShouldReturnFalseIfCheckingIfUnconfiguredPropertyChanged()
        {
            var        detector = new TestEntityChangeDetector();
            TestEntity original = new TestEntity();
            TestEntity updated  = new TestEntity();

            bool hasChange = detector.HasChange(a => a.NotConfigured, original, updated);

            Assert.IsFalse(hasChange, "A change should not be detected if the property is not recognized.");
        }
Esempio n. 3
0
        public void ShouldThrowExceptionIfAccessorNull_HasChanges()
        {
            var        detector = new TestEntityChangeDetector();
            TestEntity original = new TestEntity();
            TestEntity updated  = new TestEntity();

            Expression <Func <TestEntity, int> > accessor = null;

            detector.HasChange(accessor, original, updated);
        }
Esempio n. 4
0
        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.");
        }