예제 #1
0
        public void Reset_HasChangesTrue_ResetsAllchanges()
        {
            var removeMe         = new TestItem();
            var expectedOldValue = "My old value";
            var expectedNewValue = "The new value";
            var expectedUpdate   = new TestItem
            {
                StringValue = expectedOldValue
            };
            var expectedItems = new List <TestItem>
            {
                removeMe,
                expectedUpdate
            };
            var subject = new ChangeTrackingCollection <TestItem>(expectedItems);

            expectedUpdate.StringValue = expectedNewValue;
            subject.Add(new TestItem());
            subject.Remove(removeMe);

            subject.Reset();

            Assert.False(subject.HasChanges);
            var changes = subject.GetChangeSet(ChangePath.Empty);

            Assert.Null(changes);
            Assert.False(expectedUpdate.HasChanges);
        }
예제 #2
0
        public void GetChangeSet_CommitTrue_MakesChangesPermanent()
        {
            var removeMe       = ChangeTrackingObject.CreateTrackable <TestItem>();
            var expectedUpdate = ChangeTrackingObject.CreateTrackable <TestItem>();
            var expectedItems  = new List <TestItem>
            {
                removeMe,
                expectedUpdate
            };
            var subject = new ChangeTrackingCollection <TestItem>(expectedItems);

            subject.Add(new TestItem());
            subject.Remove(removeMe);
            var expectedNewValue = "New Value";

            expectedUpdate.StringValue = expectedNewValue;

            var result = subject.GetChangeSet(ChangePath.Empty, commit: true);

            Assert.Equal(3, result.Count);
            Assert.False(subject.HasChanges);
            Assert.False(expectedUpdate.HasChanges);
            Assert.Equal(expectedNewValue, expectedUpdate.StringValue);
            Assert.DoesNotContain(removeMe, subject);
            Assert.Equal(2, subject.Count);
        }
예제 #3
0
        public void GetChangeSet_CommitFalse_ContainsUpdates()
        {
            var expectedOldValue = "My old value";
            var expectedNewValue = "The new value";
            var expectedUpdate   = new TestItem
            {
                StringValue = expectedOldValue
            };
            var expectedItems = new List <TestItem>
            {
                new TestItem(),
                expectedUpdate,
                new TestItem()
            };
            var subject      = new ChangeTrackingCollection <TestItem>(expectedItems);
            var path         = ChangePath.Create("path");
            var expectedPath = path.AppendIndex(1).AppendProperty(nameof(TestItem.StringValue));

            expectedUpdate.StringValue = expectedNewValue;
            var result = subject.GetChangeSet(path);

            Assert.True(subject.HasChanges);
            Assert.NotNull(result);
            var kvp = Assert.Single(result);

            Assert.Equal(ChangeTarget.Object, kvp.Key.Target);
            Assert.Contains(expectedPath, result as IDictionary <ChangePath, List <ChangeValue> >);
            var values = result[expectedPath];
            var value  = Assert.Single(values);

            Assert.Equal(ChangeAction.Update, value.Action);
            Assert.Equal(expectedNewValue, value.NewValue);
            Assert.Equal(expectedOldValue, value.OldValue);
        }
예제 #4
0
        public void GetChangeSet_CommitFalse_ContainsRemoves()
        {
            var expectedRemove = new TestItem();
            var expectedItems  = new List <TestItem>
            {
                new TestItem(),
                expectedRemove,
                new TestItem()
            };
            var subject  = new ChangeTrackingCollection <TestItem>(expectedItems);
            var basePath = ChangePath.Create("path");

            Assert.True(subject.Remove(expectedRemove));
            var result       = subject.GetChangeSet(basePath);
            var expectedPath = basePath.AppendIndex(1);

            Assert.True(subject.HasChanges);
            Assert.NotNull(result);
            var kvp = Assert.Single(result);

            Assert.Equal(ChangeTarget.Collection, kvp.Key.Target);
            Assert.Contains(expectedPath, result as IDictionary <ChangePath, List <ChangeValue> >);
            var values = result[expectedPath];
            var value  = Assert.Single(values);

            Assert.Equal(ChangeAction.Remove, value.Action);
            Assert.Null(value.NewValue);
            Assert.Same(expectedRemove, value.OldValue);
        }
예제 #5
0
        public void GetChangeSet_AddAfterClear_Correct()
        {
            var expectedItems = new List <string>
            {
                "Value1",
                "Value2",
                "Value3"
            };
            var addItems = new List <string>
            {
                "Value1",
                "Value2",
                "Value3",
                "Value4"
            };
            var subject = new ChangeTrackingCollection <string>(expectedItems);

            subject.Clear();
            addItems.ForEach(item => subject.Add(item));
            var changes = subject.GetChangeSet(ChangePath.Empty);

            Assert.Single(changes);
            Assert.Single(changes.First().Value);
        }
예제 #6
0
        public void GetChangeSet_NullWhenNoChanges()
        {
            var subject = new ChangeTrackingCollection <TestItem>();

            Assert.Null(subject.GetChangeSet(ChangePath.Empty));
        }