public void Map_GivenRemovedDtosWithMatchingKey_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection <AggregateCollectionMapperTestDto> ();

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

            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)
                               .Map();

            Assert.IsTrue(returnValue);
            Assert.IsTrue(dtoCollection.RemovedItems[0].DataErrorInfoCollection.Count() == 0);
            Assert.IsTrue(requestHandler.NoOfTimesAggregateNodeRemoveMethodCalled > 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 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_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_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);
        }
        private bool MapProperties(PatientContact patientContact, PatientContactContactInformationDto patientContactDto)
        {
            var result = true;

            var phoneMapResult =
                new AggregateNodeCollectionMapper <PatientContactPhoneDto, PatientContact, PatientContactPhone> (
                    patientContactDto.PhoneNumbers, patientContact, patientContact.PhoneNumbers)
                .MapAddedItem(
                    (dto, entity) =>
                    entity.AddContactPhone(
                        dto.PhoneNumber,
                        _mappingHelper.MapLookupField <PatientContactPhoneType> (dto.PatientContactPhoneType),
                        dto.PhoneExtensionNumber,
                        dto.ConfidentialIndicator))
                .MapChangedItem(MapPhoneProperties)
                .MapRemovedItem((dto, entity, node) => entity.RemoveContactPhone(node))
                .Map();

            result &= phoneMapResult;

            patientContact.ReviseCityName(patientContactDto.CityName);
            patientContact.ReviseCountry(_mappingHelper.MapLookupField <Country> (patientContactDto.Country));
            patientContact.ReviseCountyArea(_mappingHelper.MapLookupField <CountyArea> (patientContactDto.CountyArea));
            patientContact.ReviseEmailAddress(patientContactDto.EmailAddress);
            patientContact.ReviseFirstStreetAddress(patientContactDto.FirstStreetAddress);
            patientContact.ReviseSecondStreetAddress(patientContactDto.SecondStreetAddress);
            patientContact.RevisePostalCode(patientContactDto.PostalCode);
            patientContact.ReviseStateProvince(_mappingHelper.MapLookupField <StateProvince> (patientContactDto.StateProvince));

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Processes the single aggregate.
        /// </summary>
        /// <param name="agencyContactsDto">The agency contacts dto.</param>
        /// <param name="agency">The agency.</param>
        /// <returns>A <see cref="System.Boolean"/></returns>
        protected override bool ProcessSingleAggregate(AgencyContactsDto agencyContactsDto, Agency agency)
        {
            var processSucceeded =
                new AggregateNodeCollectionMapper <AgencyContactDto, Agency, AgencyContact> (
                    agencyContactsDto.AgencyContacts, agency, agency.AgencyContacts).MapRemovedItem(RemoveAgencyContact).MapAddedItem(
                    AddAgencyContact).MapChangedItem(ChangeAgencyContact).Map();

            return(processSucceeded);
        }
Exemplo n.º 7
0
        private bool MapEmailAddresses(Location location, LocationProfileDto dto)
        {
            var result =
                new AggregateNodeCollectionMapper <LocationEmailAddressDto, Location, LocationEmailAddress> (
                    dto.EmailAddresses, location, location.EmailAddresses).MapRemovedItem(RemoveLocationEmailAddress).MapAddedItem(
                    AddLocationEmailAddress).MapChangedItem(ChangeLocationEmailAddress).Map();

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Processes the single aggregate.
        /// </summary>
        /// <param name="agencyFaqsDto">The agency faqs dto.</param>
        /// <param name="agency">The agency.</param>
        /// <returns>A <see cref="System.Boolean"/></returns>
        protected override bool ProcessSingleAggregate(AgencyFaqsDto agencyFaqsDto, Agency agency)
        {
            var processSucceeded =
                new AggregateNodeCollectionMapper <AgencyFaqDto, Agency, AgencyFrequentlyAskedQuestion> (
                    agencyFaqsDto.AgencyFaqs, agency, agency.AgencyFrequentlyAskedQuestions).MapRemovedItem(RemoveAgencyAddress).MapAddedItem(
                    AddAgencyAddress).MapChangedItem(ChangeAgencyAddress).Map();

            return(processSucceeded);
        }
Exemplo n.º 9
0
        private bool MapEmailCollection(Agency agency, AgencyProfileDto agencyProfileDto)
        {
            var result =
                new AggregateNodeCollectionMapper <AgencyEmailAddressDto, Agency, AgencyEmailAddress> (
                    agencyProfileDto.EmailAddresses, agency, agency.EmailAddresses)
                .MapRemovedItem(RemoveAgencyEmailAddress)
                .MapAddedItem(AddAgencyEmailAddress)
                .MapChangedItem(ChangeAgencyEmailAddress)
                .Map();

            return(result);
        }
Exemplo n.º 10
0
        private static bool MapAliasCollection(Agency agency, AgencyProfileDto agencyProfileDto)
        {
            var result =
                new AggregateNodeCollectionMapper <AgencyAliasDto, Agency, AgencyAlias> (
                    agencyProfileDto.AgencyAliases, agency, agency.AgencyAliases)
                .MapRemovedItem(RemoveAgencyAlias)
                .MapAddedItem(AddAgencyAlias)
                .MapChangedItem(ChangeAgencyAlias)
                .Map();

            return(result);
        }
        private bool MapSignedComments(ClinicalCaseProfileDto dto, ClinicalCase clinicalCase)
        {
            var result =
                new AggregateNodeCollectionMapper <ClinicalCaseSignedCommentDto, ClinicalCase, ClinicalCaseSignedComment> (
                    dto.SignedComments, clinicalCase, clinicalCase.SignedComments)
                .MapRemovedItem(RemoveClinicalCaseSignedComment)
                .MapAddedItem(AddClinicalCaseSignedComment)
                .MapChangedItem(ChangeClinicalCaseSignedComment)
                .Map();

            return(result);
        }
        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);
        }
        private bool MapLocationOperationScheduleProperties(LocationOperationSchedule locationOperationSchedule, LocationOperationScheduleDto dto)
        {
            var result = true;

            result &= new PropertyMapper <LocationOperationSchedule> (locationOperationSchedule, dto).MapProperty(x => x.Name, dto.Name).Map();

            result &=
                new AggregateNodeCollectionMapper <LocationWorkHourDto, LocationOperationSchedule, LocationWorkHour> (
                    dto.LocationWorkHours, locationOperationSchedule, locationOperationSchedule.LocationWorkHours).MapAddedItem(
                    AddLocationWorkHour).MapChangedItem(ChangeLocationWorkHour).MapRemovedItem(RemoveLocationWorkHour).Map();

            return(result);
        }
        public void FindCollectionEntity_GivenNullAction_Succeeds()
        {
            var dtoCollection                 = new Mock <ISoftDelete <AggregateCollectionMapperTestDto> > ();
            var aggregateRoot                 = new AggregateCollectionMapperTestAggregateRootEntity();
            var aggregateNodeCollection       = new Mock <IEnumerable <AggregateCollectionMapperTestAggregateNodeEntity> > ();
            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                                                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                                                 AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection.Object, aggregateRoot, aggregateNodeCollection.Object);

            var resultValue = aggregateNodeCollectionMapper.FindCollectionEntity(null);

            Assert.AreSame(aggregateNodeCollectionMapper, resultValue);
        }
        public void Map_GivenNoCurrentAndRemovedDtos_Succeeds()
        {
            var dtoCollection                 = new SoftDeleteObservableCollection <AggregateCollectionMapperTestDto> ();
            var aggregateRoot                 = new AggregateCollectionMapperTestAggregateRootEntity();
            var aggregateNodeCollection       = new Mock <IEnumerable <AggregateCollectionMapperTestAggregateNodeEntity> > ();
            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                                                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                                                 AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection.Object);

            bool returnValue = aggregateNodeCollectionMapper.Map();

            Assert.IsTrue(returnValue);
        }
        public void MapAddedItem_GivenNullAction_Succeeds()
        {
            var dtoCollection = new Mock<ISoftDelete<AggregateCollectionMapperTestDto>> ();
            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new Mock<IEnumerable<AggregateCollectionMapperTestAggregateNodeEntity>> ();
            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection.Object, aggregateRoot, aggregateNodeCollection.Object );

            var resultValue = aggregateNodeCollectionMapper.MapAddedItem ( null );

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

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

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

            aggregateNodeCollectionMapper
            .MapRemovedItem(null)
            .Map();
        }
        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 );
        }
Exemplo n.º 19
0
        private void CreateLabSpecimen(LabSpecimenDto dto, long patientKey, Provenance provenance)
        {
            if (dto == null || dto.LabResults == null || dto.LabResults.Count == 0)
            {
                return;
            }

            var clinicalCase = _clinicalCaseRepository.GetActiveClinicalCaseByPatient(patientKey);
            var labSpecimen  = _labSpecimenFactory.CreateLabSpecimen(
                clinicalCase, provenance, new DateTimeRange(dto.ActivityStartDateTime, dto.ActivityStartDateTime));
            var labSpecimenType = _mappingHelper.MapLookupField <LabSpecimenType> (dto.LabSpecimenType);

            labSpecimen.ReviseLabSpecimenType(labSpecimenType);
            labSpecimen.ReviseLabReceivedDate(dto.LabReceivedDate);
            labSpecimen.ReviseCollectedHereIndicator(dto.CollectedHereIndicator);

            // TODO: This needs to be rethought when the domain for Lab is redone.
            var labTest = labSpecimen.LabTests.FirstOrDefault(lt => lt.LabTestInfo.LabTestName.WellKnownName == dto.LabTestName.WellKnownName);

            if (labTest == null && labSpecimen.LabTests.Count > 0)
            {
                //right now there is only every one lab test per lab specimen?
                labSpecimen.RemoveLabTest(labSpecimen.LabTests.ElementAt(0));
            }
            var labTestInfo = new LabTestInfoBuilder()
                              .WithLabTestName(_mappingHelper.MapLookupField <LabTestName> (dto.LabTestName))
                              .WithTestReportDate(dto.LabTestDate)
                              .WithLabTestNote(dto.LabTestNote);

            if (labTest == null)
            {
                labTest = labSpecimen.AddLabTest(labTestInfo);
            }
            else
            {
                labTest.ReviseLabTestInfo(labTestInfo);
            }

            var result = new AggregateNodeCollectionMapper <LabResultDto, LabTest, LabResult> (dto.LabResults, labTest, labTest.LabResults)
                         .MapAddedItem(
                (lrdto, lt) =>
            {
                CodedConcept labTestResultNameCodedConcept = null;
                if (lrdto.LabTestResultNameCodedConcept != null)
                {
                    labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept);
                }

                lt.AddLabResult(
                    new LabResultBuilder()
                    .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept)
                    .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode)
                    .WithValue(lrdto.Value));
            }
                )
                         .MapChangedItem(
                (lrdto, lt, lr) =>
            {
                lt.RemoveLabResult(lr);
                CodedConcept labTestResultNameCodedConcept = null;
                if (lrdto.LabTestResultNameCodedConcept != null)
                {
                    labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept);
                }
                lt.AddLabResult(
                    new LabResultBuilder()
                    .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept)
                    .WithValue(lrdto.Value)
                    .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode));
            })
                         .MapRemovedItem((lrdto, lt, lr) => lt.RemoveLabResult(lr))
                         .Map();
        }
Exemplo n.º 20
0
        private bool MapProperties(LabSpecimenDto dto, LabSpecimen entity)
        {
            var labSpecimenType = _mappingHelper.MapLookupField <LabSpecimenType> (dto.LabSpecimenType);

            entity.ReviseLabSpecimenType(labSpecimenType);
            entity.ReviseLabReceivedDate(dto.LabReceivedDate);
            entity.ReviseCollectedHereIndicator(dto.CollectedHereIndicator);

            // TODO: This needs to be rethought when the domain for Lab is redone.
            var labTest = entity.LabTests.FirstOrDefault(lt => lt.LabTestInfo.LabTestName.WellKnownName == dto.LabTestName.WellKnownName);

            if (labTest == null && entity.LabTests.Count > 0)
            {
                //right now there is only every one lab test per lab specimen?
                entity.RemoveLabTest(entity.LabTests.ElementAt(0));
            }
            var labTestInfo = new LabTestInfoBuilder()
                              .WithLabTestName(_mappingHelper.MapLookupField <LabTestName> (dto.LabTestName))
                              .WithTestReportDate(dto.LabTestDate)
                              .WithLabTestNote(dto.LabTestNote);

            if (labTest == null)
            {
                labTest = entity.AddLabTest(labTestInfo);
            }
            else
            {
                labTest.ReviseLabTestInfo(labTestInfo);
            }

            var result = new AggregateNodeCollectionMapper <LabResultDto, LabTest, LabResult> (dto.LabResults, labTest, labTest.LabResults)
                         .MapAddedItem(
                (lrdto, lt) =>
            {
                CodedConcept labTestResultNameCodedConcept = null;
                if (lrdto.LabTestResultNameCodedConcept != null)
                {
                    labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept);
                }

                lt.AddLabResult(
                    new LabResultBuilder()
                    .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept)
                    .WithValue(lrdto.Value)
                    .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode));
            }
                )
                         .MapChangedItem(
                (lrdto, lt, lr) =>
            {
                lt.RemoveLabResult(lr);
                CodedConcept labTestResultNameCodedConcept = null;
                if (lrdto.LabTestResultNameCodedConcept != null)
                {
                    labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept);
                }
                lt.AddLabResult(
                    new LabResultBuilder()
                    .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept)
                    .WithValue(lrdto.Value)
                    .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode));
            })
                         .MapRemovedItem((lrdto, lt, lr) => lt.RemoveLabResult(lr))
                         .Map();

            return(result);
        }
        public void Map_GivenNoCurrentAndRemovedDtos_Succeeds()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();
            var aggregateRoot = new AggregateCollectionMapperTestAggregateRootEntity ();
            var aggregateNodeCollection = new Mock<IEnumerable<AggregateCollectionMapperTestAggregateNodeEntity>> ();
            var aggregateNodeCollectionMapper = new AggregateNodeCollectionMapper
                <AggregateCollectionMapperTestDto, AggregateCollectionMapperTestAggregateRootEntity,
                    AggregateCollectionMapperTestAggregateNodeEntity> (
                dtoCollection, aggregateRoot, aggregateNodeCollection.Object );

            bool returnValue = aggregateNodeCollectionMapper.Map ();

            Assert.IsTrue ( returnValue );
        }
        public void Map_GivenNullActionForRemovedDto_ThrowsArgumentException()
        {
            var dtoCollection = new SoftDeleteObservableCollection<AggregateCollectionMapperTestDto> ();

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

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

            aggregateNodeCollectionMapper
                .MapRemovedItem ( null )
                .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_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_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 ();
        }