Ejemplo n.º 1
0
        public void Agent_invliad_request_ID_SearchRequestOrdered_should_map_normally()
        {
            SearchRequestOrdered searchRequestOrdered = new SearchRequestOrdered()
            {
                Action = RequestAction.NEW,
                Person = new Person()
                {
                    Agency = new Agency()
                    {
                        Agent = new Name()
                        {
                        },
                        AgentContact = new List <Phone>
                        {
                        },
                        Code      = "FMEP",
                        RequestId = "12222393288",
                    },
                },
            };
            SearchRequestEntity entity = _mapper.Map <SearchRequestEntity>(searchRequestOrdered);

            Assert.AreEqual("12222393288", entity.OriginalRequestorReference);
            Assert.AreEqual(null, entity.PayerId);
            Assert.AreEqual(null, entity.CaseTrackingId);
            Assert.AreEqual(null, entity.PersonSoughtRole);
        }
        public void upload_invalid_searchReason_SearchRequest_should_throw_exception()
        {
            _odataClientMock.Setup(x => x.For <SSG_Agency>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Agency, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Agency>(new SSG_Agency()
            {
                AgencyId   = Guid.NewGuid(),
                AgencyCode = "fmep"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequestReason>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequestReason, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            var searchRequest = new SearchRequestEntity()
            {
                AgencyCode               = "fmep",
                SearchReasonCode         = "wrongreasoncode",
                AgencyOfficeLocationText = "NORTHERN AND INTERIOR CLIENT OFFICE, KAMLOOPS, BC",
                AgentFirstName           = "agentName"
            };

            Assert.ThrowsAsync <WebRequestException>(async() => await _sut.CreateSearchRequest(searchRequest, CancellationToken.None));
        }
Ejemplo n.º 3
0
        public void Agent_phone_null_SearchRequestOrdered_should_map_normally()
        {
            SearchRequestOrdered searchRequestOrdered = new SearchRequestOrdered()
            {
                Action           = RequestAction.NEW,
                RequestId        = "requestId",
                SearchRequestKey = "requestKey",
                SearchRequestId  = Guid.NewGuid(),
                Person           = new Person()
                {
                    Agency = new Agency()
                    {
                        Agent = new Name()
                        {
                        },
                        AgentContact = new List <Phone>
                        {
                        },
                        Code      = "FMEP",
                        RequestId = "QFP-12422509096920180928083433",
                    },
                },
            };
            SearchRequestEntity entity = _mapper.Map <SearchRequestEntity>(searchRequestOrdered);

            Assert.AreEqual(null, entity.AgentFirstName);
            Assert.AreEqual(null, entity.AgentLastName);
            Assert.AreEqual(null, entity.AgentPhoneNumber);
            Assert.AreEqual(null, entity.AgentPhoneExtension);
            Assert.AreEqual(null, entity.AgentFax);
            Assert.AreEqual(null, entity.Notes);
        }
        public async Task upload_valid_locationtext_SearchRequest_should_upload_mapped_location_not_locationText()
        {
            _odataClientMock.Setup(x => x.For <SSG_Agency>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Agency, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Agency>(new SSG_Agency()
            {
                AgencyId   = Guid.NewGuid(),
                AgencyCode = "fmep"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequestReason>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequestReason, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequestReason>(new SSG_SearchRequestReason()
            {
                ReasonId   = Guid.NewGuid(),
                ReasonCode = "reasonCode"
            }));

            _odataClientMock.Setup(x => x.For <SSG_AgencyLocation>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_AgencyLocation, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_AgencyLocation>(new SSG_AgencyLocation()
            {
                AgencyLocationId = Guid.NewGuid(),
                City             = "city"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null).Set(It.IsAny <SearchRequestEntity>())
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchRequest()
            {
                SearchRequestId = testId,
            })
                     );

            var searchRequest = new SearchRequestEntity()
            {
                AgencyCode               = "fmep",
                SearchReasonCode         = "reason",
                AgencyOfficeLocationText = "K",
                AgentFirstName           = "agentName"
            };

            var result = await _sut.CreateSearchRequest(searchRequest, CancellationToken.None);

            _odataClientMock.Verify(x => x.For <SSG_SearchRequest>(It.IsAny <string>())
                                    .Set(It.Is <SearchRequestEntity>(m => m.AgencyOfficeLocationText == null))
                                    .InsertEntryAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task upload_invalid_locationtext_SearchRequest_should_upload_locationText()
        {
            _odataClientMock.Setup(x => x.For <SSG_Agency>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Agency, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Agency>(new SSG_Agency()
            {
                AgencyId   = Guid.NewGuid(),
                AgencyCode = "fmep"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequestReason>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequestReason, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequestReason>(new SSG_SearchRequestReason()
            {
                ReasonId   = Guid.NewGuid(),
                ReasonCode = "reasonCode"
            }));

            _odataClientMock.Setup(x => x.For <SSG_AgencyLocation>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_AgencyLocation, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null).Set(It.IsAny <SearchRequestEntity>())
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchRequest()
            {
                SearchRequestId = testId,
            })
                     );

            var searchRequest = new SearchRequestEntity()
            {
                AgencyCode               = "fmep",
                SearchReasonCode         = "reason",
                AgencyOfficeLocationText = "WRONG ADDRESS,BC",
                AgentFirstName           = "agentName"
            };

            var result = await _sut.CreateSearchRequest(searchRequest, CancellationToken.None);

            _odataClientMock.Verify(x => x.For <SSG_SearchRequest>(It.IsAny <string>())
                                    .Set(It.Is <SearchRequestEntity>(m => m.AgencyOfficeLocationText == "WRONG ADDRESS,BC"))
                                    .InsertEntryAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task upload_correct_SearchRequest_should_success()
        {
            _odataClientMock.Setup(x => x.For <SSG_Agency>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Agency, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Agency>(new SSG_Agency()
            {
                AgencyId   = Guid.NewGuid(),
                AgencyCode = "fmep"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequestReason>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequestReason, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequestReason>(new SSG_SearchRequestReason()
            {
                ReasonId   = Guid.NewGuid(),
                ReasonCode = "reasonCode"
            }));

            _odataClientMock.Setup(x => x.For <SSG_AgencyLocation>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_AgencyLocation, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_AgencyLocation>(new SSG_AgencyLocation()
            {
                AgencyLocationId = Guid.NewGuid(),
                City             = "city"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null).Set(It.IsAny <SearchRequestEntity>())
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchRequest()
            {
                SearchRequestId = testId
            })
                     );

            var searchRequest = new SearchRequestEntity()
            {
                AgencyCode               = "fmep",
                SearchReasonCode         = "reason",
                AgencyOfficeLocationText = "k",
                AgentFirstName           = "agentName"
            };
            var result = await _sut.CreateSearchRequest(searchRequest, CancellationToken.None);

            Assert.AreEqual(testId, result.SearchRequestId);
        }
Ejemplo n.º 7
0
        private async Task <bool> UploadNotes(SearchRequestEntity newSearchRequestEntity)
        {
            NotesEntity note = new NotesEntity
            {
                StatusCode        = 1,
                Description       = newSearchRequestEntity.Notes,
                InformationSource = InformationSourceType.Request.Value,
                SearchRequest     = _uploadedSearchRequest
            };
            SSG_Notese ssgNote = await _searchRequestService.CreateNotes(note, _cancellationToken);

            if (ssgNote == null)
            {
                _logger.LogError("Create new notes failed.");
                return(false);
            }
            _logger.LogInformation("Create new notes successfully.");
            return(true);
        }
Ejemplo n.º 8
0
        public async Task <SSG_SearchRequest> ProcessSearchRequestOrdered(SearchRequestOrdered searchRequestOrdered)
        {
            _personSought = searchRequestOrdered.Person;
            var cts = new CancellationTokenSource();

            _cancellationToken = cts.Token;

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

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

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

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

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

            _logger.LogInformation("Create Person successfully");

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

            return(_uploadedSearchRequest);
        }
Ejemplo n.º 9
0
        private async Task <bool> UploadNotes(SearchRequestEntity newSearchRequestEntity, SSG_SearchRequest existedSearchRequest)
        {
            string previousNoteStr = existedSearchRequest.Notes;

            if (existedSearchRequest.SSG_Notes != null && existedSearchRequest.SSG_Notes?.Length > 0)
            {
                try
                {
                    previousNoteStr =
                        existedSearchRequest.SSG_Notes.Last(m => m.InformationSource == InformationSourceType.Request.Value).Description;
                }catch (Exception)
                {
                    _logger.LogInformation("notes does not contain notes from request. It is ok.");
                }
            }

            string newNotes = UpdateCurrentNote(newSearchRequestEntity.Notes, previousNoteStr);

            if (newNotes != null)
            {
                NotesEntity note = new NotesEntity
                {
                    StatusCode        = 1,
                    Description       = newNotes,
                    InformationSource = InformationSourceType.Request.Value,
                    SearchRequest     = _uploadedSearchRequest,
                    UpdatedByApi      = true
                };
                SSG_Notese ssgNote = await _searchRequestService.CreateNotes(note, _cancellationToken);

                if (ssgNote == null)
                {
                    _logger.LogError("Create new notes failed.");
                    return(false);
                }
                _logger.LogInformation("Create new notes successfully.");
            }
            return(true);
        }
Ejemplo n.º 10
0
        private async Task <bool> UpdateSearchRequest(SearchRequestEntity newSR)
        {
            string            originNotes = _uploadedSearchRequest.Notes;
            SSG_SearchRequest clonedSR    = _uploadedSearchRequest.Clone();

            Dictionary <string, object> updatedFields = (Dictionary <string, object>)clonedSR.GetUpdateEntries(newSR);

            if (newSR.SearchReasonCode != null && !newSR.SearchReasonCode.Equals(_uploadedSearchRequest.SearchReason?.ReasonCode, StringComparison.InvariantCultureIgnoreCase))
            {
                SSG_SearchRequestReason reason = await _searchRequestService.GetSearchReason(newSR.SearchReasonCode, _cancellationToken);

                updatedFields.Add("ssg_RequestCategoryText", reason);
            }

            if (newSR.AgencyOfficeLocationText != null && !newSR.AgencyOfficeLocationText.Equals(_uploadedSearchRequest.AgencyLocation.LocationCode, StringComparison.InvariantCultureIgnoreCase))
            {
                SSG_AgencyLocation location = await _searchRequestService.GetSearchAgencyLocation(
                    newSR.AgencyOfficeLocationText,
                    newSR.AgencyCode,
                    _cancellationToken);

                updatedFields.Add("ssg_AgencyLocation", location);
            }

            //comment out this as even there is nothing needed to change, we still need to set ssg_updatedbyagency to true to
            //trigger the Dynamics to send out the estimation date notification.
            //if (updatedFields.Count > 0) //except notes, there is something else changed.
            //{
            await _searchRequestService.UpdateSearchRequest(_uploadedSearchRequest.SearchRequestId, updatedFields, _cancellationToken);

            _logger.LogInformation("Update Search Request successfully");
            //}


            return(true);
        }
Ejemplo n.º 11
0
        public void normal_SearchRequestOrdered_should_map_to_SearchRequestEntity_correctly()
        {
            SearchRequestOrdered searchRequestOrdered = new SearchRequestOrdered()
            {
                Action           = RequestAction.NEW,
                RequestId        = "requestId",
                SearchRequestKey = "requestKey",
                SearchRequestId  = Guid.NewGuid(),
                TimeStamp        = new DateTime(2001, 1, 1),
                Person           = new Person()
                {
                    Agency = new Agency()
                    {
                        Agent = new Name()
                        {
                            FirstName = "agentFirstName", LastName = "agentLastName", Owner = OwnerType.NotApplicable
                        },
                        AgentContact = new List <Phone> {
                            new Phone()
                            {
                                PhoneNumber = "agentPhoneNumber", Extension = "agentExt", Type = "Phone"
                            },
                            new Phone()
                            {
                                PhoneNumber = "agentFaxNumber", Type = "Fax"
                            }
                        },
                        Notes                = "agency notes",
                        RequestPriority      = RequestPriority.Rush,
                        Code                 = "FMEP",
                        RequestId            = "QFP-12422509096920180928083433",
                        ReasonCode           = SearchReasonCode.EnfPayAgr,
                        RequestDate          = new DateTimeOffset(2018, 9, 28, 0, 0, 0, new TimeSpan(1, 0, 0)),
                        Email                = "*****@*****.**",
                        InformationRequested = new List <InformationRequested> {
                            InformationRequested.Location, InformationRequested.PHN, InformationRequested.DL
                        },
                        LocationCode = "v"
                    },
                    FirstName   = "personSoughtFirstName",
                    LastName    = "personSoughtLastName",
                    MiddleName  = "middleName",
                    OtherName   = "otherName",
                    Gender      = "M",
                    DateOfBirth = new DateTimeOffset(1995, 1, 1, 0, 0, 0, new TimeSpan(1, 0, 0)),
                    CautionFlag = "flag",
                    Identifiers = new List <PersonalIdentifier>()
                    {
                        new PersonalIdentifier()
                        {
                            Value = "123456", TypeCode = "SIN", Type = PersonalIdentifierType.SocialInsuranceNumber, Owner = OwnerType.PersonSought
                        },
                        new PersonalIdentifier()
                        {
                            Value = "113456", TypeCode = "BCID", Type = PersonalIdentifierType.BCID, Owner = OwnerType.PersonSought
                        },
                        new PersonalIdentifier()
                        {
                            Value = "12222456", TypeCode = "BCDL", Type = PersonalIdentifierType.BCDriverLicense, Owner = OwnerType.PersonSought
                        },
                        new PersonalIdentifier()
                        {
                            Value = "33333456", TypeCode = "SIN", Type = PersonalIdentifierType.SocialInsuranceNumber, Owner = OwnerType.Applicant
                        },
                        new PersonalIdentifier()
                        {
                            Value = "4444456", TypeCode = "BCDL", Type = PersonalIdentifierType.BCDriverLicense, Owner = OwnerType.InvolvedPerson
                        }
                    },
                    HairColour = "hairColor",
                    EyeColour  = "eyeColor",
                    Names      = new List <Name>()
                    {
                        new Name()
                        {
                            FirstName = "applicantFirstName", LastName = "applicantLastName", Owner = OwnerType.Applicant
                        }
                    },
                    Addresses = new List <Address>()
                    {
                        new Address()
                        {
                            AddressLine1  = "applicantAddressLine1",
                            AddressLine2  = "applicantAddressLine2",
                            City          = "applicantCity",
                            StateProvince = "applicantProvince",
                            ZipPostalCode = "applicantPostalCode",
                            Owner         = OwnerType.Applicant
                        },
                        new Address()
                        {
                            AddressLine1  = "involvedPersonAddressLine1",
                            AddressLine2  = "involvedPersonAddressLine2",
                            City          = "involvedPersonCity",
                            StateProvince = "involvedPersonProvince",
                            ZipPostalCode = "involvedPersonPostalCode",
                            Owner         = OwnerType.InvolvedPerson
                        },
                    },
                    Phones = new List <Phone>()
                    {
                        new Phone()
                        {
                            PhoneNumber = "11111111",
                            Owner       = OwnerType.Applicant
                        }
                    }
                },
            };
            SearchRequestEntity entity = _mapper.Map <SearchRequestEntity>(searchRequestOrdered);

            Assert.AreEqual("agentFirstName", entity.AgentFirstName);
            Assert.AreEqual("agentLastName", entity.AgentLastName);
            Assert.AreEqual("agentPhoneNumber", entity.AgentPhoneNumber);
            Assert.AreEqual("agentExt", entity.AgentPhoneExtension);
            Assert.AreEqual("v", entity.AgencyOfficeLocationText);
            Assert.AreEqual("agentFaxNumber", entity.AgentFax);
            Assert.AreEqual("agency notes", entity.Notes);
            Assert.AreEqual("QFP-12422509096920180928083433", entity.OriginalRequestorReference);
            Assert.AreEqual("124225", entity.PayerId);
            Assert.AreEqual("090969", entity.CaseTrackingId);
            Assert.AreEqual(new DateTime(2018, 9, 28), entity.RequestDate);
            Assert.AreEqual("*****@*****.**", entity.AgentEmail);
            Assert.AreEqual(true, entity.LocationRequested);
            Assert.AreEqual(true, entity.PhoneNumberRequested);
            Assert.AreEqual(true, entity.PHNRequested);
            Assert.AreEqual(true, entity.DriverLicenseRequested);
            Assert.AreEqual("FMEP", entity.AgencyCode);
            Assert.AreEqual("EnfPayAgr", entity.SearchReasonCode);
            Assert.AreEqual(RequestPriorityType.Rush.Value, entity.RequestPriority);
            Assert.AreEqual(PersonSoughtType.P.Value, entity.PersonSoughtRole);
            Assert.AreEqual("personSoughtFirstName", entity.PersonSoughtFirstName);
            Assert.AreEqual("personSoughtLastName", entity.PersonSoughtLastName);
            Assert.AreEqual("middleName", entity.PersonSoughtMiddleName);
            Assert.AreEqual("otherName", entity.PersonSoughtThirdGiveName);
            Assert.AreEqual(GenderType.Male.Value, entity.PersonSoughtGender);
            Assert.AreEqual(new DateTime(1995, 1, 1), entity.PersonSoughtDateOfBirth);
            Assert.AreEqual("12222456", entity.PersonSoughtBCDL);
            Assert.AreEqual("113456", entity.PersonSoughtBCID);
            Assert.AreEqual("eyeColor", entity.PersonSoughtEyeColor);
            Assert.AreEqual("hairColor", entity.PersonSoughtHairColor);
            Assert.AreEqual("123456", entity.PersonSoughtSIN);

            Assert.AreEqual("applicantAddressLine1", entity.ApplicantAddressLine1);
            Assert.AreEqual("applicantAddressLine2", entity.ApplicantAddressLine2);
            Assert.AreEqual("applicantCity", entity.ApplicantCity);
            Assert.AreEqual("canada", entity.ApplicantCountry);
            Assert.AreEqual("applicantFirstName", entity.ApplicantFirstName);
            Assert.AreEqual("applicantLastName", entity.ApplicantLastName);
            Assert.AreEqual("11111111", entity.ApplicantPhoneNumber);
            Assert.AreEqual("applicantPostalCode", entity.ApplicantPostalCode);
            Assert.AreEqual("applicantProvince", entity.ApplicantProvince);
            Assert.AreEqual("33333456", entity.ApplicantSIN);
        }
Ejemplo n.º 12
0
        public async Task <SSG_SearchRequest> ProcessUpdateSearchRequest(SearchRequestOrdered searchRequestOrdered)
        {
            var cts = new CancellationTokenSource();

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

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

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

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

            existedSoughtPerson.IsDuplicated = true;
            _uploadedPerson = existedSoughtPerson;


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

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

            //update searchRequestEntity
            await UpdateSearchRequest(newSearchRequest);

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

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

            await UpdatePersonSought();
            await UpdateSafetyConcern();

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

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

            //update employment
            await UploadEmployment(true);

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



            return(_uploadedSearchRequest);
        }
Ejemplo n.º 13
0
        public static SearchRequestEntity ConstructSearchRequestEntity(SearchRequestOrdered src)
        {
            if (src?.Person?.Agency?.RequestId == null)
            {
                throw new ArgumentNullException("SearchRequestOrdered.Person, Agency or RequestID are not allowed Null.");
            }
            SearchRequestEntity entity = new SearchRequestEntity();

            #region agency part
            entity.AgentEmail = src.Person.Agency.Email;
            if (src.Person.Agency.AgentContact != null)
            {
                Phone agencyPhone = src.Person.Agency.AgentContact.FirstOrDefault <Phone>(m => String.Equals(m.Type, "Phone", StringComparison.InvariantCultureIgnoreCase));
                entity.AgentPhoneNumber    = agencyPhone?.PhoneNumber;
                entity.AgentPhoneExtension = agencyPhone?.Extension;
                Phone agencyFax = src.Person.Agency.AgentContact.FirstOrDefault <Phone>(m => String.Equals(m.Type, "Fax", StringComparison.InvariantCultureIgnoreCase));
                if (string.IsNullOrEmpty(agencyFax?.Extension))
                {
                    entity.AgentFax = agencyFax?.PhoneNumber;
                }
                else
                {
                    entity.AgentFax = agencyFax?.PhoneNumber + " -" + agencyFax?.Extension;
                }
            }
            if (src.Person.Agency.Agent != null)
            {
                Name agentName = src.Person.Agency.Agent;
                entity.AgentFirstName = agentName.FirstName;
                entity.AgentLastName  = agentName.LastName;
            }
            if (src.Person.Agency.InformationRequested != null)
            {
                foreach (InformationRequested info in src.Person.Agency.InformationRequested)
                {
                    //todo: need to confirm with agency about the string
                    switch (info)
                    {
                    case InformationRequested.Location:
                    {
                        entity.LocationRequested    = true;
                        entity.PhoneNumberRequested = true;
                        //todo: set requested Email to be true
                        break;
                    }

                    case InformationRequested.Employment: entity.EmploymentRequested = true; break;

                    case InformationRequested.Asset: entity.AssetRequested = true; break;

                    case InformationRequested.SIN: entity.SINRequested = true; break;

                    case InformationRequested.DL: entity.DriverLicenseRequested = true; break;

                    case InformationRequested.PHN: entity.PHNRequested = true; break;

                    case InformationRequested.Phone: entity.PhoneNumberRequested = true; break;

                    case InformationRequested.Carceration: entity.CarcerationStatusRequested = true; break;

                    case InformationRequested.DateOfDeath: entity.DateOfDeathRequested = true; break;

                    case InformationRequested.IA: entity.IAStatusRequested = true; break;

                    case InformationRequested.SafetyConcern: entity.SafetyConcernRequested = true; break;
                    }
                    ;
                }
            }
            if (src.Person?.Agency.RequestId != null)
            {
                if (src.Person.Agency.RequestId.Length >= 30)
                {
                    string[] ids = src.Person.Agency.RequestId.Split('-');
                    if (ids.Length == 2)
                    {
                        entity.PayerId        = ids[1].Substring(0, 6);
                        entity.CaseTrackingId = ids[1].Substring(6, 6);
                        string role = ids[0].Substring(2, 1);
                        if (string.Equals(role, "P", StringComparison.InvariantCultureIgnoreCase))
                        {
                            entity.PersonSoughtRole = PersonSoughtType.P.Value;
                        }
                        if (string.Equals(role, "R", StringComparison.InvariantCultureIgnoreCase))
                        {
                            entity.PersonSoughtRole = PersonSoughtType.R.Value;
                        }
                    }
                }
            }
            #endregion


            if (src.Person.Addresses != null)
            {
                Address applicantAddress = src.Person.Addresses.FirstOrDefault <Address>(m => m.Owner == OwnerType.Applicant);
                entity.ApplicantAddressLine1 = applicantAddress?.AddressLine1;
                entity.ApplicantAddressLine2 = applicantAddress?.AddressLine2;
                entity.ApplicantCity         = applicantAddress?.City;
                entity.ApplicantPostalCode   = applicantAddress?.ZipPostalCode;
                entity.ApplicantProvince     = applicantAddress?.StateProvince;
                entity.ApplicantCountry      = "canada";
            }

            if (src.Person.Names != null)
            {
                Name applicantName = src.Person.Names.FirstOrDefault <Name>(m => m.Owner == OwnerType.Applicant);
                entity.ApplicantFirstName = applicantName.FirstName;
                entity.ApplicantLastName  = applicantName.LastName;
            }

            if (src.Person.Phones != null)
            {
                entity.ApplicantPhoneNumber = src.Person.Phones.FirstOrDefault <Phone>(m => m.Owner == OwnerType.Applicant)?.PhoneNumber;
            }
            if (src.Person.Identifiers != null)
            {
                entity.ApplicantSIN = src.Person.Identifiers.FirstOrDefault <PersonalIdentifier>(
                    m => m.Owner == OwnerType.Applicant && m.Type == PersonalIdentifierType.SocialInsuranceNumber)?.Value;
                entity.PersonSoughtSIN = src.Person.Identifiers.FirstOrDefault <PersonalIdentifier>(
                    m => m.Owner == OwnerType.PersonSought && m.Type == PersonalIdentifierType.SocialInsuranceNumber)?.Value;
                entity.PersonSoughtBCDL = src.Person.Identifiers.FirstOrDefault <PersonalIdentifier>(
                    m => m.Owner == OwnerType.PersonSought && m.Type == PersonalIdentifierType.BCDriverLicense)?.Value;
                entity.PersonSoughtBCID = src.Person.Identifiers.FirstOrDefault <PersonalIdentifier>(
                    m => m.Owner == OwnerType.PersonSought && m.Type == PersonalIdentifierType.BCID)?.Value;
            }

            return(entity);
        }
        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);
        }