Example #1
0
        private async Task <bool> UploadRelatedPersons()
        {
            if (_foundPerson.RelatedPersons == null)
            {
                return(true);
            }
            try
            {
                _logger.LogDebug($"Attempting to create found related person records for SearchRequest[{_searchRequest.SearchRequestId}]");

                foreach (var relatedPerson in _foundPerson.RelatedPersons)
                {
                    RelatedPersonEntity n = _mapper.Map <RelatedPersonEntity>(relatedPerson);
                    n.SearchRequest     = _searchRequest;
                    n.InformationSource = _providerDynamicsID;
                    n.Person            = _returnedPerson;
                    SSG_Identity relate = await _searchRequestService.CreateRelatedPerson(n, _cancellationToken);
                    await CreateResultTransaction(relate);
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }
        }
Example #2
0
        private async Task <bool> UploadRelatedApplicant(string firstName, string lastName)
        {
            if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
            {
                return(true);
            }

            _logger.LogDebug($"Attempting to create related applicant.");

            RelatedPersonEntity n = new RelatedPersonEntity
            {
                FirstName         = firstName,
                LastName          = lastName,
                SearchRequest     = _uploadedSearchRequest,
                InformationSource = InformationSourceType.Request.Value,
                Person            = _uploadedPerson,
                IsCreatedByAgency = true,
                PersonType        = RelatedPersonPersonType.Applicant.Value,
                StatusCode        = 1
            };

            SSG_Identity relate = await _searchRequestService.CreateRelatedPerson(n, _cancellationToken);

            _logger.LogInformation("Create Related Applicant for SearchRequest successfully");
            return(true);
        }
Example #3
0
        private async Task <bool> UpdateRelatedApplicant(RelatedPersonEntity newApplicantEntity)
        {
            if (newApplicantEntity == null)
            {
                return(true);
            }

            //update or add relation relatedPerson
            SSG_Identity originalRelatedApplicant = _uploadedPerson.SSG_Identities?.FirstOrDefault(
                m => m.InformationSource == InformationSourceType.Request.Value &&
                m.PersonType == RelatedPersonPersonType.Applicant.Value);

            if (originalRelatedApplicant == null)
            {
                await UploadRelatedApplicant(newApplicantEntity.FirstName, newApplicantEntity.LastName);

                _logger.LogInformation("Create Related Applicant for SearchRequest successfully");
            }
            else
            {
                Dictionary <string, object> updatedFields = (Dictionary <string, object>)originalRelatedApplicant.Clone().GetUpdateEntries(newApplicantEntity);
                if (updatedFields.Count > 0)
                {
                    await _searchRequestService.UpdateRelatedPerson(originalRelatedApplicant.RelatedPersonId, updatedFields, _cancellationToken);

                    _logger.LogInformation("Update Related Applicant records for SearchRequest successfully");
                }
            }

            return(true);
        }
Example #4
0
        public async Task with_correct_searchRequestid_upload_related_person_should_success()
        {
            var relatedPerson = new SSG_Identity()
            {
                FirstName            = "First",
                LastName             = "lastName",
                MiddleName           = "middleName",
                ThirdGivenName       = "otherName",
                Type                 = PersonRelationType.Friend.Value,
                Notes                = "notes",
                SupplierRelationType = "friend",
                Date1                = new DateTime(2001, 1, 1),
                Date1Label           = "date1lable",
                Date2                = new DateTime(2005, 1, 1),
                Date2Label           = "date2lable",
                Gender               = GenderType.Female.Value,
                Description          = "description",
                SearchRequest        = new SSG_SearchRequest()
                {
                    SearchRequestId = testId
                },
                Person = new SSG_Person()
                {
                    PersonId = testPersonId
                }
            };

            var result = await _sut.CreateRelatedPerson(relatedPerson, CancellationToken.None);

            Assert.AreEqual("FirstName", result.FirstName);
        }
Example #5
0
        private async Task <bool> UploadRelatedPersons(bool inUpdateProcess = false)
        {
            if (_personSought.RelatedPersons == null)
            {
                return(true);
            }

            _logger.LogDebug($"Attempting to create related person records person sought.");

            foreach (var relatedPerson in _personSought.RelatedPersons)
            {
                RelatedPersonEntity n = _mapper.Map <RelatedPersonEntity>(relatedPerson);
                n.SearchRequest     = _uploadedSearchRequest;
                n.InformationSource = InformationSourceType.Request.Value;
                n.Person            = _uploadedPerson;
                n.UpdatedByApi      = inUpdateProcess;
                if (inUpdateProcess)
                {
                    n.UpdateDetails = "Create New Related Person";
                }
                n.IsCreatedByAgency = true;
                SSG_Identity relate = await _searchRequestService.CreateRelatedPerson(n, _cancellationToken);
            }

            _logger.LogInformation("Create RelatedPersons records for SearchRequest successfully");
            return(true);
        }
Example #6
0
        public async Task update_correct_relatedPerson_should_success()
        {
            Guid testId = Guid.NewGuid();

            _odataClientMock.Setup(x => x.For <SSG_Identity>(null).Key(It.Is <Guid>(m => m == testId)).Set(It.IsAny <Dictionary <string, object> >())
                                   .UpdateEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_Identity()
            {
                RelatedPersonId = testId,
                FirstName       = "new"
            })
                     );

            var relatedPerson = new SSG_Identity()
            {
                RelatedPersonId = testId,
                FirstName       = "old"
            };
            IDictionary <string, object> updatedFields = new Dictionary <string, object> {
                { "businessname", "new" }
            };
            var result = await _sut.UpdateRelatedPerson(testId, updatedFields, CancellationToken.None);

            Assert.AreEqual("new", result.FirstName);
        }
Example #7
0
        public void gender_null_RelatedPerson_should_map_to_SSG_Identity_correctly()
        {
            var relatedPerson = new RelatedPerson()
            {
                FirstName   = "FirstName",
                Description = "test description",
                Notes       = "notes",
                Gender      = null,
            };
            SSG_Identity ssg_relatedPerson = _mapper.Map <SSG_Identity>(relatedPerson);

            Assert.AreEqual(null, ssg_relatedPerson.Gender);
        }
Example #8
0
        public void RelatedPerson_should_map_to_SSG_Identity_correctly()
        {
            var relatedPerson = new RelatedPerson()
            {
                FirstName      = "FirstName",
                LastName       = "LastName",
                MiddleName     = "MiddleName",
                OtherName      = "OtherName",
                Type           = "Aunt",
                Description    = "test description",
                Notes          = "notes",
                Gender         = "U",
                DateOfBirth    = new DateTimeOffset(new DateTime(2012, 3, 4)),
                ReferenceDates = new List <ReferenceDate>()
                {
                    new ReferenceDate()
                    {
                        Index = 0, Key = "relation start date", Value = new DateTimeOffset(new DateTime(2012, 1, 1))
                    },
                    new ReferenceDate()
                    {
                        Index = 1, Key = "relation end date", Value = new DateTimeOffset(new DateTime(2014, 1, 1))
                    }
                }
            };
            SSG_Identity ssg_relatedPerson = _mapper.Map <SSG_Identity>(relatedPerson);

            Assert.AreEqual("FirstName", ssg_relatedPerson.FirstName);
            Assert.AreEqual("LastName", ssg_relatedPerson.LastName);
            Assert.AreEqual("MiddleName", ssg_relatedPerson.MiddleName);
            Assert.AreEqual("OtherName", ssg_relatedPerson.ThirdGivenName);
            Assert.AreEqual("test description", ssg_relatedPerson.Description);
            Assert.AreEqual("notes", ssg_relatedPerson.Notes);
            Assert.AreEqual(867670002, ssg_relatedPerson.Type);
            Assert.AreEqual("Aunt", ssg_relatedPerson.SupplierRelationType);
            Assert.AreEqual(new DateTime(2012, 3, 4), ssg_relatedPerson.DateOfBirth);
            Assert.AreEqual(867670002, ssg_relatedPerson.Gender);
            Assert.AreEqual(1, ssg_relatedPerson.StatusCode);
            Assert.AreEqual(0, ssg_relatedPerson.StateCode);
            Assert.AreEqual(new DateTime(2012, 1, 1), ssg_relatedPerson.Date1);
            Assert.AreEqual(new DateTime(2014, 1, 1), ssg_relatedPerson.Date2);
            Assert.AreEqual("relation start date", ssg_relatedPerson.Date1Label);
            Assert.AreEqual("relation end date", ssg_relatedPerson.Date2Label);
        }
        public void SSG_Identity_should_map_to_RelatedPerson_correctly()
        {
            SSG_Identity relatedPerson = new SSG_Identity
            {
                PersonType     = RelatedPersonPersonType.Relation.Value,
                Type           = PersonRelationType.Friend.Value,
                FirstName      = "firstName",
                MiddleName     = "middleNm",
                LastName       = "lastNm",
                ThirdGivenName = "middleNm2",
                Gender         = GenderType.Female.Value,
                DateOfBirth    = new DateTime(2015, 1, 1),
                DateOfDeath    = new DateTime(2020, 10, 1)
            };

            RelatedPerson person = _mapper.Map <RelatedPerson>(relatedPerson);

            Assert.AreEqual("firstName", person.FirstName);
            Assert.AreEqual("f", person.Gender);
            Assert.AreEqual("Relation", person.PersonType);
            Assert.AreEqual("Friend", person.Type);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2015, 1, 1)), person.DateOfBirth);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2020, 10, 1)), person.DateOfDeath);
        }
 private async Task <bool> UploadRelatedPersons(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
 {
     if (person.RelatedPersons == null)
     {
         return(true);
     }
     try
     {
         foreach (var relatedPerson in person.RelatedPersons)
         {
             SSG_Identity n = _mapper.Map <SSG_Identity>(relatedPerson);
             n.SearchRequest     = request;
             n.InformationSource = providerDynamicsID;
             n.Person            = ssg_person;
             await _searchRequestService.CreateRelatedPerson(n, concellationToken);
         }
         return(true);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
        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);
        }
Example #12
0
 public async Task <SSG_Identity> CreateRelatedPerson(SSG_Identity relatedPerson, CancellationToken cancellationToken)
 {
     return(await this._oDataClient.For <SSG_Identity>().Set(relatedPerson).InsertEntryAsync(cancellationToken));
 }