Beispiel #1
0
        public async Task update_correct_Person_should_success()
        {
            Guid       testId        = Guid.NewGuid();
            SSG_Person existedPerson = new SSG_Person()
            {
                PersonId  = testId,
                FirstName = "new"
            };

            _odataClientMock.Setup(x => x.For <SSG_Person>(null).Key(It.Is <Guid>(m => m == testId)).Set(It.IsAny <Dictionary <string, object> >())
                                   .UpdateEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(existedPerson)
                     );
            IDictionary <string, object> updatedFields = new Dictionary <string, object> {
                { "ssg_firstname", "new" }
            };
            var person = new SSG_Person()
            {
                PersonId  = testId,
                FirstName = "old"
            };
            var result = await _sut.UpdatePerson(existedPerson, updatedFields, person, CancellationToken.None);

            Assert.AreEqual("new", result.FirstName);
        }
Beispiel #2
0
 public AgencyRequestService(ISearchRequestService searchRequestService, ILogger <AgencyRequestService> logger, IMapper mapper)
 {
     _searchRequestService = searchRequestService;
     _logger                = logger;
     _mapper                = mapper;
     _personSought          = null;
     _uploadedPerson        = null;
     _uploadedSearchRequest = null;
 }
Beispiel #3
0
 public SearchResultService(ISearchRequestService searchRequestService, ILogger <SearchResultService> logger, IMapper mapper)
 {
     _searchRequestService = searchRequestService;
     _logger             = logger;
     _mapper             = mapper;
     _returnedPerson     = null;
     _sourceIdentifier   = null;
     _providerDynamicsID = null;
     _searchApiRequest   = null;
     _searchRequest      = null;
     _foundPerson        = null;
 }
Beispiel #4
0
        public async Task <bool> ProcessPersonFound(
            Person person,
            ProviderProfile providerProfile,
            SSG_SearchRequest searchRequest,
            Guid?searchApiRequestId,
            CancellationToken cancellationToken,
            SSG_Identifier sourceIdentifier = null)
        {
            if (person == null)
            {
                return(true);
            }

            _foundPerson        = person;
            _providerDynamicsID = providerProfile.DynamicsID();
            _searchRequest      = searchRequest;
            _sourceIdentifier   = sourceIdentifier;
            _searchApiRequest   = searchApiRequestId == null? null : new SSG_SearchApiRequest()
            {
                SearchApiRequestId = (Guid)searchApiRequestId
            };
            _cancellationToken = cancellationToken;

            _returnedPerson = await UploadPerson();

            await UploadSafetyConcern();

            await UploadIdentifiers( );

            await UploadAddresses();

            await UploadPhoneNumbers();

            await UploadNames( );

            await UploadEmployment( );

            await UploadRelatedPersons();

            await UploadBankInfos();

            await UploadVehicles();

            await UploadOtherAssets();

            await UploadCompensationClaims();

            await UploadInsuranceClaims();

            await UploadEmails();

            return(true);
        }
Beispiel #5
0
        private async Task <SSG_Person> UploadPerson()
        {
            _logger.LogDebug($"Attempting to create the found person record for SearchRequest[{_searchRequest.SearchRequestId}]");
            PersonEntity ssg_person = _mapper.Map <PersonEntity>(_foundPerson);

            ssg_person.SearchRequest     = _searchRequest;
            ssg_person.InformationSource = _providerDynamicsID;
            SSG_Person returnedPerson = await _searchRequestService.SavePerson(ssg_person, _cancellationToken);

            await CreateResultTransaction(returnedPerson);

            return(returnedPerson);
        }
        public void fatherObj_not_contain_entity_type_should_throw_exception()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedOwnerID = Guid.NewGuid();
            SSG_Person person         = new SSG_Person()
            {
            };
            AssetOwnerEntity entity = new AssetOwnerEntity()
            {
                LastName = "ownerlastname1", FirstName = "test"
            };

            Assert.ThrowsAsync <System.InvalidCastException>(async() => await _sut.Exists(person, entity));
        }
        public void SSG_Person_should_map_to_ResponsePerson_correctly()
        {
            SSG_Person person = new SSG_Person
            {
                DateOfDeath     = new DateTime(2015, 1, 1),
                GenderOptionSet = GenderType.Other.Value,
                FirstName       = "firstName"
            };

            ResponsePerson rp = _mapper.Map <ResponsePerson>(person);

            Assert.AreEqual(new DateTimeOffset(new DateTime(2015, 1, 1)), rp.DateOfDeath);
            Assert.AreEqual("u", rp.Gender);
            Assert.AreEqual("firstName", rp.FirstName);
        }
Beispiel #8
0
        public async Task <SSG_Person> GetPerson(Guid personId, CancellationToken cancellationToken)
        {
            SSG_Person person = await _oDataClient
                                .For <SSG_Person>()
                                .Key(personId)
                                .Expand(x => x.SSG_Identities)
                                .Expand(x => x.SSG_PhoneNumbers)
                                .Expand(x => x.SSG_Identifiers)
                                .Expand(x => x.SSG_Employments)
                                .Expand(x => x.SSG_Addresses)
                                .Expand(x => x.SSG_Aliases)
                                .Expand(x => x.SSG_SafetyConcernDetails)
                                .FindEntryAsync(cancellationToken);

            return(person);
        }
        public async Task <bool> ProcessPersonFound(Person person, ProviderProfile providerProfile, SSG_SearchRequest request, CancellationToken concellationToken)
        {
            if (person == null)
            {
                return(true);
            }

            int?         providerDynamicsID = providerProfile.DynamicsID();
            PersonEntity ssg_person         = _mapper.Map <PersonEntity>(person);

            ssg_person.SearchRequest     = request;
            ssg_person.InformationSource = providerDynamicsID;
            _logger.LogDebug($"Attempting to create the found person record for SearchRequest[{request.SearchRequestId}]");
            SSG_Person returnedPerson = await _searchRequestService.SavePerson(ssg_person, concellationToken);

            _logger.LogDebug($"Attempting to create found identifier records for SearchRequest[{request.SearchRequestId}]");
            await UploadIdentifiers(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create found adddress records for SearchRequest[{request.SearchRequestId}]");
            await UploadAddresses(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create found phone records for SearchRequest[{request.SearchRequestId}]");
            await UploadPhoneNumbers(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create found name records for SearchRequest[{request.SearchRequestId}]");
            await UploadNames(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create found employment records for SearchRequest[{request.SearchRequestId}]");
            await UploadEmployment(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create found related person records for SearchRequest[{request.SearchRequestId}]");
            await UploadRelatedPersons(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create bank info records for SearchRequest[{request.SearchRequestId}]");
            await UploadBankInfos(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create vehicles records for SearchRequest[{request.SearchRequestId}]");
            await UploadVehicles(person, request, returnedPerson, providerDynamicsID, concellationToken);

            _logger.LogDebug($"Attempting to create other assets records for SearchRequest[{request.SearchRequestId}]");
            await UploadOtherAssets(person, request, returnedPerson, providerDynamicsID, concellationToken);

            return(true);
        }
Beispiel #10
0
        public async Task <SSG_Person> UpdatePerson(SSG_Person existedPerson, IDictionary <string, object> updatedFields, PersonEntity newPerson, CancellationToken cancellationToken)
        {
            string duplicateDetectHash = await _duplicateDetectService.GetDuplicateDetectHashData(newPerson);

            if (duplicateDetectHash != existedPerson.DuplicateDetectHash)
            {
                updatedFields.Add("ssg_duplicatedetectionhash", duplicateDetectHash);
            }

            updatedFields.Add(new KeyValuePair <string, object>("ssg_updatedbyagency", true));
            try
            {
                return(await this._oDataClient.For <SSG_Person>().Key(existedPerson.PersonId).Set(updatedFields).UpdateEntryAsync(cancellationToken));
            }catch (WebRequestException e) when(e.IsDuplicateHashError())
            {
                _logger.LogError(e, "Update Person failed with DuplicationHash [{hash}]", duplicateDetectHash);
                return(null);
            }
        }
Beispiel #11
0
        public async Task <SSG_SearchRequest> ProcessSearchRequestOrdered(SearchRequestOrdered searchRequestOrdered)
        {
            _personSought = searchRequestOrdered.Person;
            var cts = new CancellationTokenSource();

            _cancellationToken = cts.Token;

            SearchRequestEntity searchRequestEntity = _mapper.Map <SearchRequestEntity>(searchRequestOrdered);

            searchRequestEntity.CreatedByApi = true;
            searchRequestEntity.SendNotificationOnCreation = true;
            _uploadedSearchRequest = await _searchRequestService.CreateSearchRequest(searchRequestEntity, cts.Token);

            if (_uploadedSearchRequest == null)
            {
                return(null);
            }
            _logger.LogInformation("Create Search Request successfully");

            PersonEntity personEntity = _mapper.Map <PersonEntity>(_personSought);

            personEntity.SearchRequest     = _uploadedSearchRequest;
            personEntity.InformationSource = InformationSourceType.Request.Value;
            personEntity.IsCreatedByAgency = true;
            personEntity.IsPrimary         = true;
            _uploadedPerson = await _searchRequestService.SavePerson(personEntity, _cancellationToken);

            _logger.LogInformation("Create Person successfully");

            await UploadIdentifiers();
            await UploadAddresses();
            await UploadPhones();
            await UploadEmployment();
            await UploadRelatedPersons();
            await UploadRelatedApplicant(_uploadedSearchRequest.ApplicantFirstName, _uploadedSearchRequest.ApplicantLastName);
            await UploadAliases();
            await UploadSafetyConcern();

            return(_uploadedSearchRequest);
        }
        public async Task person_does_not_contain_same_relatedperson_Exists_should_return_empty_guid()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedRelatedPersonID = Guid.NewGuid();
            SSG_Person person = new SSG_Person()
            {
                SSG_Identities = new List <SSG_Identity>()
                {
                    new SSG_Identity()
                    {
                        FirstName = "11111", RelatedPersonId = existedRelatedPersonID
                    }
                }.ToArray()
            };
            RelatedPersonEntity entity = new RelatedPersonEntity()
            {
                FirstName = "11121"
            };
            Guid guid = await _sut.Exists(person, entity);

            Assert.AreEqual(Guid.Empty, guid);
        }
        public async Task person_does_not_contain_same_vehicle_Exists_should_return_empty_guid()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedVehicleID = Guid.NewGuid();
            SSG_Person person           = new SSG_Person()
            {
                SSG_Asset_Vehicles = new List <SSG_Asset_Vehicle>()
                {
                    new SSG_Asset_Vehicle()
                    {
                        Vin = "vin", PlateNumber = "platenumber", VehicleId = existedVehicleID
                    }
                }.ToArray()
            };
            VehicleEntity entity = new VehicleEntity()
            {
                Vin = "vin", PlateNumber = "platenumber2"
            };
            Guid guid = await _sut.Exists(person, entity);

            Assert.AreEqual(Guid.Empty, guid);
        }
        public async Task person_does_not_contain_same_name_Exists_should_return_empty_guid()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedAliasID = Guid.NewGuid();
            SSG_Person person         = new SSG_Person()
            {
                SSG_Aliases = new List <SSG_Aliase>()
                {
                    new SSG_Aliase()
                    {
                        FirstName = "firstname", MiddleName = "middlename", LastName = "lastName", AliasId = existedAliasID
                    }
                }.ToArray()
            };
            AliasEntity entity = new AliasEntity()
            {
                FirstName = "firstnameNew", LastName = "lastName"
            };
            Guid guid = await _sut.Exists(person, entity);

            Assert.AreEqual(Guid.Empty, guid);
        }
        public async Task person_does_not_contain_same_address_Exists_should_return_empty_guid()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedAddressID = Guid.NewGuid();
            SSG_Person person           = new SSG_Person()
            {
                SSG_Addresses = new List <SSG_Address>()
                {
                    new SSG_Address()
                    {
                        AddressLine1 = "11111", AddressLine2 = "111", City = "city", CountryText = "usa", AddressId = existedAddressID
                    }
                }.ToArray()
            };
            AddressEntity entity = new AddressEntity()
            {
                AddressLine1 = "11111", AddressLine2 = "111", CountryText = "canada"
            };
            Guid guid = await _sut.Exists(person, entity);

            Assert.AreEqual(Guid.Empty, guid);
        }
        public async Task person_does_not_contain_same_phonenumber_Exists_should_return_empty_guid()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedPhoneID = Guid.NewGuid();
            SSG_Person person         = new SSG_Person()
            {
                SSG_PhoneNumbers = new List <SSG_PhoneNumber>()
                {
                    new SSG_PhoneNumber()
                    {
                        TelePhoneNumber = "111112", PhoneExtension = "111", PhoneNumberId = existedPhoneID
                    }
                }.ToArray()
            };
            PhoneNumberEntity entity = new PhoneNumberEntity()
            {
                TelePhoneNumber = "11111", PhoneExtension = "111"
            };
            Guid guid = await _sut.Exists(person, entity);

            Assert.AreEqual(Guid.Empty, guid);
        }
        public async Task person_does_not_contain_same_identifier_Exists_should_return_empty_guid()
        {
            DuplicateDetectionService._configs = null;
            Guid       existedIdentifierID = Guid.NewGuid();
            SSG_Person person = new SSG_Person()
            {
                SSG_Identifiers = new List <SSG_Identifier>()
                {
                    new SSG_Identifier()
                    {
                        Identification = "22111", IdentifierType = IdentificationType.BCDriverLicense.Value, IdentifierId = existedIdentifierID
                    }
                }.ToArray()
            };
            IdentifierEntity entity = new IdentifierEntity()
            {
                Identification = "11111", IdentifierType = IdentificationType.BCDriverLicense.Value
            };
            Guid guid = await _sut.Exists(person, entity);

            Assert.AreEqual(Guid.Empty, guid);
        }
 private async Task <bool> UploadBankInfos(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
 {
     if (person.BankInfos == null)
     {
         return(true);
     }
     try
     {
         foreach (var bankInfo in person.BankInfos)
         {
             SSG_Asset_BankingInformation bank = _mapper.Map <SSG_Asset_BankingInformation>(bankInfo);
             bank.SearchRequest     = request;
             bank.InformationSource = providerDynamicsID;
             bank.Person            = ssg_person;
             await _searchRequestService.CreateBankInfo(bank, concellationToken);
         }
         return(true);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
        private async Task <bool> UploadVehicles(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
        {
            if (person.Vehicles == null)
            {
                return(true);
            }
            try
            {
                foreach (var v in person.Vehicles)
                {
                    VehicleEntity vehicle = _mapper.Map <VehicleEntity>(v);
                    vehicle.SearchRequest     = request;
                    vehicle.InformationSource = providerDynamicsID;
                    vehicle.Person            = ssg_person;
                    SSG_Asset_Vehicle ssgVehicle = await _searchRequestService.CreateVehicle(vehicle, concellationToken);

                    if (v.Owners != null)
                    {
                        foreach (var owner in v.Owners)
                        {
                            SSG_AssetOwner assetOwner = _mapper.Map <SSG_AssetOwner>(owner);
                            assetOwner.Vehicle = ssgVehicle;
                            await _searchRequestService.CreateAssetOwner(assetOwner, concellationToken);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(false);
            }
        }
        private async Task <bool> UploadOtherAssets(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
        {
            if (person.OtherAssets == null)
            {
                return(true);
            }
            try
            {
                foreach (OtherAsset asset in person.OtherAssets)
                {
                    AssetOtherEntity other = _mapper.Map <AssetOtherEntity>(asset);
                    other.SearchRequest     = request;
                    other.InformationSource = providerDynamicsID;
                    other.Person            = ssg_person;
                    SSG_Asset_Other ssgOtherAsset = await _searchRequestService.CreateOtherAsset(other, concellationToken);

                    if (asset.Owners != null)
                    {
                        foreach (var owner in asset.Owners)
                        {
                            SSG_AssetOwner assetOwner = _mapper.Map <SSG_AssetOwner>(owner);
                            assetOwner.OtherAsset = ssgOtherAsset;
                            await _searchRequestService.CreateAssetOwner(assetOwner, concellationToken);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(false);
            }
        }
 private async Task <bool> UploadIdentifiers(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
 {
     if (person.Identifiers == null)
     {
         return(true);
     }
     try
     {
         foreach (var matchFoundPersonId in person.Identifiers)
         {
             SSG_Identifier identifier = _mapper.Map <SSG_Identifier>(matchFoundPersonId);
             identifier.SearchRequest     = request;
             identifier.InformationSource = providerDynamicsID;
             identifier.Person            = ssg_person;
             var identifer = await _searchRequestService.CreateIdentifier(identifier, concellationToken);
         }
         return(true);
     }catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
        public void Init()
        {
            _testGuid         = Guid.NewGuid();
            _searchRequestKey = "fileId_SequenceNumber";
            _searchRequestKeySearchNotComplete = "fileId_SequenceNumber_NotComplete";
            _exceptionSearchRequestKey         = "exception_seqNum";
            _exceptionGuid = Guid.NewGuid();
            _loggerMock    = new Mock <ILogger <PersonSearchController> >();
            _searchApiRequestServiceMock = new Mock <ISearchApiRequestService>();
            _searchResultServiceMock     = new Mock <ISearchResultService>();
            _dataPartnerServiceMock      = new Mock <IDataPartnerService>();
            _mapper       = new Mock <IMapper>();
            _registerMock = new Mock <ISearchRequestRegister>();

            _fakeSearchApiRequest = new SSG_SearchApiRequest()
            {
                SearchApiRequestId = _testGuid
            };

            var validRequestId   = Guid.NewGuid();
            var invalidRequestId = Guid.NewGuid();

            _fakeSearchApiEvent = new SSG_SearchApiEvent {
            };

            _fakePersoneIdentifier = new IdentifierEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };


            _fakePersonAddress = new AddressEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakePersonPhoneNumber = new PhoneNumberEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakeName = new AliasEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakePerson = new SSG_Person
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakeSourceIdentifier = new SSG_Identifier()
            {
                IdentifierId = Guid.NewGuid()
            };

            _fakePersonAcceptedEvent = new PersonSearchAccepted()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                }
            };

            _fakePersonCompletedEvent = new PersonSearchCompleted()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                MatchedPersons = new List <PersonFound>()
                {
                    new PersonFound()
                    {
                        DateOfBirth = DateTime.Now,
                        FirstName   = "TEST1",
                        LastName    = "TEST2",
                        Identifiers = new List <PersonalIdentifier>()
                        {
                        },
                        Addresses = new List <Address>()
                        {
                        },
                        Phones = new List <Phone>()
                        {
                        },
                        Names = new List <Name>()
                        {
                        },
                        SourcePersonalIdentifier = new PersonalIdentifier()
                        {
                            Value = "1234567"
                        }
                    }
                }
            };

            _fakePersonFailedEvent = new PersonSearchFailed()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Cause = "Unable to proceed"
            };


            _fakePersonRejectEvent = new PersonSearchRejected()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Reasons = new List <ValidationResult> {
                }
            };

            _fakePersonFinalizedEvent = new PersonSearchFinalized()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                Message          = "test message"
            };

            _fakePersonSubmittedEvent = new PersonSearchSubmitted()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Message = "the search api request has been submitted to the Data provider."
            };

            _fakePersonInformationEvent = new PersonSearchInformation
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Message = "Recieved info from data provider"
            };

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchAccepted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchRejected>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchFailed>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchCompleted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchSubmitted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <IdentifierEntity>(It.IsAny <PersonalIdentifier>()))
            .Returns(_fakePersoneIdentifier);

            _mapper.Setup(m => m.Map <PhoneNumberEntity>(It.IsAny <Phone>()))
            .Returns(_fakePersonPhoneNumber);

            _mapper.Setup(m => m.Map <AddressEntity>(It.IsAny <Address>()))
            .Returns(_fakePersonAddress);

            _mapper.Setup(m => m.Map <AliasEntity>(It.IsAny <Name>()))
            .Returns(_fakeName);

            _mapper.Setup(m => m.Map <SSG_Person>(It.IsAny <Person>()))
            .Returns(_fakePerson);


            _searchApiRequestServiceMock.Setup(x => x.GetLinkedSearchRequestIdAsync(It.Is <Guid>(x => x == _testGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Guid>(_testGuid));

            _searchApiRequestServiceMock.Setup(x => x.GetLinkedSearchRequestIdAsync(It.Is <Guid>(x => x == _exceptionGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Guid>(invalidRequestId));


            _searchApiRequestServiceMock.Setup(x => x.MarkComplete(It.Is <Guid>(x => x == _testGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchApiRequest>(new SSG_SearchApiRequest()
            {
                SearchApiRequestId = _testGuid,
                SequenceNumber     = "1234567"
            }));

            _dataPartnerServiceMock
            .Setup(x => x.GetSearchApiRequestDataProvider(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchapiRequestDataProvider {
                AdaptorName = "ICBC", SearchAPIRequestId = _testGuid, NumberOfFailures = 0, TimeBetweenRetries = 10
            }));


            _dataPartnerServiceMock
            .Setup(x => x.UpdateSearchRequestApiProvider(It.IsAny <SSG_SearchapiRequestDataProvider>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchapiRequestDataProvider {
                AdaptorName = "ICBC", SearchAPIRequestId = _testGuid, NumberOfFailures = 0, TimeBetweenRetries = 10
            }));

            _searchResultServiceMock.Setup(x => x.ProcessPersonFound(It.Is <Person>(x => x.FirstName == "TEST1"), It.IsAny <ProviderProfile>(), It.IsAny <SSG_SearchRequest>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>(), It.IsAny <SSG_Identifier>()))
            .Returns(Task.FromResult <bool>(true));

            _searchApiRequestServiceMock.Setup(x => x.AddEventAsync(It.Is <Guid>(x => x == _testGuid),
                                                                    It.IsAny <SSG_SearchApiEvent>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchApiEvent>(new SSG_SearchApiEvent()
            {
                Id   = _testGuid,
                Name = "Random Event"
            }));

            _searchApiRequestServiceMock.Setup(x => x.AddEventAsync(It.Is <Guid>(x => x == _exceptionGuid),
                                                                    It.IsAny <SSG_SearchApiEvent>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception("random exception"));

            _registerMock.Setup(x => x.GetSearchApiRequest(It.Is <string>(m => m == _searchRequestKey)))
            .Returns(Task.FromResult(_fakeSearchApiRequest));
            _registerMock.Setup(x => x.GetSearchApiRequest(It.Is <string>(m => m == _searchRequestKeySearchNotComplete)))
            .Returns(Task.FromResult(_fakeSearchApiRequest));

            _registerMock.Setup(x => x.DataPartnerSearchIsComplete(It.Is <string>(m => m == _searchRequestKey)))
            .Returns(Task.FromResult(true));

            _registerMock.Setup(x => x.DataPartnerSearchIsComplete(It.Is <string>(m => m == _searchRequestKeySearchNotComplete)))
            .Returns(Task.FromResult(false));

            _registerMock.Setup(x => x.GetMatchedSourceIdentifier(It.IsAny <PersonalIdentifier>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(_fakeSourceIdentifier));

            _registerMock.Setup(x => x.RemoveSearchApiRequest(It.IsAny <Guid>()))
            .Returns(Task.FromResult(true));

            _sut = new PersonSearchController(_searchResultServiceMock.Object, _searchApiRequestServiceMock.Object, _dataPartnerServiceMock.Object, _loggerMock.Object, _mapper.Object, _registerMock.Object);
        }
Beispiel #23
0
        public async Task <SSG_SearchRequest> ProcessUpdateSearchRequest(SearchRequestOrdered searchRequestOrdered)
        {
            var cts = new CancellationTokenSource();

            _cancellationToken = cts.Token;
            SSG_SearchRequest existedSearchRequest = await VerifySearchRequest(searchRequestOrdered);

            if (existedSearchRequest == null)
            {
                return(null);
            }
            existedSearchRequest.IsDuplicated = true;
            _uploadedSearchRequest            = existedSearchRequest;

            //get existedPersonSought
            SSG_Person existedSoughtPerson = existedSearchRequest?.SSG_Persons?.FirstOrDefault(
                m => m.IsPrimary == true);

            if (existedSoughtPerson == null)
            {
                string error = "the updating personSought does not exist. something is wrong.";
                _logger.LogError(error);
                throw new Exception(error);
            }
            existedSoughtPerson = await _searchRequestService.GetPerson(existedSoughtPerson.PersonId, _cancellationToken);

            existedSoughtPerson.IsDuplicated = true;
            _uploadedPerson = existedSoughtPerson;


            SearchRequestEntity newSearchRequest = _mapper.Map <SearchRequestEntity>(searchRequestOrdered);

            if (newSearchRequest == null)
            {
                string error = "cannot do updating as newSearchRequest is null";
                _logger.LogError(error);
                throw new Exception(error);
            }

            //update searchRequestEntity
            await UpdateSearchRequest(newSearchRequest);

            //update notesEntity
            if (!String.IsNullOrEmpty(newSearchRequest.Notes) &&
                !String.Equals(existedSearchRequest.Notes, newSearchRequest.Notes, StringComparison.InvariantCultureIgnoreCase))
            {
                await UploadNotes(newSearchRequest, existedSearchRequest);
            }

            //update PersonEntity
            if (searchRequestOrdered.Person == null)
            {
                string error = "the searchRequestOrdered does not contain Person. The request is wrong.";
                _logger.LogError(error);
                throw new Exception(error);
            }
            _personSought = searchRequestOrdered.Person;

            await UpdatePersonSought();
            await UpdateSafetyConcern();

            //update RelatedPerson applicant
            await UpdateRelatedApplicant((string.IsNullOrEmpty(newSearchRequest.ApplicantFirstName) && string.IsNullOrEmpty(newSearchRequest.ApplicantLastName))?null : new RelatedPersonEntity()
            {
                FirstName  = newSearchRequest.ApplicantFirstName,
                LastName   = newSearchRequest.ApplicantLastName,
                StatusCode = 1
            });

            //update identifiers
            //await UpdateIdentifiers();
            await UploadIdentifiers(true);

            //update employment
            await UploadEmployment(true);

            //for phones, addresses, relatedPersons, names are same as creation, as if different, add new one, if same, ignore
            await UploadAddresses(true);
            await UploadPhones(true);
            await UploadRelatedPersons(true);
            await UploadAliases(true);



            return(_uploadedSearchRequest);
        }
        public void Init()
        {
            _testGuid      = Guid.NewGuid();
            _testFileId    = "testFileId";
            _exceptionGuid = Guid.NewGuid();
            _loggerMock    = new Mock <ILogger <PersonSearchController> >();
            _searchApiRequestServiceMock = new Mock <ISearchApiRequestService>();
            _searchResultServiceMock     = new Mock <ISearchResultService>();
            _mapper = new Mock <IMapper>();
            var validRequestId   = Guid.NewGuid();
            var invalidRequestId = Guid.NewGuid();

            _fakeSearchApiEvent = new SSG_SearchApiEvent {
            };

            _fakePersoneIdentifier = new SSG_Identifier {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakePersonAddress = new SSG_Address
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakePersonPhoneNumber = new SSG_PhoneNumber
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakeName = new SSG_Aliase
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakePerson = new SSG_Person
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakePersonAcceptedEvent = new PersonSearchAccepted()
            {
                SearchRequestId = Guid.NewGuid(),
                FileId          = _testFileId,
                TimeStamp       = DateTime.Now,
                ProviderProfile = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                }
            };

            _fakePersonCompletedEvent = new PersonSearchCompleted()
            {
                SearchRequestId = Guid.NewGuid(),
                FileId          = _testFileId,
                TimeStamp       = DateTime.Now,
                ProviderProfile = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                MatchedPersons = new List <Person>()
                {
                    new Person()
                    {
                        DateOfBirth = DateTime.Now,
                        FirstName   = "TEST1",
                        LastName    = "TEST2",
                        Identifiers = new List <PersonalIdentifier>()
                        {
                        },
                        Addresses = new List <Address>()
                        {
                        },
                        Phones = new List <Phone>()
                        {
                        },
                        Names = new List <Name>()
                        {
                        }
                    }
                }
            };

            _fakePersonFailedEvent = new PersonSearchFailed()
            {
                SearchRequestId = Guid.NewGuid(),
                FileId          = _testFileId,
                TimeStamp       = DateTime.Now,
                ProviderProfile = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Cause = "Unable to proceed"
            };

            _fakePersonRejectEvent = new PersonSearchRejected()
            {
                SearchRequestId = Guid.NewGuid(),
                FileId          = _testFileId,
                TimeStamp       = DateTime.Now,
                ProviderProfile = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Reasons = new List <ValidationResult> {
                }
            };

            _fakePersonFinalizedEvent = new PersonSearchFinalized()
            {
                SearchRequestId = Guid.NewGuid(),
                FileId          = _testFileId,
                TimeStamp       = DateTime.Now,
                Message         = "test message"
            };


            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchAccepted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchRejected>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchFailed>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchCompleted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_Identifier>(It.IsAny <PersonalIdentifier>()))
            .Returns(_fakePersoneIdentifier);

            _mapper.Setup(m => m.Map <SSG_PhoneNumber>(It.IsAny <Phone>()))
            .Returns(_fakePersonPhoneNumber);

            _mapper.Setup(m => m.Map <SSG_Address>(It.IsAny <Address>()))
            .Returns(_fakePersonAddress);

            _mapper.Setup(m => m.Map <SSG_Aliase>(It.IsAny <Name>()))
            .Returns(_fakeName);

            _mapper.Setup(m => m.Map <SSG_Person>(It.IsAny <Person>()))
            .Returns(_fakePerson);


            _searchApiRequestServiceMock.Setup(x => x.GetLinkedSearchRequestIdAsync(It.Is <Guid>(x => x == _testGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Guid>(_testGuid));

            _searchApiRequestServiceMock.Setup(x => x.GetLinkedSearchRequestIdAsync(It.Is <Guid>(x => x == _exceptionGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Guid>(invalidRequestId));


            _searchApiRequestServiceMock.Setup(x => x.MarkComplete(It.Is <Guid>(x => x == _testGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchApiRequest>(new SSG_SearchApiRequest()
            {
                SearchApiRequestId = _testGuid,
                Name = "Random Event"
            }));

            _searchResultServiceMock.Setup(x => x.ProcessPersonFound(It.Is <Person>(x => x.FirstName == "TEST1"), It.IsAny <ProviderProfile>(), It.IsAny <SSG_SearchRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <bool>(true));

            _searchApiRequestServiceMock.Setup(x => x.AddEventAsync(It.Is <Guid>(x => x == _testGuid),
                                                                    It.IsAny <SSG_SearchApiEvent>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchApiEvent>(new SSG_SearchApiEvent()
            {
                Id   = _testGuid,
                Name = "Random Event"
            }));

            _searchApiRequestServiceMock.Setup(x => x.AddEventAsync(It.Is <Guid>(x => x == _exceptionGuid),
                                                                    It.IsAny <SSG_SearchApiEvent>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception("random exception"));

            _sut = new PersonSearchController(_searchResultServiceMock.Object, _searchApiRequestServiceMock.Object, _loggerMock.Object, _mapper.Object);
        }