コード例 #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 entityMemento_isTracking_with_service_and_registerAsTransient_false_should_be_true()
        {
            var memento = new ChangeTrackingService();
            var target  = new TestableMementoEntity(memento, false);

            target.GetIsTracking().Should().Be.True();
        }
コード例 #4
0
        public void entityMemento_isTracking_with_service_should_be_true()
        {
            var memento = new ChangeTrackingService();
            var target  = new TestableMementoEntity(memento);

            target.GetIsTracking().Should().Be.True();
        }
コード例 #5
0
        public void service_on_clear_generate_valid_advisory()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            svc.AcceptChanges();

            p.Clear();

            IEnumerable <IAdvisedAction> advisory = svc.GetAdvisory();

            Assert.IsNotNull(advisory);
            Assert.AreEqual <int>(5, advisory.Count());
            foreach (var aa in advisory)
            {
                Assert.AreEqual <ProposedActions>(ProposedActions.Delete, aa.Action);
            }
        }
コード例 #6
0
        public void changeTrackingService_beginAtomicOperation_normal_should_create_valid_atomic_operation()
        {
            var target = new ChangeTrackingService();
            var actual = target.BeginAtomicOperation();

            actual.Should().Not.Be.Null();
        }
コード例 #7
0
        public void entityMemento_memento_changing_on_disposed_entity_using_base_iMemento_should_raise_ObjectDisposedException()
        {
            var memento = new ChangeTrackingService();
            var target  = new TestableMementoEntity(memento);

            target.Dispose();
            ((IMemento)target).Memento = null;
        }
コード例 #8
0
        public void Instance_NoObjectsAdded_HasChangesIsFalse()
        {
            _InitializeDependencies();

            var target = new ChangeTrackingService();

            Assert.IsFalse(target.HasChanges);
        }
コード例 #9
0
        public void Instance_IsCreated_EventPublisherIsImported()
        {
            _InitializeDependencies();

            var target = new ChangeTrackingService();

            Assert.IsNotNull(target.EventPublisher);
        }
コード例 #10
0
        public void unchangedEntity_service_isChanged_is_false()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

            Assert.IsFalse(svc.IsChanged);
        }
コード例 #11
0
        public void entityMemento_ctor_memento_registerAsTransient_true_set_default_values()
        {
            var expected = new ChangeTrackingService();
            var target   = new FakeMementoEntity(expected, true);

            ((IMemento)target).Memento.Should().Be.EqualTo(expected);
            ((IMemento)target).Memento.Should().Be.EqualTo(expected);
        }
コード例 #12
0
        public void entityMemento_chacheChange_value_rejectCallback_commitCallback_addChangeBeahvior_should_be_called()
        {
            var memento = new ChangeTrackingService();
            var target  = new TestableMementoEntity(memento);

            var change = target.InvokeCacheChange("Foo", cv => { }, cv => { }, AddChangeBehavior.Default);

            change.Should().Not.Be.Null();
        }
コード例 #13
0
        public void entityMemento_chacheChange_value_rejectCallback_commitCallback_addChangeBeahvior_on_disposed_object_should_raise_ObjectDisposedException()
        {
            var memento = new ChangeTrackingService();
            var target  = new TestableMementoEntity(memento);

            target.Dispose();

            target.InvokeCacheChange("Foo", cv => { }, cv => { }, AddChangeBehavior.Default);
        }
コード例 #14
0
        public void after_Add_canUndo_is_true()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            svc.CanUndo.Should().Be.True();
        }
コード例 #15
0
        public void after_change_canRedo_is_false()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            Assert.IsFalse(svc.CanRedo);
        }
コード例 #16
0
        public void entityMemento_isTracking_with_suspended_serviceand_registerAsTransient_true_should_be_false()
        {
            var memento = new ChangeTrackingService();

            memento.Suspend();

            var target = new TestableMementoEntity(memento, true);

            target.GetIsTracking().Should().Be.False();
        }
コード例 #17
0
        public void unchangedEntity_service_getEntityState_is_None()
        {
            EntityTrackingStates expected = EntityTrackingStates.None;

            ChangeTrackingService svc = new ChangeTrackingService();
            PersonCollection      p   = new PersonCollection(svc);

            EntityTrackingStates actual = svc.GetEntityState(p);

            Assert.AreEqual <EntityTrackingStates>(expected, actual);
        }
コード例 #18
0
        public void entityMemento_memento_using_base_iMemento_succesfully_set_and_get_memento_reference()
        {
            var expected = new ChangeTrackingService();

            var target = new FakeMementoEntity();

            ((IMemento)target).Memento = expected;
            var actual = ((IMemento)target).Memento;

            actual.Should().Be.EqualTo(expected);
        }
コード例 #19
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);
        }
コード例 #20
0
        public void entityMemento_chacheChange_value_rejectCallback_commitCallback_addChangeBeahvior_should_be_called_with_expected_values()
        {
            var memento = new ChangeTrackingService();
            var target  = new TestableMementoEntity(memento);

            var change = target.InvokeCacheChange("Foo", cv => { }, cv => { }, AddChangeBehavior.Default);

            change.IsCommitSupported.Should().Be.True();
            change.Owner.Should().Be.EqualTo(target);
            change.Description.Should().Be.EqualTo(string.Empty);
        }
コード例 #21
0
        public void after_mutual_exclusive_actions_service_CanUndo()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            Assert.IsTrue(svc.CanUndo);
        }
コード例 #22
0
        public void after_acceptChanges_service_canUndo_is_false()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            svc.AcceptChanges();

            Assert.IsFalse(svc.CanUndo);
        }
コード例 #23
0
        public void entityMemento_chacheChange_value_rejectCallback_commitCallback_with_suspended_service_should_not_be_called()
        {
            var memento = new ChangeTrackingService();

            memento.Suspend();

            var target = new TestableMementoEntity(memento);

            var change = target.InvokeCacheChange("Foo", cv => { }, cv => { });

            change.Should().Be.Null();
        }
コード例 #24
0
        public void after_rejectChanges_service_isChanged_is_false()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            svc.RejectChanges();

            Assert.IsFalse(svc.IsChanged);
        }
コード例 #25
0
        public void after_Add_getChangeSet_contains_change()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            IChangeSet cSet = svc.GetChangeSet();

            cSet.Count.Should().Be.EqualTo(2);
        }
        /// <summary>
        /// Sets the <see cref="IsChanged"/> flag to true manually.
        /// </summary>
        public void SetChanged()
        {
            // the order of these two operations is important
            // to keep the service in a consistent state
            IsChanged = true;

            if (ChangeTrackingService != null)
            {
                ChangeTrackingService.Add(this);
            }

            OnSetChanged();
        }
コード例 #27
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);
        }
コード例 #28
0
        public void service_on_single_add_generate_valid_advisory_even_with_transient_persistable_entity()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

            p.Add(new Person(null, ChangeTrackingRegistration.AsTransient, TransientRegistration.AsPersistable));

            IEnumerable <IAdvisedAction> advisory = svc.GetAdvisory();

            Assert.IsNotNull(advisory);
            Assert.AreEqual <int>(1, advisory.Count());
            Assert.AreEqual <ProposedActions>(ProposedActions.Create, advisory.First().Action);
        }
コード例 #29
0
        public void service_on_single_add_generate_valid_advisory()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection(svc);

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

            IEnumerable <IAdvisedAction> advisory = svc.GetAdvisory();

            Assert.IsNotNull(advisory);
            Assert.AreEqual <int>(1, advisory.Count());
            Assert.AreEqual <ProposedActions>(ProposedActions.Update, advisory.First().Action);
        }
コード例 #30
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);
        }