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); }
public void Employment_should_map_to_SSG_Employment_correctly() { var employment = new Employment() { Employer = new Employer() { ContactPerson = "Person", Name = "Name", OwnerName = "OwnerName", Address = new Address { AddressLine1 = "AddressLine1", AddressLine2 = "AddressLine2", AddressLine3 = "AddressLine3", StateProvince = "Manitoba", City = "testCity", Type = "residence", CountryRegion = "canada", ZipPostalCode = "p3p3p3", } }, IncomeAssistance = false, EmploymentConfirmed = true, IncomeAssistanceStatus = "Status", Occupation = "Occupation", Website = "Website", 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" }; EmploymentEntity ssg_empl = _mapper.Map <EmploymentEntity>(employment); Assert.AreEqual("Person", ssg_empl.ContactPerson); Assert.AreEqual("Name", ssg_empl.BusinessName); Assert.AreEqual("OwnerName", ssg_empl.BusinessOwner); Assert.AreEqual(true, ssg_empl.EmploymentConfirmed); Assert.AreEqual("Occupation", ssg_empl.Occupation); Assert.AreEqual("Website", ssg_empl.Website); Assert.AreEqual("Status", ssg_empl.IncomeAssistanceStatus); Assert.AreEqual("AddressLine1", ssg_empl.AddressLine1); Assert.AreEqual("AddressLine2", ssg_empl.AddressLine2); Assert.AreEqual("AddressLine3", ssg_empl.AddressLine3); Assert.AreEqual("Manitoba", ssg_empl.CountrySubdivisionText); Assert.AreEqual("testCity", ssg_empl.City); Assert.AreEqual("canada", ssg_empl.CountryText); Assert.AreEqual("p3p3p3", ssg_empl.PostalCode); Assert.AreEqual(1, ssg_empl.StatusCode); Assert.AreEqual(0, ssg_empl.StateCode); Assert.AreEqual("Start Date", ssg_empl.Date1Label); Assert.AreEqual("End Date", ssg_empl.Date2Label); Assert.AreEqual(false, ssg_empl.IncomeAssistance); Assert.AreEqual(new DateTime(2019, 9, 1), ssg_empl.Date1); Assert.AreEqual(new DateTime(2020, 9, 1), ssg_empl.Date2); }
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); }
private async Task <bool> UpdateEmployment() { if (_personSought.Employments == null) { return(true); } _logger.LogDebug($"Attempting to update employment records for PersonSought."); SSG_Employment originalEmployment = _uploadedPerson.SSG_Employments?.FirstOrDefault( m => m.InformationSource == InformationSourceType.Request.Value && m.IsCreatedByAgency); if (_personSought.Employments.Count() > 0) { EmploymentEntity employ = _mapper.Map <EmploymentEntity>(_personSought.Employments.ElementAt(0)); if (originalEmployment == null) { await UploadEmployment(); } else { IDictionary <string, object> updatedFields = originalEmployment.Clone().GetUpdateEntries(employ); if (updatedFields.ContainsKey("ssg_countrytext")) //country changed { SSG_Country country = await _searchRequestService.GetEmploymentCountry(employ.CountryText, _cancellationToken); updatedFields.Add("ssg_LocationCountry", country); } if (updatedFields.ContainsKey("ssg_countrysubdivision_text")) //subdivision changed { SSG_CountrySubdivision subdivision = await _searchRequestService.GetEmploymentSubdivision(employ.CountrySubdivisionText, _cancellationToken); updatedFields.Add("ssg_CountrySubDivision", subdivision); } if (updatedFields.Count > 0) { await _searchRequestService.UpdateEmployment(originalEmployment.EmploymentId, updatedFields, _cancellationToken); _logger.LogInformation("Update Employment records for SearchRequest successfully"); } Employer employer = _personSought.Employments.ElementAt(0).Employer; if (employer != null && employer.Phones != null && employer.Phones.Count() > 0) { SSG_Employment existedEmployment = await _searchRequestService.GetEmployment(originalEmployment.EmploymentId, _cancellationToken); existedEmployment.IsDuplicated = true; foreach (var phone in employer.Phones) { EmploymentContactEntity p = _mapper.Map <EmploymentContactEntity>(phone); p.Employment = existedEmployment; await _searchRequestService.CreateEmploymentContact(p, _cancellationToken); } } } } return(true); }