public void Map_GivenWithRemovedDtosWithExceptionThrownByRemoveMethod_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var dto = new AggregateCollectionMapperTestDto ();
            dtoCollection.RemovedItems.Add ( dto );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new List<AggregateCollectionMapperTestAggregateNodeEntity>
                                              { new AggregateCollectionMapperTestAggregateNodeEntity () };

            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection );

            bool returnValue = aggregateNodeCollectionMapper
                .MapRemovedItem ( requestHandler.AggregateNodeRemoveWithThrowException )
                .MapChangedItem ( requestHandler.AggregateNodeChangeWithThrowException )
                .MapAddedItem ( requestHandler.AggregateNodeAddWithThrowException )
                .Map ();

            Assert.IsTrue ( dtoCollection.RemovedItems[ 0 ].DataErrorInfoCollection.Count () > 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeAddWithThrowExceptionMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeChangeWithThrowExceptionMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeRemoveWithThrowExceptionMethodCalled > 0 );
            Assert.IsFalse ( returnValue );
        }
        public void Map_GivenWithCurrentDtosAndEditStatusAsUpdate_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var dto = new AggregateCollectionMapperTestDto { EditStatus = EditStatus.Update };
            dtoCollection.CurrentItems.Add ( dto );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new List<AggregateCollectionMapperTestAggregateNodeEntity>
                                              { new AggregateCollectionMapperTestAggregateNodeEntity () };

            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection );

            bool returnValue = aggregateNodeCollectionMapper
                .MapRemovedItem ( requestHandler.AggregateNodeRemove )
                .MapChangedItem ( requestHandler.AggregateNodeChange )
                .MapAddedItem ( requestHandler.AggregateNodeAdd )
                .Map ();

            Assert.IsTrue ( returnValue );
            Assert.IsTrue ( dtoCollection.CurrentItems[ 0 ].DataErrorInfoCollection.Count () == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeRemoveMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeChangeMethodCalled > 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeAddMethodCalled == 0 );
        }
        public void Map_GivenWithMultipleRemovedAndCurrentDtos_Succeeds()
        {
            int NoOfRemovedItems = 5;
            int NoOfAddedItems = 6;
            int NoOfUpdatedItems = 7;

            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();

            for ( int removedItemIndex = 0; removedItemIndex < NoOfRemovedItems; removedItemIndex++ )
            {
                dtoCollection.RemovedItems.Add ( new AggregateCollectionMapperTestDto () );
            }

            for ( int addedItemIndex = 0; addedItemIndex < NoOfAddedItems; addedItemIndex++ )
            {
                dtoCollection.CurrentItems.Add ( new AggregateCollectionMapperTestDto { EditStatus = EditStatus.Create } );
            }

            for ( int updatedItemIndex = 0; updatedItemIndex < NoOfUpdatedItems; updatedItemIndex++ )
            {
                dtoCollection.CurrentItems.Add ( new AggregateCollectionMapperTestDto { EditStatus = EditStatus.Update } );
            }

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new List<AggregateCollectionMapperTestAggregateNodeEntity> ()
                                              { new AggregateCollectionMapperTestAggregateNodeEntity () };

            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection );

            bool returnValue = aggregateNodeCollectionMapper
                .MapRemovedItem ( requestHandler.AggregateNodeRemove )
                .MapChangedItem ( requestHandler.AggregateNodeChange )
                .MapAddedItem ( requestHandler.AggregateNodeAdd )
                .Map ();

            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeRemoveMethodCalled == NoOfRemovedItems );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeChangeMethodCalled == NoOfUpdatedItems );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateNodeAddMethodCalled == NoOfAddedItems );
            Assert.IsTrue ( returnValue );
        }
        public void Map_GivenWithCurrentDtosAndEditStatusAsDelete_ThrowsArgumentException()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var dto = new AggregateCollectionMapperTestDto { EditStatus = EditStatus.Delete };
            dtoCollection.CurrentItems.Add ( dto );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new List<AggregateCollectionMapperTestAggregateNodeEntity>
                                              { new AggregateCollectionMapperTestAggregateNodeEntity () };

            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection );

            bool returnValue = aggregateNodeCollectionMapper
                .MapRemovedItem ( requestHandler.AggregateNodeRemove )
                .MapChangedItem ( requestHandler.AggregateNodeChange )
                .MapAddedItem ( requestHandler.AggregateNodeAdd )
                .Map ();
        }
        public void Map_GivenRemovedDtosWithNoMatchingKey_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();

            dtoCollection.RemovedItems.Add ( new AggregateCollectionMapperTestDto () );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new List<AggregateCollectionMapperTestAggregateNodeEntity> ();
            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection );

            bool returnValue = aggregateNodeCollectionMapper
                .MapRemovedItem ( requestHandler.AggregateNodeRemove )
                .Map ();

            Assert.IsFalse ( returnValue );
            Assert.IsTrue ( dtoCollection.RemovedItems[ 0 ].DataErrorInfoCollection.Count () > 0 );
        }
        public void Map_GivenWithCurrentDtosAndEditStatusAsUpdateWithExceptionThrownByChangeMethod_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var dto = new AggregateCollectionMapperTestDto { EditStatus = EditStatus.Update };
            dtoCollection.CurrentItems.Add ( dto );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRootCollectionMapper = new AggregateRootCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity> ( dtoCollection );

            bool returnValue = aggregateRootCollectionMapper
                .FindCollectionEntity ( requestHandler.AggregateRootFind )
                .MapRemovedItem ( requestHandler.AggregateRootRemoveWithThrowException )
                .MapChangedItem ( requestHandler.AggregateRootChangeWithThrowException )
                .MapAddedItem ( requestHandler.AggregateRootAddWithThrowException )
                .Map ();

            Assert.IsTrue ( dtoCollection.CurrentItems[ 0 ].DataErrorInfoCollection.Count () > 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootFindMethodCalled > 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootAddWithThrowExceptionMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootChangeWithThrowExceptionMethodCalled > 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootRemoveWithThrowExceptionMethodCalled == 0 );
            Assert.IsFalse ( returnValue );
        }
        public void Map_GivenWithCurrentDtosAndEditStatusAsNoop_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();

            dtoCollection.CurrentItems.Add ( new AggregateCollectionMapperTestDto () );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRootCollectionMapper = new AggregateRootCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity> ( dtoCollection );

            bool returnValue = aggregateRootCollectionMapper
                .FindCollectionEntity ( requestHandler.AggregateRootFind )
                .MapRemovedItem ( requestHandler.AggregateRootRemove )
                .MapChangedItem ( requestHandler.AggregateRootChange )
                .MapAddedItem ( requestHandler.AggregateRootAdd )
                .Map ();

            Assert.IsTrue ( returnValue );
            Assert.IsTrue ( dtoCollection.CurrentItems[ 0 ].DataErrorInfoCollection.Count () == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootFindMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootRemoveMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootChangeMethodCalled == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootAddMethodCalled == 0 );
        }
        public void Map_GivenRemovedDtosWithMatchingKey_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();

            dtoCollection.RemovedItems.Add ( new AggregateCollectionMapperTestDto () );

            var requestHandler = new AggregateCollectionMapperTestRequestHandler ();

            var aggregateRootCollectionMapper = new AggregateRootCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity> ( dtoCollection );

            bool returnValue = aggregateRootCollectionMapper
                .FindCollectionEntity ( requestHandler.AggregateRootFind )
                .MapRemovedItem ( requestHandler.AggregateRootRemove )
                .Map ();

            Assert.IsTrue ( returnValue );
            Assert.IsTrue ( dtoCollection.RemovedItems[ 0 ].DataErrorInfoCollection.Count () == 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootFindMethodCalled > 0 );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootRemoveMethodCalled > 0 );
        }