Exemple #1
0
        public void Address_should_map_to_SSG_Address_correctly()
        {
            var address = new AddressActual()
            {
                AddressLine1  = "AddressLine1",
                AddressLine2  = "AddressLine2",
                AddressLine3  = "AddressLine3",
                StateProvince = "Manitoba",
                City          = "testCity",
                Type          = "residence",
                CountryRegion = "canada",
                ZipPostalCode = "p3p3p3",
                SuppliedBy    = "Employer",
                EffectiveDate = new DateTimeOffset(new DateTime(2001, 1, 1)),
                EndDate       = new DateTimeOffset(new DateTime(2002, 2, 1))
            };
            SSG_Address ssg_addr = _mapper.Map <SSG_Address>(address);

            Assert.AreEqual("AddressLine1", ssg_addr.AddressLine1);
            Assert.AreEqual("AddressLine2", ssg_addr.AddressLine2);
            Assert.AreEqual("AddressLine3", ssg_addr.AddressLine3);
            Assert.AreEqual(CanadianProvinceType.Manitoba.Value, ssg_addr.Province);
            Assert.AreEqual("testCity", ssg_addr.City);
            Assert.AreEqual("canada", ssg_addr.Country.Name);
            Assert.AreEqual(LocationType.Residence.Value, ssg_addr.Category);
            Assert.AreEqual("p3p3p3", ssg_addr.PostalCode);
            Assert.AreEqual((int)InformationSourceType.Employer.Value, ssg_addr.InformationSource);
            Assert.AreEqual("AddressLine1 AddressLine2 AddressLine3 testCity Manitoba canada p3p3p3", ssg_addr.FullText);
            Assert.AreEqual(1, ssg_addr.StatusCode);
            Assert.AreEqual(0, ssg_addr.StateCode);
            Assert.AreEqual(new DateTime(2001, 1, 1), ssg_addr.EffectiveDate);
            Assert.AreEqual(new DateTime(2002, 2, 1), ssg_addr.EndDate);
            Assert.AreEqual("Effective Date", ssg_addr.EffectiveDateLabel);
            Assert.AreEqual("End Date", ssg_addr.EndDateLabel);
        }
Exemple #2
0
        private async Task <bool> UploadAddresses( )
        {
            if (_foundPerson.Addresses == null)
            {
                return(true);
            }
            try
            {
                _logger.LogDebug($"Attempting to create found adddress records for SearchRequest[{_searchRequest.SearchRequestId}]");

                foreach (var address in _foundPerson.Addresses)
                {
                    AddressEntity addr = _mapper.Map <AddressEntity>(address);
                    addr.SearchRequest     = _searchRequest;
                    addr.InformationSource = _providerDynamicsID;
                    addr.Person            = _returnedPerson;
                    SSG_Address uploadedAddr = await _searchRequestService.CreateAddress(addr, _cancellationToken);
                    await CreateResultTransaction(uploadedAddr);
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }
        }
Exemple #3
0
        public void Address_should_map_to_SSG_Address_correctly()
        {
            var address = new PersonalAddressActual()
            {
                AddressLine1 = "AddressLine1",
                AddressLine2 = "AddressLine2",
                Province     = "Manitoba",
                City         = "testCity",
                Type         = "residence",
                Country      = "canada",
                PostalCode   = "p3p3p3",
                SuppliedBy   = "Employer"
            };
            SSG_Address ssg_addr = _mapper.Map <SSG_Address>(address);

            Assert.AreEqual("AddressLine1", ssg_addr.AddressLine1);
            Assert.AreEqual("AddressLine2", ssg_addr.AddressLine2);
            Assert.AreEqual(CanadianProvinceType.Manitoba.Value, ssg_addr.Province);
            Assert.AreEqual("testCity", ssg_addr.City);
            Assert.AreEqual("canada", ssg_addr.Country.Name);
            Assert.AreEqual(LocationType.Residence.Value, ssg_addr.Category);
            Assert.AreEqual("p3p3p3", ssg_addr.PostalCode);
            Assert.AreEqual((int)InformationSourceType.Employer.Value, ssg_addr.InformationSource);
            Assert.AreEqual("AddressLine1 AddressLine2 testCity Manitoba canada p3p3p3", ssg_addr.FullText);
            Assert.AreEqual(1, ssg_addr.StatusCode);
            Assert.AreEqual(0, ssg_addr.StateCode);
        }
        public void SSG_Address_should_map_to_Person_Address_correctly()
        {
            var address = new SSG_Address
            {
                AddressLine1           = "addressline1",
                AddressLine2           = "addressline2",
                PostalCode             = "postalCode",
                City                   = "city",
                Date1Label             = "label",
                Date1                  = new DateTime(2000, 1, 1),
                ResponseComments       = "addressComments",
                CountryText            = "canada",
                CountrySubdivisionText = "bc",
                Category               = LocationType.Business.Value,
                IncarcerationStatus    = "incarceration"
            };

            Address addr = _mapper.Map <Address>(address);

            Assert.AreEqual("addressline1", addr.AddressLine1);
            Assert.AreEqual("addressComments", addr.ResponseComments);
            Assert.AreEqual("city", addr.City);
            Assert.AreEqual("canada", addr.CountryRegion);
            Assert.AreEqual("bc", addr.StateProvince);
            Assert.AreEqual("Business", addr.Type);
            Assert.AreEqual("incarceration", addr.IncarcerationStatus);
            Assert.AreEqual(1, addr.ReferenceDates.Count);
        }
Exemple #5
0
        public async Task <SSG_Address> CreateAddress(SSG_Address address, CancellationToken cancellationToken)
        {
            string countryName = address.Country.Name;
            var    country     = await _oDataClient.For <SSG_Country>()
                                 .Filter(x => x.Name == countryName)
                                 .FindEntryAsync(cancellationToken);

            address.Country = country;
            return(await this._oDataClient.For <SSG_Address>().Set(address).InsertEntryAsync(cancellationToken));
        }
        public void SSG_Address_couldnotlocate_map_to_Person_Address_correctly()
        {
            var address = new SSG_Address
            {
                CouldNotLocate      = true,
                Category            = LocationType.Business.Value,
                IncarcerationStatus = "incarceration"
            };

            Address addr = _mapper.Map <Address>(address);

            Assert.AreEqual("Could Not Locate", addr.AddressLine1);
        }
 private async Task <bool> UploadAddresses(SSG_SearchRequest request, PersonSearchCompleted personCompletedEvent, CancellationToken concellationToken)
 {
     if (personCompletedEvent.MatchedPerson.Addresses == null)
     {
         return(true);
     }
     foreach (var address in personCompletedEvent.MatchedPerson.Addresses)
     {
         SSG_Address addr = _mapper.Map <SSG_Address>(address);
         addr.SearchRequest = request;
         var uploadedAddr = await _searchRequestService.CreateAddress(addr, concellationToken);
     }
     return(true);
 }
Exemple #8
0
        private async Task <bool> UploadAddresses(bool inUpdateProcess = false)
        {
            if (_personSought.Addresses == null)
            {
                return(true);
            }

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

            foreach (var address in _personSought.Addresses.Where(m => m.Owner == OwnerType.PersonSought))
            {
                AddressEntity addr = _mapper.Map <AddressEntity>(address);
                addr.SearchRequest     = _uploadedSearchRequest;
                addr.InformationSource = InformationSourceType.Request.Value;
                addr.Person            = _uploadedPerson;
                addr.IsCreatedByAgency = true;
                addr.UpdatedByApi      = inUpdateProcess;
                if (inUpdateProcess)
                {
                    addr.UpdateDetails = "New Address";
                }
                SSG_Address uploadedAddr = await _searchRequestService.CreateAddress(addr, _cancellationToken);
            }

            //following is for alias person has addresses, this situation never happened before. But the data structure is there.
            if (_personSought.Names == null)
            {
                return(true);
            }
            foreach (Name personName in _personSought.Names?.Where(m => m.Owner == OwnerType.PersonSought))
            {
                if (personName.Addresses != null)
                {
                    foreach (var address in personName.Addresses)
                    {
                        AddressEntity addr = _mapper.Map <AddressEntity>(address);
                        addr.SearchRequest     = _uploadedSearchRequest;
                        addr.InformationSource = InformationSourceType.Request.Value;
                        addr.Person            = _uploadedPerson;
                        addr.IsCreatedByAgency = true;

                        SSG_Address uploadedAddr = await _searchRequestService.CreateAddress(addr, _cancellationToken);
                    }
                }
            }
            _logger.LogInformation("Create addresses records for SearchRequest successfully");
            return(true);
        }
Exemple #9
0
        public void Address_should_map_to_SSG_Address_correctly()
        {
            var 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",
                Notes       = "notes"
            };
            SSG_Address ssg_addr = _mapper.Map <SSG_Address>(address);

            Assert.AreEqual("AddressLine1", ssg_addr.AddressLine1);
            Assert.AreEqual("AddressLine2", ssg_addr.AddressLine2);
            Assert.AreEqual("AddressLine3", ssg_addr.AddressLine3);
            Assert.AreEqual("Manitoba", ssg_addr.CountrySubdivisionText);
            Assert.AreEqual("testCity", ssg_addr.City);
            Assert.AreEqual("canada", ssg_addr.CountryText);
            Assert.AreEqual(LocationType.Residence.Value, ssg_addr.Category);
            Assert.AreEqual("p3p3p3", ssg_addr.PostalCode);
            Assert.AreEqual(1, ssg_addr.StatusCode);
            Assert.AreEqual(0, ssg_addr.StateCode);
            Assert.AreEqual("Start Date", ssg_addr.Date1Label);
            Assert.AreEqual("End Date", ssg_addr.Date2Label);
            Assert.AreEqual(new DateTime(2019, 9, 1), ssg_addr.Date1);
            Assert.AreEqual(new DateTime(2020, 9, 1), ssg_addr.Date2);
        }
Exemple #10
0
        public async Task with_correct_searchRequestid_upload_address_should_success()
        {
            var address = new SSG_Address()
            {
                FullText = "address full text",
                Country  = new SSG_Country()
                {
                    Name = "canada"
                },
                SearchRequest = new SSG_SearchRequest()
                {
                    SearchRequestId = testId
                }
            };

            var result = await _sut.CreateAddress(address, CancellationToken.None);

            Assert.AreEqual("test", result.FullText);
        }
Exemple #11
0
        public async Task with_correct_searchRequestid_upload_address_should_success()
        {
            var address = new SSG_Address()
            {
                AddressLine1           = "address full text",
                CountryText            = "canada",
                CountrySubdivisionText = "British Columbia",
                SearchRequest          = new SSG_SearchRequest()
                {
                    SearchRequestId = testId
                },
                Person = new SSG_Person()
                {
                    PersonId = testPersonId
                }
            };

            var result = await _sut.CreateAddress(address, CancellationToken.None);

            Assert.AreEqual("test", result.AddressLine1);
        }
 private async Task <bool> UploadAddresses(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
 {
     if (person.Addresses == null)
     {
         return(true);
     }
     try
     {
         foreach (var address in person.Addresses)
         {
             SSG_Address addr = _mapper.Map <SSG_Address>(address);
             addr.SearchRequest     = request;
             addr.InformationSource = providerDynamicsID;
             addr.Person            = ssg_person;
             var uploadedAddr = await _searchRequestService.CreateAddress(addr, concellationToken);
         }
         return(true);
     }catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
        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);
        }
Exemple #14
0
        public async Task <SSG_SearchRequestResponse> GetSearchResponse(Guid responseId, CancellationToken cancellationToken)
        {
            try
            {
                SSG_SearchRequestResponse ssgSearchResponse = await _oDataClient
                                                              .For <SSG_SearchRequestResponse>()
                                                              .Key(responseId)
                                                              .Expand(x => x.SSG_BankInfos)
                                                              .Expand(x => x.SSG_Asset_Others)
                                                              .Expand(x => x.SSG_Addresses)
                                                              .Expand(x => x.SSG_Aliases)
                                                              .Expand(x => x.SSG_Asset_ICBCClaims)
                                                              .Expand(x => x.SSG_Asset_Vehicles)
                                                              .Expand(x => x.SSG_Asset_WorkSafeBcClaims)
                                                              .Expand(x => x.SSG_Employments)
                                                              .Expand(x => x.SSG_Identifiers)
                                                              .Expand(x => x.SSG_Identities)
                                                              .Expand(x => x.SSG_Noteses)
                                                              .Expand(x => x.SSG_Persons)
                                                              .Expand(x => x.SSG_PhoneNumbers)
                                                              .Expand(x => x.SSG_SearchRequests)
                                                              .Expand(x => x.SSG_Asset_Investments)
                                                              .Expand(x => x.SSG_SafetyConcernDetails)
                                                              .Expand(x => x.SSG_Asset_PensionDisablilitys)
                                                              .Expand(x => x.SSG_Asset_RealEstatePropertys)
                                                              .Expand(x => x.SSG_Emails)
                                                              .Expand(x => x.SSG_Electronicas)
                                                              .FindEntryAsync(cancellationToken);

                if (ssgSearchResponse.SSG_SearchRequests != null)
                {
                    Guid id = ssgSearchResponse.SSG_SearchRequests[0].SearchRequestId;
                    ssgSearchResponse.SSG_SearchRequests[0] = await _oDataClient.For <SSG_SearchRequest>()
                                                              .Key(id)
                                                              .Expand(x => x.SearchReason)
                                                              .FindEntryAsync(cancellationToken);
                }

                if (ssgSearchResponse.SSG_Asset_WorkSafeBcClaims != null)
                {
                    foreach (SSG_Asset_WorkSafeBcClaim claim in ssgSearchResponse.SSG_Asset_WorkSafeBcClaims)
                    {
                        SSG_Asset_WorkSafeBcClaim c = await _oDataClient.For <SSG_Asset_WorkSafeBcClaim>()
                                                      .Key(claim.CompensationClaimId)
                                                      .Expand(x => x.BankingInformation)
                                                      .Expand(x => x.Employment)
                                                      .FindEntryAsync(cancellationToken);

                        claim.BankingInformation = c.BankingInformation;
                        claim.Employment         = c.Employment;
                    }
                }

                if (ssgSearchResponse.SSG_Addresses != null)
                {
                    foreach (SSG_Address address in ssgSearchResponse.SSG_Addresses)
                    {
                        SSG_Address addr = await _oDataClient.For <SSG_Address>()
                                           .Key(address.AddressId)
                                           .Expand(x => x.CountrySubdivision)
                                           .FindEntryAsync(cancellationToken);

                        if (addr.CountrySubdivision != null)
                        {
                            address.CountrySubdivisionText = addr.CountrySubdivision.ProvinceCode;
                        }
                    }
                }

                if (ssgSearchResponse.SSG_Asset_ICBCClaims != null)
                {
                    foreach (SSG_Asset_ICBCClaim claim in ssgSearchResponse.SSG_Asset_ICBCClaims)
                    {
                        if (claim.CountrySubdivision != null)
                        {
                            SSG_Asset_ICBCClaim expandedClaim = await _oDataClient.For <SSG_Asset_ICBCClaim>()
                                                                .Key(claim.ICBCClaimId)
                                                                .Expand(x => x.CountrySubdivision)
                                                                .FindEntryAsync(cancellationToken);


                            if (expandedClaim.CountrySubdivision != null)
                            {
                                claim.SupplierCountrySubdivisionCode = expandedClaim.CountrySubdivision.ProvinceCode;
                            }
                        }
                    }
                }

                if (ssgSearchResponse.SSG_Employments != null)
                {
                    foreach (SSG_Employment e in ssgSearchResponse.SSG_Employments)
                    {
                        SSG_Employment expandedEmployment = await _oDataClient.For <SSG_Employment>()
                                                            .Key(e.EmploymentId)
                                                            .Expand(x => x.CountrySubdivision)
                                                            .FindEntryAsync(cancellationToken);

                        if (expandedEmployment.CountrySubdivision != null)
                        {
                            e.CountrySubdivisionText = expandedEmployment.CountrySubdivision.ProvinceCode;
                        }

                        SSG_Employment temp = await _oDataClient.For <SSG_Employment>()
                                              .Key(e.EmploymentId)
                                              .Expand(x => x.SSG_EmploymentContacts)
                                              .FindEntryAsync(cancellationToken);

                        if (temp.SSG_EmploymentContacts != null)
                        {
                            e.SSG_EmploymentContacts = temp.SSG_EmploymentContacts;
                        }
                    }
                }


                return(ssgSearchResponse);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Init()
        {
            _testGuid      = Guid.NewGuid();
            _exceptionGuid = Guid.NewGuid();
            _loggerMock    = new Mock <ILogger <PersonSearchController> >();
            _searchApiRequestServiceMock = new Mock <ISearchApiRequestService>();
            _searchRequestServiceMock    = new Mock <ISearchRequestService>();
            _mapper = new Mock <IMapper>();
            var validRequestId   = Guid.NewGuid();
            var invalidRequestId = Guid.NewGuid();

            fakeSearchApiEvent = new SSG_SearchApiEvent {
            };

            _fakePersoneIdentifier = new SSG_Identifier {
                SSG_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
                }
            };

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

            _fakePersonCompletedEvent = new PersonSearchCompleted()
            {
                SearchRequestId = Guid.NewGuid(),
                TimeStamp       = DateTime.Now,
                ProviderProfile = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                MatchedPerson = new Person()
                {
                    DateOfBirth = DateTime.Now,
                    FirstName   = "TEST1",
                    LastName    = "TEST2",
                    Identifiers = new List <PersonalIdentifierActual>()
                    {
                        new PersonalIdentifierActual()
                        {
                            SerialNumber = "test",
                            IssuedBy     = "test",
                            Type         = PersonalIdentifierType.DriverLicense
                        }
                    },
                    Addresses = new List <PersonalAddressActual>()
                    {
                        new PersonalAddressActual()
                        {
                            AddressLine1 = "AddressLine1",
                            AddressLine2 = "AddressLine2",
                            Province     = "Manitoba",
                            City         = "testCity",
                            Type         = "residence",
                            Country      = "canada",
                            PostalCode   = "p3p3p3",
                            SuppliedBy   = "Employer"
                        }
                    },
                    PhoneNumbers = new List <PersonalPhoneNumberActual>()
                    {
                        new PersonalPhoneNumberActual()
                        {
                            PhoneNumber = "4005678900"
                        }
                    }
                }
            };

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

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


            _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 <PersonalPhoneNumber>()))
            .Returns(_fakePersonPhoneNumber);

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


            _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));


            _searchRequestServiceMock.Setup(x => x.CreateIdentifier(It.Is <SSG_Identifier>(x => x.SSG_SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Identifier>(new SSG_Identifier()
            {
                Identification = "test identification"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateIdentifier(It.Is <SSG_Identifier>(x => x.SSG_SearchRequest.SearchRequestId == invalidRequestId), It.IsAny <CancellationToken>()))
            .Throws(new Exception("random exception"));

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

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

            _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(_searchRequestServiceMock.Object, _searchApiRequestServiceMock.Object, _loggerMock.Object, _mapper.Object);
        }
        public void Init()
        {
            _loggerMock = new Mock <ILogger <SearchResultService> >();
            _searchRequestServiceMock = new Mock <ISearchRequestService>();
            _mapper = new Mock <IMapper>();
            var validRequestId    = Guid.NewGuid();
            var invalidRequestId  = Guid.NewGuid();
            var validVehicleId    = Guid.NewGuid();
            var validOtherAssetId = Guid.NewGuid();

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

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

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

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

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

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

            _ssg_fakePerson = new PersonEntity
            {
            };

            _searchRequest = new SSG_SearchRequest
            {
                SearchRequestId = validRequestId
            };

            _fakeBankInfo = new SSG_Asset_BankingInformation
            {
                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"
            };

            _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 <AssetOwner>()
                        {
                            new AssetOwner()
                            {
                            }
                        }
                    }
                },
                OtherAssets = new List <OtherAsset>()
                {
                    new OtherAsset()
                    {
                        Owners = new List <AssetOwner>()
                        {
                            new AssetOwner()
                            {
                            }
                        }
                    }
                }
            };

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


            _fakeToken = new CancellationToken();

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

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

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

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

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

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

            _mapper.Setup(m => m.Map <SSG_AssetOwner>(It.IsAny <AssetOwner>()))
            .Returns(_fakeAssetOwner);

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

            _searchRequestServiceMock.Setup(x => x.CreateIdentifier(It.Is <SSG_Identifier>(x => x.SearchRequest.SearchRequestId == invalidRequestId), It.IsAny <CancellationToken>()))
            .Throws(new Exception("random exception"));

            _searchRequestServiceMock.Setup(x => x.CreateAddress(It.Is <SSG_Address>(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 <SSG_PhoneNumber>(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 <SSG_Aliase>(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 <SSG_EmploymentContact>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_EmploymentContact>(new SSG_EmploymentContact()
            {
                PhoneNumber = "4007678231"
            }));

            _searchRequestServiceMock.Setup(x => x.CreateRelatedPerson(It.Is <SSG_Identity>(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 <SSG_Asset_BankingInformation>(x => x.SearchRequest.SearchRequestId == validRequestId), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Asset_BankingInformation>(new SSG_Asset_BankingInformation()
            {
                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
            }));

            _sut = new SearchResultService(_searchRequestServiceMock.Object, _loggerMock.Object, _mapper.Object);
        }