Пример #1
0
        public void service_undoes_are_in_the_correct_order()
        {
            var p1 = new Person(null, false);
            var p2 = new Person(null, false);
            var p3 = new Person(null, false);

            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection list = new PersonCollection(svc);

            list.Add(p1);
            list.Add(p2);
            list.Add(p3);
            list.Move(p2, 0);
            list.Remove(p1);

            svc.Undo();
            Assert.AreEqual <int>(3, list.Count);
            Assert.IsTrue(list.Contains(p1));

            svc.Undo();
            Assert.AreEqual <int>(1, list.IndexOf(p2));

            svc.Undo();
            Assert.AreEqual <int>(2, list.Count);
            Assert.IsFalse(list.Contains(p3));

            svc.Undo();
            Assert.AreEqual <int>(1, list.Count);
            Assert.IsFalse(list.Contains(p2));

            svc.Undo();
            Assert.AreEqual <int>(0, list.Count);
            Assert.IsFalse(list.Contains(p1));
        }
Пример #2
0
        public void service_on_clear_undo_entities_are_restored()
        {
            var source = new Person[]
            {
                new Person(null, false),
                new Person(null, false),
                new Person(null, false),
                new Person(null, false),
                new Person(null, false)
            };

            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection list = new PersonCollection(svc);

            list.BeginInit();
            list.AddRange(source);
            list.EndInit();

            list.Clear();
            svc.Undo();

            Assert.AreEqual <int>(source.Length, list.Count());
            source.ForEach(p =>
            {
                int expected = Array.IndexOf(source, p);
                int actual   = list.IndexOf(p);

                Assert.AreEqual <int>(expected, actual);
            });
        }
Пример #3
0
        public void afterUndo_service_canRedo()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

            p.Add(new Person(null, false));
            svc.Undo();

            Assert.IsTrue(svc.CanRedo);
        }
Пример #4
0
        public void changeTrackingService_using_beginAtomicOperation_undo_redo_should_restore_in_one_pass()
        {
            var target = new ChangeTrackingService();

            var person = new Person(target);
            var list   = new PersonCollection(target);

            using (var actual = target.BeginAtomicOperation())
            {
                person.Name = "Mauro";
                list.Add(person);
                person.Name = "Mauro Servienti";

                actual.Complete();
            }

            target.Undo();
            target.Redo();
            target.Undo();

            list.Count.Should().Be.EqualTo(0);
            person.Name.Should().Be.EqualTo(string.Empty);
        }
Пример #5
0
        public void after_Undo_collection_is_rolledback()
        {
            int expected = 0;

            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

            p.Add(new Person(svc, false));

            svc.Undo();

            p.Count.Should().Be.EqualTo(expected);
        }
Пример #6
0
        public void afterUndo_service_Redo_restore_previous_value()
        {
            ChangeTrackingService svc = new ChangeTrackingService();
            int expected = 1;

            PersonCollection p = new PersonCollection(svc);

            p.Add(new Person(null, false));

            svc.Undo();
            svc.Redo();

            Assert.AreEqual <int>(expected, p.Count);
        }
Пример #7
0
        public void mementoEntity_using_trackingService_should_undo_a_single_change()
        {
            var memento = new ChangeTrackingService();

            var target = new MementoMockEntity();

            ((IMemento)target).Memento = memento;

            target.FirstName = "Mauro";

            memento.Undo();

            target.FirstName.Should().Be.Null();
        }
Пример #8
0
        public void mementoEntity_using_trackingService_should_undo_and_redo_a_single_change()
        {
            var expected = "Mauro";

            var memento = new ChangeTrackingService();

            var target = new MementoMockEntity();

            ((IMemento)target).Memento = memento;

            target.FirstName = expected;

            memento.Undo();
            memento.Redo();

            target.FirstName.Should().Be.EqualTo(expected);
        }