Beispiel #1
0
 private async Task <bool> UploadNames( )
 {
     if (_foundPerson.Names == null)
     {
         return(true);
     }
     try
     {
         _logger.LogDebug($"Attempting to create found name records for SearchRequest[{_searchRequest.SearchRequestId}]");
         foreach (var name in _foundPerson.Names)
         {
             AliasEntity n = _mapper.Map <AliasEntity>(name);
             n.SearchRequest     = _searchRequest;
             n.InformationSource = _providerDynamicsID;
             n.Person            = _returnedPerson;
             SSG_Aliase alias = await _searchRequestService.CreateName(n, _cancellationToken);
             await CreateResultTransaction(alias);
         }
         return(true);
     }
     catch (Exception ex)
     {
         LogException(ex);
         return(false);
     }
 }
        public async Task with_duplicated_person_not_contains_same_alias_should_return_new_SSG_Alias()
        {
            _odataClientMock.Setup(x => x.For <SSG_Aliase>(null).Set(It.Is <AliasEntity>(x => x.FirstName == "notContain"))
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_Aliase()
            {
                AliasId = _testAliasId
            })
                     );
            _duplicateServiceMock.Setup(x => x.Exists(It.Is <SSG_Person>(m => m.PersonId == _testId), It.Is <AliasEntity>(m => m.FirstName == "notContain")))
            .Returns(Task.FromResult(Guid.Empty));

            var alias = new AliasEntity()
            {
                FirstName = "notContain",
                Person    = new SSG_Person()
                {
                    PersonId     = _testId,
                    IsDuplicated = true
                }
            };
            var result = await _sut.CreateName(alias, CancellationToken.None);

            Assert.AreEqual(_testAliasId, result.AliasId);
        }
Beispiel #3
0
        private async Task <bool> UploadAliases(bool inUpdateProcess = false)
        {
            if (_personSought.Names == null)
            {
                return(true);
            }

            _logger.LogDebug($"Attempting to create aliases for SoughtPerson");

            foreach (var name in _personSought.Names.Where(m => m.Owner == OwnerType.PersonSought))
            {
                AliasEntity aliasEntity = _mapper.Map <AliasEntity>(name);
                aliasEntity.SearchRequest     = _uploadedSearchRequest;
                aliasEntity.InformationSource = InformationSourceType.Request.Value;
                aliasEntity.Person            = _uploadedPerson;
                aliasEntity.IsCreatedByAgency = true;
                aliasEntity.UpdatedByApi      = inUpdateProcess;
                if (inUpdateProcess)
                {
                    aliasEntity.UpdateDetails = "New Alias";
                }
                await _searchRequestService.CreateName(aliasEntity, _cancellationToken);
            }
            _logger.LogInformation("Create alias records for SearchRequest successfully");
            return(true);
        }
        public async Task with_non_duplicated_person_createName_should_return_new_SSG_Aliase()
        {
            _odataClientMock.Setup(x => x.For <SSG_Aliase>(null).Set(It.Is <AliasEntity>(x => x.FirstName == "firstname"))
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_Aliase()
            {
                AliasId = _testAliasId
            })
                     );
            var alias = new AliasEntity()
            {
                Date1      = DateTime.Now,
                Date1Label = "Effective Date",
                Date2      = new DateTime(2001, 1, 1),
                Date2Label = "Expiry Date",
                FirstName  = "firstname",
                Person     = new SSG_Person()
                {
                    IsDuplicated = false
                }
            };
            var result = await _sut.CreateName(alias, CancellationToken.None);

            Assert.AreEqual(_testAliasId, result.AliasId);
        }
Beispiel #5
0
 public async Task Save(Alias model)
 {
     await InTx(async session =>
     {
         AliasEntity entity = await session.GetAsync <AliasEntity>(model.Id).ConfigureAwait(false) ?? new AliasEntity();
         entity.Site        = await session.GetAsync <SiteEntity>(model.SiteId).ConfigureAwait(false);
         entity.AliasUrl    = model.AliasUrl;
         entity.RedirectUrl = model.RedirectUrl;
         entity.Type        = model.Type;
         await session.SaveOrUpdateAsync(entity).ConfigureAwait(false);
         model.Id = entity.Id;
     }).ConfigureAwait(false);
 }
        public override string TryToExecute(CommandReceivedEventArgs eventArgs)
        {
            if (eventArgs?.Arguments == null ||
                eventArgs.Arguments.Count < 3)
            {
                return(HelpText);
            }

            var word      = eventArgs.Arguments[1].ToLowerInvariant();
            var newAlias  = eventArgs.Arguments[2].ToLowerInvariant();
            var arguments = eventArgs.Arguments.Skip(3).ToList();

            var commandEntity = _repository.Single(CommandPolicy.ByWord(word));
            var existingWord  = _repository.Single(CommandPolicy.ByWord(newAlias));

            if (string.IsNullOrEmpty(newAlias))
            {
                return("You seem to be missing the new alias you want to set.");
            }

            if (existingWord != null)
            {
                return($"The command word '!{existingWord.CommandWord}' already exists.");
            }

            var alias = new AliasEntity
            {
                Word    = newAlias,
                Command = commandEntity,
            };

            for (int i = 0; i < arguments.Count; i++)
            {
                alias.Arguments.Add(new AliasArgumentEntity
                {
                    Argument = arguments[i],
                    Alias    = alias,
                    Index    = i
                });
            }

            commandEntity.Aliases.Add(alias);

            _repository.Update(commandEntity);

            return($"Created new command alias '!{newAlias}' for '!{word}'.");
        }
Beispiel #7
0
        public async Task <SSG_Aliase> CreateName(AliasEntity name, CancellationToken cancellationToken)
        {
            if (name.Person.IsDuplicated)
            {
                Guid duplicatedNameId = await _duplicateDetectService.Exists(name.Person, name);

                if (duplicatedNameId != Guid.Empty)
                {
                    return new SSG_Aliase()
                           {
                               AliasId = duplicatedNameId
                           }
                }
                ;
            }
            return(await this._oDataClient.For <SSG_Aliase>().Set(name).InsertEntryAsync(cancellationToken));
        }
        public async Task with_duplicated_person_contains_same_alias_should_return_original_alias_guid()
        {
            _duplicateServiceMock.Setup(x => x.Exists(It.Is <SSG_Person>(m => m.PersonId == _testId), It.Is <AliasEntity>(m => m.FirstName == "contains")))
            .Returns(Task.FromResult(_testAliasId));

            var alias = new AliasEntity()
            {
                FirstName = "contains",
                Person    = new SSG_Person()
                {
                    PersonId     = _testId,
                    IsDuplicated = true
                }
            };
            var result = await _sut.CreateName(alias, CancellationToken.None);

            Assert.AreEqual(_testAliasId, result.AliasId);
        }
        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);
        }
Beispiel #10
0
        public void Init()
        {
            _loggerMock = new Mock <ILogger <SearchResultService> >();
            _searchRequestServiceMock = new Mock <ISearchRequestService>();
            _mapper = new Mock <IMapper>();
            var validRequestId = Guid.NewGuid();

            var validVehicleId         = Guid.NewGuid();
            var validOtherAssetId      = Guid.NewGuid();
            var validBankInformationId = Guid.NewGuid();
            var validEmploymentId      = Guid.NewGuid();

            _fakePersoneIdentifier = new IdentifierEntity
            {
                Identification = "1234567",
                SearchRequest  = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

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

            _fakePersonAddress = new AddressEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                },
                AddressLine1 = "addressLine1"
            };
            _fakeEmployment = new EmploymentEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakeEmploymentContact = new EmploymentContactEntity
            {
                PhoneNumber = "11111111"
            };

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

            _fakeRelatedPerson = new RelatedPersonEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

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

            _ssg_fakePerson = new PersonEntity
            {
            };

            _searchRequest = new SSG_SearchRequest
            {
                SearchRequestId = validRequestId
            };

            _fakeBankInfo = new BankingInformationEntity
            {
                BankName = "bank"
            };

            _fakeVehicleEntity = new VehicleEntity
            {
                SearchRequest = _searchRequest,
                PlateNumber   = "AAA.BBB"
            };

            _fakeAssetOwner = new SSG_AssetOwner()
            {
                OrganizationName = "Ford Inc."
            };

            _fakeOtherAsset = new AssetOtherEntity()
            {
                SearchRequest   = _searchRequest,
                TypeDescription = "type description"
            };

            _fakeWorkSafeBcClaim = new CompensationClaimEntity()
            {
                SearchRequest      = _searchRequest,
                ClaimNumber        = "claimNumber",
                BankingInformation = new SSG_Asset_BankingInformation()
                {
                    BankingInformationId = validBankInformationId
                },
                Employment = new SSG_Employment()
                {
                    EmploymentId = validEmploymentId
                }
            };

            _fakeCompensationEmployment = new EmploymentEntity()
            {
                BusinessName = COMPENSATION_BUISNESS_NAME
            };

            _fakeIcbcClaim = new ICBCClaimEntity()
            {
                ClaimNumber = "icbcClaimNumber"
            };

            _fakeInvolvedParty = new SSG_InvolvedParty()
            {
                OrganizationName = "name"
            };

            _fakeSimplePhone = new SSG_SimplePhoneNumber()
            {
                PhoneNumber = "0"
            };

            _fakePerson = new Person()
            {
                DateOfBirth = DateTime.Now,
                FirstName   = "TEST1",
                LastName    = "TEST2",
                Identifiers = new List <PersonalIdentifier>()
                {
                    new PersonalIdentifier()
                    {
                        Value    = "test",
                        IssuedBy = "test",
                        Type     = PersonalIdentifierType.BCDriverLicense
                    }
                },
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        AddressLine1   = "AddressLine1",
                        AddressLine2   = "AddressLine2",
                        AddressLine3   = "AddressLine3",
                        StateProvince  = "Manitoba",
                        City           = "testCity",
                        Type           = "residence",
                        CountryRegion  = "canada",
                        ZipPostalCode  = "p3p3p3",
                        ReferenceDates = new List <ReferenceDate>()
                        {
                            new ReferenceDate()
                            {
                                Index = 0, Key = "Start Date", Value = new DateTime(2019, 9, 1)
                            },
                            new ReferenceDate()
                            {
                                Index = 1, Key = "End Date", Value = new DateTime(2020, 9, 1)
                            }
                        },
                        Description = "description"
                    }
                },
                Phones = new List <Phone>()
                {
                    new Phone()
                    {
                        PhoneNumber = "4005678900"
                    }
                },
                Names = new List <Name>()
                {
                    new Name()
                    {
                        FirstName = "firstName"
                    }
                },
                RelatedPersons = new List <RelatedPerson>()
                {
                    new RelatedPerson()
                    {
                        FirstName = "firstName"
                    }
                },

                Employments = new List <Employment>()
                {
                    new Employment()
                    {
                        Occupation = "Occupation",
                        Employer   = new Employer()
                        {
                            Phones = new List <Phone>()
                            {
                                new Phone()
                                {
                                    PhoneNumber = "1111111", Type = "Phone"
                                }
                            }
                        }
                    }
                },

                BankInfos = new List <BankInfo>()
                {
                    new BankInfo()
                    {
                        BankName = "BankName",
                    }
                },
                Vehicles = new List <Vehicle>()
                {
                    new Vehicle()
                    {
                    },
                    new Vehicle()
                    {
                        Owners = new List <InvolvedParty>()
                        {
                            new InvolvedParty()
                            {
                            }
                        }
                    }
                },
                OtherAssets = new List <OtherAsset>()
                {
                    new OtherAsset()
                    {
                        Owners = new List <InvolvedParty>()
                        {
                            new InvolvedParty()
                            {
                            }
                        }
                    }
                },
                CompensationClaims = new List <CompensationClaim>()
                {
                    new CompensationClaim()
                    {
                        ClaimNumber = "claimNumber",
                        BankInfo    = new BankInfo()
                        {
                            BankName = "compensationBankName"
                        },
                        Employer = new Employer()
                        {
                            Name = COMPENSATION_BUISNESS_NAME
                        },
                        ReferenceDates = new ReferenceDate[]
                        {
                            new ReferenceDate()
                            {
                                Index = 0, Key = "Start Date", Value = new DateTime(2019, 9, 1)
                            }
                        }
                    }
                },
                InsuranceClaims = new List <InsuranceClaim>()
                {
                    new InsuranceClaim()
                    {
                        ClaimNumber    = "icbcClaimNumber",
                        InsuredParties = new List <InvolvedParty>()
                        {
                            new InvolvedParty()
                            {
                                Organization = "insuranceClaimOrg"
                            }
                        },
                        ClaimCentre = new ClaimCentre()
                        {
                            ContactNumber = new List <Phone>()
                            {
                                new Phone()
                                {
                                    PhoneNumber = "9999"
                                }
                            }
                        }
                    }
                }
            };

            _providerProfile = new ProviderProfile()
            {
                Name = "Other"
            };


            _fakeToken = new CancellationToken();

            _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 <PersonEntity>(It.IsAny <Person>()))
            .Returns(_ssg_fakePerson);

            _mapper.Setup(m => m.Map <EmploymentEntity>(It.Is <Employer>(m => m.Name == COMPENSATION_BUISNESS_NAME)))
            .Returns(_fakeCompensationEmployment);

            _mapper.Setup(m => m.Map <EmploymentEntity>(It.IsAny <Employment>()))
            .Returns(_fakeEmployment);

            _mapper.Setup(m => m.Map <EmploymentContactEntity>(It.IsAny <Phone>()))
            .Returns(_fakeEmploymentContact);

            _mapper.Setup(m => m.Map <RelatedPersonEntity>(It.IsAny <RelatedPerson>()))
            .Returns(_fakeRelatedPerson);

            _mapper.Setup(m => m.Map <BankingInformationEntity>(It.IsAny <BankInfo>()))
            .Returns(_fakeBankInfo);

            _mapper.Setup(m => m.Map <VehicleEntity>(It.IsAny <Vehicle>()))
            .Returns(_fakeVehicleEntity);

            _mapper.Setup(m => m.Map <AssetOwnerEntity>(It.IsAny <InvolvedParty>()))
            .Returns(_fakeAssetOwner);

            _mapper.Setup(m => m.Map <AssetOtherEntity>(It.IsAny <OtherAsset>()))
            .Returns(_fakeOtherAsset);

            _mapper.Setup(m => m.Map <CompensationClaimEntity>(It.IsAny <CompensationClaim>()))
            .Returns(_fakeWorkSafeBcClaim);

            _mapper.Setup(m => m.Map <ICBCClaimEntity>(It.IsAny <InsuranceClaim>()))
            .Returns(_fakeIcbcClaim);

            _mapper.Setup(m => m.Map <InvolvedPartyEntity>(It.Is <InvolvedParty>(m => m.Organization == "insuranceClaimOrg")))
            .Returns(_fakeInvolvedParty);

            _mapper.Setup(m => m.Map <SimplePhoneNumberEntity>(It.Is <Phone>(m => m.PhoneNumber == "9999")))
            .Returns(_fakeSimplePhone);

            _searchRequestServiceMock.Setup(x => x.CreateIdentifier(It.IsAny <IdentifierEntity>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Identifier>(new SSG_Identifier()
            {
            }));

            _searchRequestServiceMock.Setup(x => x.CreateAddress(It.Is <AddressEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Address>(new SSG_Address()
            {
                AddressLine1 = "test full line"
            }));

            _searchRequestServiceMock.Setup(x => x.CreatePhoneNumber(It.Is <PhoneNumberEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_PhoneNumber>(new SSG_PhoneNumber()
            {
                TelePhoneNumber = "4007678231"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateName(It.Is <AliasEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Aliase>(new SSG_Aliase()
            {
                FirstName = "firstName"
            }));

            _searchRequestServiceMock.Setup(x => x.SavePerson(It.Is <PersonEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Person>(new SSG_Person()
            {
                FirstName = "First"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateEmployment(It.Is <EmploymentEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Employment>(new SSG_Employment()
            {
                EmploymentId = Guid.NewGuid(),
                Occupation   = "Occupation"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateEmploymentContact(It.IsAny <EmploymentContactEntity>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_EmploymentContact>(new SSG_EmploymentContact()
            {
                PhoneNumber = "4007678231"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateRelatedPerson(It.Is <RelatedPersonEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Identity>(new SSG_Identity()
            {
                FirstName = "firstName"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateBankInfo(It.Is <BankingInformationEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Asset_BankingInformation>(new SSG_Asset_BankingInformation()
            {
                BankingInformationId = validBankInformationId,
                BankName             = "bankName"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateVehicle(It.Is <VehicleEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Asset_Vehicle>(new SSG_Asset_Vehicle()
            {
                VehicleId = validVehicleId
            }));

            _searchRequestServiceMock.Setup(x => x.CreateAssetOwner(It.Is <SSG_AssetOwner>(x => x.Vehicle.VehicleId == validVehicleId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_AssetOwner>(new SSG_AssetOwner()
            {
                Type = "Owner"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateOtherAsset(It.Is <AssetOtherEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Asset_Other>(new SSG_Asset_Other()
            {
                AssetOtherId = validOtherAssetId
            }));

            _searchRequestServiceMock.Setup(x => x.CreateCompensationClaim(It.Is <CompensationClaimEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Asset_WorkSafeBcClaim>(new SSG_Asset_WorkSafeBcClaim()
            {
                ClaimNumber = "claimNumber"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateEmployment(It.Is <EmploymentEntity>(x => x.BusinessName == COMPENSATION_BUISNESS_NAME && x.Date1 == new DateTime(2019, 9, 1)), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Employment>(new SSG_Employment()
            {
                EmploymentId = Guid.NewGuid(),
            }));

            _searchRequestServiceMock.Setup(x => x.CreateInsuranceClaim(It.Is <ICBCClaimEntity>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Asset_ICBCClaim>(new SSG_Asset_ICBCClaim()
            {
                ICBCClaimId = Guid.NewGuid()
            }));

            _searchRequestServiceMock.Setup(x => x.CreateInvolvedParty(It.IsAny <SSG_InvolvedParty>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_InvolvedParty>(new SSG_InvolvedParty()
            {
            }));

            _searchRequestServiceMock.Setup(x => x.CreateSimplePhoneNumber(It.IsAny <SSG_SimplePhoneNumber>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SimplePhoneNumber>(new SSG_SimplePhoneNumber()
            {
            }));

            _searchRequestServiceMock.Setup(x => x.CreateTransaction(It.IsAny <SSG_SearchRequestResultTransaction>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequestResultTransaction>(new SSG_SearchRequestResultTransaction()
            {
            }));

            _sut = new SearchResultService(_searchRequestServiceMock.Object, _loggerMock.Object, _mapper.Object);
        }
        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);
        }
        public void Init()
        {
            _validRequestId           = Guid.NewGuid();
            _loggerMock               = new Mock <ILogger <AgencyRequestService> >();
            _searchRequestServiceMock = new Mock <ISearchRequestService>();
            _mapper = new Mock <IMapper>();

            _searchRequestPerson = new Person()
            {
                DateOfBirth   = DateTime.Now,
                FirstName     = "TEST1",
                LastName      = "TEST2",
                CautionFlag   = "cautionFlag",
                CautionReason = "violence",
                Identifiers   = new List <PersonalIdentifier>()
                {
                    new PersonalIdentifier()
                    {
                        Value = "test",
                        Type  = PersonalIdentifierType.BCDriverLicense,
                        Owner = OwnerType.PersonSought
                    },
                    new PersonalIdentifier()
                    {
                        Value = "test2",
                        Type  = PersonalIdentifierType.SocialInsuranceNumber,
                        Owner = OwnerType.PersonSought
                    }
                },
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        AddressLine1 = "AddressLine1",
                        AddressLine2 = "AddressLine2",
                        City         = "testCity",
                        Owner        = OwnerType.PersonSought
                    }
                },
                Phones = new List <Phone>()
                {
                    new Phone()
                    {
                        PhoneNumber = "4005678900"
                    }
                },
                Names = new List <Name>()
                {
                    new Name()
                    {
                        FirstName   = "firstName",
                        Owner       = OwnerType.PersonSought,
                        Identifiers = new List <PersonalIdentifier> {
                            new PersonalIdentifier {
                                Value = "123222", Type = PersonalIdentifierType.BCDriverLicense
                            }
                        },
                        Addresses = new List <Address> {
                            new Address {
                                AddressLine1 = "line1"
                            }
                        },
                        Phones = new List <Phone>
                        {
                            new Phone {
                                PhoneNumber = "12343"
                            }
                        }
                    },
                    new Name()
                    {
                        FirstName = "applicantFirstName",
                        Owner     = OwnerType.Applicant
                    }
                },
                RelatedPersons = new List <RelatedPerson>()
                {
                    new RelatedPerson()
                    {
                        FirstName = "firstName"
                    }
                },

                Employments = new List <Employment>()
                {
                    new Employment()
                    {
                        Occupation = "Occupation",
                        Employer   = new Employer()
                        {
                            Phones = new List <Phone>()
                            {
                                new Phone()
                                {
                                    PhoneNumber = "1111111", Type = "Phone"
                                }
                            }
                        }
                    }
                },
                Agency = new Agency {
                    Code = "FMEP"
                }
            };

            _searchRequstOrdered = new SearchRequestOrdered()
            {
                Action           = RequestAction.NEW,
                RequestId        = "1111111",
                SearchRequestId  = Guid.NewGuid(),
                TimeStamp        = new DateTime(2010, 1, 1),
                SearchRequestKey = "key",
                Person           = _searchRequestPerson
            };


            _fakePersoneIdentifier = new IdentifierEntity
            {
                Identification = "1234567",
                SearchRequest  = new SSG_SearchRequest
                {
                    SearchRequestId = _validRequestId
                }
            };
            _fakePersonAddress = new AddressEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = _validRequestId
                },
                AddressLine1 = "addressLine1"
            };
            _fakeEmployment = new EmploymentEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = _validRequestId
                }
            };

            _fakeEmploymentContact = new EmploymentContactEntity
            {
                PhoneNumber = "11111111"
            };

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

            _fakeRelatedPerson = new RelatedPersonEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = _validRequestId
                }
            };

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

            _fakeSearchRequest = new SearchRequestEntity()
            {
                AgencyCode              = "FMEP",
                RequestPriority         = RequestPriorityType.Rush.Value,
                ApplicantAddressLine1   = "new Address line 1",
                ApplicantAddressLine2   = "",
                PersonSoughtDateOfBirth = new DateTime(1998, 1, 1),
                LocationRequested       = true,
                PHNRequested            = true,
                DateOfDeathRequested    = false
            };

            _fakeSafety = new SafetyConcernEntity {
                Detail = "safety"
            };

            _ssg_fakePerson = new PersonEntity
            {
            };

            _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 <PersonEntity>(It.IsAny <Person>()))
            .Returns(_ssg_fakePerson);

            _mapper.Setup(m => m.Map <EmploymentEntity>(It.IsAny <Employment>()))
            .Returns(_fakeEmployment);

            _mapper.Setup(m => m.Map <EmploymentContactEntity>(It.IsAny <Phone>()))
            .Returns(_fakeEmploymentContact);

            _mapper.Setup(m => m.Map <RelatedPersonEntity>(It.IsAny <RelatedPerson>()))
            .Returns(_fakeRelatedPerson);

            _mapper.Setup(m => m.Map <SearchRequestEntity>(It.IsAny <SearchRequestOrdered>()))
            .Returns(_fakeSearchRequest);

            _mapper.Setup(m => m.Map <SafetyConcernEntity>(It.IsAny <Person>()))
            .Returns(_fakeSafety);

            _searchRequestServiceMock.Setup(x => x.CreateSearchRequest(It.Is <SearchRequestEntity>(x => x.AgencyCode == "FMEP"), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequest>(new SSG_SearchRequest()
            {
                SearchRequestId = _validRequestId,
                AgencyCode      = "SUCCEED"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateIdentifier(It.IsAny <IdentifierEntity>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Identifier>(new SSG_Identifier()
            {
            }));

            _searchRequestServiceMock.Setup(x => x.CreateAddress(It.Is <AddressEntity>(x => x.SearchRequest.SearchRequestId == _validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Address>(new SSG_Address()
            {
                AddressLine1 = "test full line"
            }));

            _searchRequestServiceMock.Setup(x => x.CreatePhoneNumber(It.Is <PhoneNumberEntity>(x => x.SearchRequest.SearchRequestId == _validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_PhoneNumber>(new SSG_PhoneNumber()
            {
                TelePhoneNumber = "4007678231"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateName(It.Is <AliasEntity>(x => x.SearchRequest.SearchRequestId == _validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Aliase>(new SSG_Aliase()
            {
                FirstName = "firstName"
            }));

            _searchRequestServiceMock.Setup(x => x.SavePerson(It.Is <PersonEntity>(x => x.SearchRequest.SearchRequestId == _validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Person>(new SSG_Person()
            {
                FirstName = "First"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateEmployment(It.Is <EmploymentEntity>(x => x.SearchRequest.SearchRequestId == _validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Employment>(new SSG_Employment()
            {
                EmploymentId = Guid.NewGuid(),
                Occupation   = "Occupation"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateEmploymentContact(It.IsAny <EmploymentContactEntity>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_EmploymentContact>(new SSG_EmploymentContact()
            {
                PhoneNumber = "4007678231"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateRelatedPerson(It.Is <RelatedPersonEntity>(x => x.SearchRequest.SearchRequestId == _validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Identity>(new SSG_Identity()
            {
                FirstName = "firstName"
            }));

            _searchRequestServiceMock.Setup(x => x.SubmitToQueue(It.IsAny <Guid>()))
            .Returns(Task.FromResult <bool>(true));
            _sut = new AgencyRequestService(_searchRequestServiceMock.Object, _loggerMock.Object, _mapper.Object);
        }