Exemple #1
0
        public void service_getChangeSet_returns_valid_cSet()
        {
            int expected = 3;
            int actual   = 0;

            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

            p.Add(new Person(null, false));
            p.Add(new Person(null, false));
            p.Move(0, 1);

            IChangeSet cSet = svc.GetChangeSet();

            actual = cSet.Count;

            Assert.AreEqual <int>(expected, actual);
        }
Exemple #2
0
        public void changeTrackingService_using_beginAtomicOperation_should_set_is_changed_only_on_operation_completed()
        {
            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";

                target.IsChanged.Should().Be.False();

                actual.Complete();
            }

            target.IsChanged.Should().Be.True();
        }
Exemple #3
0
        public void changeTrackingService_using_beginAtomicOperation_getEntityState_should_return_valid_entity_state()
        {
            var target = new ChangeTrackingService();

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

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

                op.Complete();
            }

            var actual = target.GetEntityState(person);

            actual.Should().Be.EqualTo(EntityTrackingStates.HasBackwardChanges | EntityTrackingStates.IsTransient | EntityTrackingStates.AutoRemove);
        }
Exemple #4
0
        public void changeTrackingService_using_beginAtomicOperation_should_fully_rollback_on_single_undo()
        {
            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();

            list.Count.Should().Be.EqualTo(0);
            person.Name.Should().Be.EqualTo(string.Empty);
        }
Exemple #5
0
        public void changeTrackingService_using_beginAtomicOperation_hasTransientEntities_should_return_true_even_for_entities_created_in_the_atomic_operation()
        {
            var target = new ChangeTrackingService();

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

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

                op.Complete();
            }

            var actual = target.HasTransientEntities;

            actual.Should().Be.True();
        }
Exemple #6
0
        public void changeTrackingService_using_beginAtomicOperation_getEntities_should_return_all_transient_entities()
        {
            var target = new ChangeTrackingService();

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

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

                op.Complete();
            }

            var actual = target.GetEntities(EntityTrackingStates.IsTransient, false);

            actual.Contains(person).Should().Be.True();
        }
Exemple #7
0
        public void service_redoes_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);

            while (svc.CanUndo)
            {
                svc.Undo();
            }

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

            svc.Redo();
            Assert.AreEqual <int>(2, list.Count);
            Assert.IsTrue(list.Contains(p2));

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

            svc.Redo();
            Assert.AreEqual <int>(0, list.IndexOf(p2));

            svc.Redo();
            Assert.AreEqual <int>(2, list.Count);
            Assert.IsFalse(list.Contains(p1));
        }
Exemple #8
0
        public void changeTrackingService_using_beginAtomicOperation_redo_should_reapply_all_changes_with_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();

            list.Count.Should().Be.EqualTo(1);
            person.Name.Should().Be.EqualTo("Mauro Servienti");
        }
Exemple #9
0
        public void changeTrackingService_using_beginAtomicOperation_getEntities_should_return_all_changed_entities()
        {
            var target = new ChangeTrackingService();

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

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

                op.Complete();
            }

            var actual = target.GetEntities(EntityTrackingStates.HasBackwardChanges, false);

            /*
             * Non funziona perchè non funziona GetEntityState()
             */

            actual.Contains(person).Should().Be.True();
        }