public void MapRemovedItem_GivenNullAction_Succeeds()
        {
            var dtoCollection = new Mock<ISoftDelete<AggregateCollectionMapperTestDto>> ();
            var aggregateRootCollectionMapper = new AggregateRootCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity> ( dtoCollection.Object );

            var resultValue = aggregateRootCollectionMapper.MapRemovedItem ( null );

            Assert.AreSame ( aggregateRootCollectionMapper, resultValue );
        }
        public void Map_GivenNullActionForFindCollectionEntity_ThrowsArgumentException()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();

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

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

            aggregateRootCollectionMapper
                .FindCollectionEntity ( null )
                .Map ();
        }
        public void Map_GivenNoCurrentAndRemovedDtos_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var aggregateRootCollectionMapper = new AggregateRootCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity> ( dtoCollection );

            bool returnValue = aggregateRootCollectionMapper.Map ();

            Assert.IsTrue ( returnValue );
        }
        public void Map_GivenWithRemovedDtosWithExceptionThrownByRemoveMethod_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var dto = new AggregateCollectionMapperTestDto ();
            dtoCollection.RemovedItems.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.RemovedItems[ 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_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 aggregateRootCollectionMapper = new AggregateRootCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity> ( dtoCollection );

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

            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootFindMethodCalled == NoOfRemovedItems + NoOfUpdatedItems );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootRemoveMethodCalled == NoOfRemovedItems );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootChangeMethodCalled == NoOfUpdatedItems );
            Assert.IsTrue ( requestHandler.NoOfTimesAggregateRootAddMethodCalled == NoOfAddedItems );
            Assert.IsTrue ( 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 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_GivenWithCurrentDtosAndEditStatusAsDelete_ThrowsArgumentException()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var dto = new AggregateCollectionMapperTestDto { EditStatus = EditStatus.Delete };
            dtoCollection.CurrentItems.Add ( dto );

            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 ();
        }
        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 );
        }