Example #1
0
        private void WarmUpCache(ChangeCachingCollectionDataDecorator decorator, bool hasChanged)
        {
            _strategyStrictMock.Stub(mock => mock.HasDataChanged(Arg.Is(decorator), Arg <IDomainObjectCollectionData> .Is.Anything)).Return(hasChanged);
            _strategyStrictMock.Replay();

            decorator.HasChanged(_strategyStrictMock);
            Assert.That(decorator.IsCacheUpToDate, Is.True);
        }
Example #2
0
        private void CheckOriginalDataNotCopied(ChangeCachingCollectionDataDecorator decorator)
        {
            var originalData = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> (
                decorator.OriginalData);

            var originalDataStore   = DomainObjectCollectionDataTestHelper.GetWrappedData(originalData);
            var observedWrappedData = PrivateInvoke.GetNonPublicField(decorator, "_observedWrappedData");

            Assert.That(originalDataStore, Is.SameAs(observedWrappedData));
        }
Example #3
0
        public override void SetUp()
        {
            base.SetUp();

            _domainObject = DomainObjectMother.CreateFakeObject <Order> ();

            _wrappedData           = new DomainObjectCollectionData(new[] { _domainObject });
            _decoratorWithRealData = new ChangeCachingCollectionDataDecorator(_wrappedData);

            _strategyStrictMock = new MockRepository().StrictMock <ICollectionEndPointChangeDetectionStrategy> ();
        }
Example #4
0
        private void CheckOriginalValuesCopiedBeforeModification(Action <ChangeCachingCollectionDataDecorator, DomainObject> action)
        {
            var domainObject1 = DomainObjectMother.CreateFakeObject <Order>();
            var domainObject2 = DomainObjectMother.CreateFakeObject <Order> ();

            var wrappedData = new DomainObjectCollectionData(new[] { domainObject1, domainObject2 });
            var decorator   = new ChangeCachingCollectionDataDecorator(wrappedData);

            action(decorator, domainObject1);

            Assert.That(decorator.OriginalData.ToArray(), Is.EqualTo(new[] { domainObject1, domainObject2 }));
        }
Example #5
0
        public void SortOriginalAndCurrent_Unchanged_OriginalDataIsNotCopied()
        {
            var domainObject1 = DomainObjectMother.CreateFakeObject <Order> ();
            var domainObject2 = DomainObjectMother.CreateFakeObject <OrderItem> ();
            var domainObject3 = DomainObjectMother.CreateFakeObject <Customer> ();

            var decorator = new ChangeCachingCollectionDataDecorator(
                new DomainObjectCollectionData(new DomainObject[] { domainObject1, domainObject2, domainObject3 }));

            decorator.SortOriginalAndCurrent(CompareTypeNames);

            CheckOriginalDataNotCopied(decorator);
        }
Example #6
0
        public void Commit_RevertsOriginalObjects_ToCurrentObjects()
        {
            var wrappedData = new DomainObjectCollectionData();
            var decorator   = new ChangeCachingCollectionDataDecorator(wrappedData);

            decorator.Add(_domainObject);
            Assert.That(decorator.OriginalData.ToArray(), Is.Empty);

            decorator.Commit();

            Assert.That(decorator.OriginalData.ToArray(), Is.EqualTo(new[] { _domainObject }));
            CheckOriginalDataNotCopied(decorator);
        }
Example #7
0
        public void SortOriginalAndCurrent_Unchanged()
        {
            var domainObject1 = DomainObjectMother.CreateFakeObject <Order> ();
            var domainObject2 = DomainObjectMother.CreateFakeObject <OrderItem> ();
            var domainObject3 = DomainObjectMother.CreateFakeObject <Customer> ();

            var decorator = new ChangeCachingCollectionDataDecorator(
                new DomainObjectCollectionData(new DomainObject[] { domainObject1, domainObject2, domainObject3 }));

            decorator.SortOriginalAndCurrent(CompareTypeNames);

            Assert.That(decorator.ToArray(), Is.EqualTo(new DomainObject[] { domainObject3, domainObject1, domainObject2 }));
            Assert.That(decorator.OriginalData.ToArray(), Is.EqualTo(new DomainObject[] { domainObject3, domainObject1, domainObject2 }));
        }
Example #8
0
        public void Rollback_SetsFlagUnchanged()
        {
            var wrappedData = new DomainObjectCollectionData();
            var decorator   = new ChangeCachingCollectionDataDecorator(wrappedData);

            decorator.Add(_domainObject);
            _strategyStrictMock.Replay();

            decorator.Rollback();

            Assert.That(decorator.HasChanged(_strategyStrictMock), Is.False);
            _strategyStrictMock.AssertWasNotCalled(
                mock => mock.HasDataChanged(Arg <IDomainObjectCollectionData> .Is.Anything, Arg <IDomainObjectCollectionData> .Is.Anything));
        }
Example #9
0
        public void Rollback_RevertsCurrentObjects_ToOriginalObjects()
        {
            var wrappedData = new DomainObjectCollectionData();
            var decorator   = new ChangeCachingCollectionDataDecorator(wrappedData);

            decorator.Add(_domainObject);

            Assert.That(decorator.ToArray(), Is.Not.Empty);
            Assert.That(decorator.OriginalData.ToArray(), Is.Empty);

            decorator.Rollback();

            Assert.That(decorator.ToArray(), Is.Empty);
            Assert.That(decorator.OriginalData.ToArray(), Is.Empty);
            CheckOriginalDataNotCopied(decorator);
        }
Example #10
0
        public void Serializable()
        {
            var wrappedData = new DomainObjectCollectionData(new[] { _domainObject });
            var decorator   = new ChangeCachingCollectionDataDecorator(wrappedData);

            WarmUpCache(decorator, false);

            Assert.That(decorator.Count, Is.EqualTo(1));
            Assert.That(decorator.IsCacheUpToDate, Is.True);
            Assert.That(decorator.HasChanged(_strategyStrictMock), Is.False);

            var deserializedDecorator = Serializer.SerializeAndDeserialize(decorator);

            Assert.That(deserializedDecorator.Count, Is.EqualTo(1));
            Assert.That(deserializedDecorator.IsCacheUpToDate, Is.True);
            Assert.That(deserializedDecorator.HasChanged(_strategyStrictMock), Is.False);
        }
Example #11
0
        public void SortOriginalAndCurrent_OriginalDataCopied_ChangeFlagInvalidated()
        {
            var domainObject1 = DomainObjectMother.CreateFakeObject <Order> ();
            var domainObject2 = DomainObjectMother.CreateFakeObject <OrderItem> ();
            var domainObject3 = DomainObjectMother.CreateFakeObject <Customer> ();

            var decorator = new ChangeCachingCollectionDataDecorator(
                new DomainObjectCollectionData(new DomainObject[] { domainObject1, domainObject2, domainObject3 }));

            decorator.Remove(domainObject2);

            PrepareCheckChangeFlagInvalidated(decorator, true);

            decorator.SortOriginalAndCurrent(CompareTypeNames);

            CheckChangeFlagInvalidated(decorator);
        }
Example #12
0
 private void CheckChangeFlagInvalidated(ChangeCachingCollectionDataDecorator decorator)
 {
     Assert.That(decorator.IsCacheUpToDate, Is.False);
 }
Example #13
0
 private void PrepareCheckChangeFlagInvalidated(ChangeCachingCollectionDataDecorator decorator, bool hasChanged)
 {
     WarmUpCache(decorator, hasChanged);
     Assert.That(decorator.HasChanged(_strategyStrictMock), Is.EqualTo(hasChanged));
 }
Example #14
0
 private void CheckChangeFlagRetained(ChangeCachingCollectionDataDecorator decorator)
 {
     Assert.That(decorator.IsCacheUpToDate, Is.True);
 }
Example #15
0
        private void CallOnDataChangedOnWrappedData(ChangeCachingCollectionDataDecorator decorator)
        {
            var wrappedData = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <ObservableCollectionDataDecorator> (decorator);

            PrivateInvoke.InvokeNonPublicMethod(wrappedData, "OnDataChanged", ObservableCollectionDataDecoratorBase.OperationKind.Remove, _domainObject, 12);
        }