示例#1
0
        //for identifier, we should not do update, as it links to the search result.
        private async Task <bool> UpdateIdentifiers()
        {
            if (_personSought.Identifiers == null)
            {
                return(true);
            }

            _logger.LogDebug($"Attempting to update identifier records for PersonSought.");

            foreach (PersonalIdentifier pi in _personSought.Identifiers.Where(m => m.Owner == OwnerType.PersonSought))
            {
                IdentifierEntity identifierEntity   = _mapper.Map <IdentifierEntity>(pi);
                SSG_Identifier   originalIdentifier = _uploadedPerson.SSG_Identifiers?.FirstOrDefault(
                    m => m.InformationSource == InformationSourceType.Request.Value &&
                    m.IdentifierType == identifierEntity.IdentifierType &&
                    m.IsCreatedByAgency);
                if (originalIdentifier == null)
                {
                    await UploadIdentifiers();
                }
                else
                {
                    identifierEntity.IsCreatedByAgency = true;
                    IDictionary <string, object> updatedFields = originalIdentifier.Clone().GetUpdateEntries(identifierEntity);
                    if (updatedFields.Count > 0)
                    {
                        await _searchRequestService.UpdateIdentifier(originalIdentifier.IdentifierId, updatedFields, _cancellationToken);

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

            return(true);
        }
示例#2
0
        public void SSG_Identifier_should_map_to_PersonalIdentifier_correctly()
        {
            SSG_Identifier sSG_Identifier = new SSG_Identifier()
            {
                Identification    = "testIdentification",
                Date1             = new DateTime(2001, 1, 1),
                Date1Label        = "effectiveDate",
                Date2             = new DateTime(2001, 1, 1),
                Date2Label        = "expiredDate",
                IdentifierType    = IdentificationType.SocialInsuranceNumber.Value,
                InformationSource = InformationSourceType.ICBC.Value,
                IssuedBy          = "BC",
                SupplierTypeCode  = "TypeCode",
                Description       = "description",
                Notes             = "note"
            };
            PersonalIdentifier identifier = _mapper.Map <PersonalIdentifier>(sSG_Identifier);

            Assert.AreEqual("testIdentification", identifier.Value);
            Assert.AreEqual("note", identifier.Notes);
            Assert.AreEqual("description", identifier.Description);
            Assert.AreEqual("BC", identifier.IssuedBy);
            Assert.AreEqual("TypeCode", identifier.TypeCode);
            Assert.AreEqual(2, identifier.ReferenceDates.Count());
            Assert.AreEqual(PersonalIdentifierType.SocialInsuranceNumber, identifier.Type);
        }
示例#3
0
        public async Task wrong_fileId_will_get_null_ssgIdentifier()
        {
            SSG_Identifier result = await _sut.GetMatchedSourceIdentifier(_fakeIdentifier, _invalidSearchRequestKey);

            _loggerMock.VerifyLog(LogLevel.Error, "Cannot find the searchApiRequest in Redis Cache.", Times.Once());
            Assert.AreEqual(null, result);
        }
示例#4
0
        private async Task <bool> UploadIdentifiers()
        {
            if (_foundPerson.Identifiers == null)
            {
                return(true);
            }
            try
            {
                _logger.LogDebug($"Attempting to create found identifier records for SearchRequest[{_searchRequest.SearchRequestId}]");

                foreach (var matchFoundPersonId in _foundPerson.Identifiers)
                {
                    IdentifierEntity identifier = _mapper.Map <IdentifierEntity>(matchFoundPersonId);
                    identifier.SearchRequest     = _searchRequest;
                    identifier.InformationSource = _providerDynamicsID;
                    identifier.Person            = _returnedPerson;
                    SSG_Identifier newIdentifier = await _searchRequestService.CreateIdentifier(identifier, _cancellationToken);
                    await CreateResultTransaction(newIdentifier);
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }
        }
示例#5
0
        public async Task correct_sourceId_validFileId_will_get_correct_ssgIdentifier()
        {
            SSG_Identifier result = await _sut.GetMatchedSourceIdentifier(_fakeIdentifier, _validSearchRequestKey);

            Assert.AreEqual(IdentificationType.BirthCertificate.Value, result.IdentifierType);
            Assert.AreEqual("1234567", result.Identification);
            Assert.AreEqual(_validSouceIdentifierGuid, result.IdentifierId);
        }
示例#6
0
        public async Task <bool> ProcessPersonFound(
            Person person,
            ProviderProfile providerProfile,
            SSG_SearchRequest searchRequest,
            Guid?searchApiRequestId,
            CancellationToken cancellationToken,
            SSG_Identifier sourceIdentifier = null)
        {
            if (person == null)
            {
                return(true);
            }

            _foundPerson        = person;
            _providerDynamicsID = providerProfile.DynamicsID();
            _searchRequest      = searchRequest;
            _sourceIdentifier   = sourceIdentifier;
            _searchApiRequest   = searchApiRequestId == null? null : new SSG_SearchApiRequest()
            {
                SearchApiRequestId = (Guid)searchApiRequestId
            };
            _cancellationToken = cancellationToken;

            _returnedPerson = await UploadPerson();

            await UploadSafetyConcern();

            await UploadIdentifiers( );

            await UploadAddresses();

            await UploadPhoneNumbers();

            await UploadNames( );

            await UploadEmployment( );

            await UploadRelatedPersons();

            await UploadBankInfos();

            await UploadVehicles();

            await UploadOtherAssets();

            await UploadCompensationClaims();

            await UploadInsuranceClaims();

            await UploadEmails();

            return(true);
        }
示例#7
0
 public SearchResultService(ISearchRequestService searchRequestService, ILogger <SearchResultService> logger, IMapper mapper)
 {
     _searchRequestService = searchRequestService;
     _logger             = logger;
     _mapper             = mapper;
     _returnedPerson     = null;
     _sourceIdentifier   = null;
     _providerDynamicsID = null;
     _searchApiRequest   = null;
     _searchRequest      = null;
     _foundPerson        = null;
 }
示例#8
0
        public async Task <IActionResult> Completed(string key, [FromBody] PersonSearchCompleted personCompletedEvent)
        {
            try
            {
                Guard.NotNull(personCompletedEvent, nameof(personCompletedEvent));
                using (LogContext.PushProperty("SearchRequestKey", personCompletedEvent?.SearchRequestKey))
                    using (LogContext.PushProperty("DataPartner", personCompletedEvent?.ProviderProfile.Name))
                    {
                        _logger.LogInformation("Received Person search completed event");
                        var cts = new CancellationTokenSource();
                        SSG_SearchApiRequest request = await _register.GetSearchApiRequest(key);

                        //update completed event
                        var searchApiEvent = _mapper.Map <SSG_SearchApiEvent>(personCompletedEvent);
                        _logger.LogDebug($"Attempting to create a new event for SearchApiRequest");
                        await _searchApiRequestService.AddEventAsync(request.SearchApiRequestId, searchApiEvent, cts.Token);

                        _logger.LogInformation($"Successfully created completed event for SearchApiRequest");

                        //upload search result to dynamic search api
                        var searchRequestId = await _searchApiRequestService.GetLinkedSearchRequestIdAsync(request.SearchApiRequestId, cts.Token);

                        SSG_SearchRequest searchRequest = new SSG_SearchRequest()
                        {
                            SearchRequestId = searchRequestId
                        };

                        if (personCompletedEvent?.MatchedPersons != null)
                        {
                            //try following code, but automapper throws exception.Cannot access a disposed object.Object name: 'IServiceProvider'.
                            //Parallel.ForEach<Person>(personCompletedEvent.MatchedPersons, async p =>
                            //{
                            //    await _searchResultService.ProcessPersonFound(p, personCompletedEvent.ProviderProfile, searchRequest, cts.Token);
                            //});
                            foreach (PersonFound p in personCompletedEvent.MatchedPersons)
                            {
                                SSG_Identifier sourceIdentifer = await _register.GetMatchedSourceIdentifier(p.SourcePersonalIdentifier, key);

                                await _searchResultService.ProcessPersonFound(p, personCompletedEvent.ProviderProfile, searchRequest, request.SearchApiRequestId, cts.Token, sourceIdentifer);
                            }
                        }

                        await UpdateRetries(personCompletedEvent?.ProviderProfile.Name, 0, cts, request);

                        return(Ok());
                    }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
示例#9
0
        private async Task <bool> UploadIdentifiers(bool inUpdateProcess = false)
        {
            if (_personSought.Identifiers == null)
            {
                return(true);
            }
            _logger.LogDebug($"Attempting to create identifier records for SearchRequest.");

            foreach (var personId in _personSought.Identifiers.Where(m => m.Owner == OwnerType.PersonSought))
            {
                IdentifierEntity identifier = _mapper.Map <IdentifierEntity>(personId);
                identifier.SearchRequest     = _uploadedSearchRequest;
                identifier.InformationSource = InformationSourceType.Request.Value;
                identifier.Person            = _uploadedPerson;
                identifier.IsCreatedByAgency = true;
                identifier.UpdatedByApi      = inUpdateProcess;
                if (inUpdateProcess)
                {
                    identifier.UpdateDetails = "New Identifier";
                }
                SSG_Identifier newIdentifier = await _searchRequestService.CreateIdentifier(identifier, _cancellationToken);
            }

            //following is for alias person has identifiers, 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.Identifiers != null)
                {
                    foreach (var personId in personName.Identifiers)
                    {
                        IdentifierEntity identifier = _mapper.Map <IdentifierEntity>(personId);
                        identifier.SearchRequest     = _uploadedSearchRequest;
                        identifier.InformationSource = InformationSourceType.Request.Value;
                        identifier.Person            = _uploadedPerson;
                        identifier.IsCreatedByAgency = true;
                        identifier.UpdatedByApi      = inUpdateProcess;
                        if (inUpdateProcess)
                        {
                            identifier.UpdateDetails = "New Identifier";
                        }
                        SSG_Identifier newIdentifier = await _searchRequestService.CreateIdentifier(identifier, _cancellationToken);
                    }
                }
            }
            _logger.LogInformation("Create identifier records for SearchRequest successfully");
            return(true);
        }
示例#10
0
 private async Task <bool> UploadIdentifiers(SSG_SearchRequest request, PersonSearchCompleted personCompletedEvent, CancellationToken concellationToken)
 {
     if (personCompletedEvent.MatchedPerson.Identifiers == null)
     {
         return(true);
     }
     foreach (var matchFoundPersonId in personCompletedEvent.MatchedPerson.Identifiers)
     {
         SSG_Identifier identifier = _mapper.Map <SSG_Identifier>(matchFoundPersonId);
         identifier.SSG_SearchRequest = request;
         var identifer = await _searchRequestService.CreateIdentifier(identifier, concellationToken);
     }
     return(true);
 }
示例#11
0
        public void SSG_Identifier_should_map_to_PersonalIdentifier_correctly()
        {
            SSG_Identifier sSG_Identifier = new SSG_Identifier()
            {
                Identification = "testIdentification",
                IdentificationEffectiveDate  = new DateTime(2001, 1, 1),
                IdentificationExpirationDate = new DateTime(2001, 1, 1),
                IdentifierType    = IdentificationType.SocialInsuranceNumber.Value,
                InformationSource = InformationSourceType.Employer.Value
            };
            PersonalIdentifier identifier = _mapper.Map <PersonalIdentifier>(sSG_Identifier);

            Assert.AreEqual("testIdentification", identifier.Value);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2001, 1, 1)), identifier.EffectiveDate);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2001, 1, 1)), identifier.ExpirationDate);
            Assert.AreEqual(PersonalIdentifierType.SocialInsuranceNumber, identifier.Type);
        }
示例#12
0
        public async Task with_correct_searchRequestid_upload_identifier_should_success()
        {
            var identifier = new SSG_Identifier()
            {
                Identification = "identificationtest",
                IdentificationEffectiveDate = DateTime.Now,
                StateCode         = 0,
                StatusCode        = 1,
                SSG_SearchRequest = new SSG_SearchRequest()
                {
                    SearchRequestId = testId
                }
            };

            var result = await _sut.CreateIdentifier(identifier, CancellationToken.None);

            Assert.AreEqual("test", result.Identification);
        }
示例#13
0
        public void PersonalIdentifier_should_map_to_SSG_Identifier_correctly()
        {
            PersonalIdentifier identifier = new PersonalIdentifierActual()
            {
                Value          = "1111111",
                ExpirationDate = new DateTimeOffset(new DateTime(2003, 3, 3)),
                EffectiveDate  = new DateTimeOffset(new DateTime(2002, 2, 2)),
                Type           = PersonalIdentifierType.DriverLicense,
                IssuedBy       = "BC"
            };
            SSG_Identifier sSG_Identifier = _mapper.Map <SSG_Identifier>(identifier);

            Assert.AreEqual("1111111", sSG_Identifier.Identification);
            Assert.AreEqual(new DateTime(2002, 2, 2), sSG_Identifier.IdentificationEffectiveDate);
            Assert.AreEqual(new DateTime(2003, 3, 3), sSG_Identifier.IdentificationExpirationDate);
            Assert.AreEqual(IdentificationType.DriverLicense.Value, sSG_Identifier.IdentifierType);
            Assert.AreEqual(1, sSG_Identifier.StatusCode);
            Assert.AreEqual(0, sSG_Identifier.StateCode);
        }
示例#14
0
        public ICollection <ReferenceDate> Resolve(SSG_Identifier source, PersonalIdentifier dest, ICollection <ReferenceDate> dates, ResolutionContext context)
        {
            List <ReferenceDate> referDates = new List <ReferenceDate>();

            if (source.Date1 != null)
            {
                referDates.Add(new ReferenceDate()
                {
                    Index = 0, Key = source.Date1Label, Value = new DateTimeOffset((DateTime)source.Date1)
                });
            }
            if (source.Date2 != null)
            {
                referDates.Add(new ReferenceDate()
                {
                    Index = 1, Key = source.Date2Label, Value = new DateTimeOffset((DateTime)source.Date2)
                });
            }
            return(referDates);
        }
        public void SSG_Identifier_should_map_to_Person_Identifier_correctly()
        {
            var id = new SSG_Identifier
            {
                Identification   = "1234455",
                IssuedBy         = "ICBC",
                Date1Label       = "label",
                Date1            = new DateTime(2000, 1, 1),
                ResponseComments = "identifierComments",
                IdentifierType   = IdentificationType.BCDriverLicense.Value,
            };

            PersonalIdentifier personalIdentifier = _mapper.Map <PersonalIdentifier>(id);

            Assert.AreEqual("ICBC", personalIdentifier.IssuedBy);
            Assert.AreEqual("1234455", personalIdentifier.Value);
            Assert.AreEqual("identifierComments", personalIdentifier.ResponseComments);
            Assert.AreEqual(PersonalIdentifierType.BCDriverLicense, personalIdentifier.Type);
            Assert.AreEqual(1, personalIdentifier.ReferenceDates.Count);
        }
 private async Task <bool> UploadIdentifiers(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken)
 {
     if (person.Identifiers == null)
     {
         return(true);
     }
     try
     {
         foreach (var matchFoundPersonId in person.Identifiers)
         {
             SSG_Identifier identifier = _mapper.Map <SSG_Identifier>(matchFoundPersonId);
             identifier.SearchRequest     = request;
             identifier.InformationSource = providerDynamicsID;
             identifier.Person            = ssg_person;
             var identifer = await _searchRequestService.CreateIdentifier(identifier, concellationToken);
         }
         return(true);
     }catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(false);
     }
 }
示例#17
0
        public void PersonalIdentifierActual_should_map_to_SSG_Identifier_correctly()
        {
            PersonalIdentifier identifier = new PersonalIdentifier()
            {
                Value          = "1111111",
                Type           = PersonalIdentifierType.BCDriverLicense,
                IssuedBy       = "BC",
                Description    = "description",
                Notes          = "notes",
                TypeCode       = "BCDL",
                ReferenceDates = new List <ReferenceDate>()
                {
                    new ReferenceDate()
                    {
                        Index = 0, Key = "startDate", Value = new DateTime(2012, 1, 1)
                    },
                    new ReferenceDate()
                    {
                        Index = 1, Key = "endDate", Value = new DateTime(2014, 1, 1)
                    },
                }
            };
            SSG_Identifier sSG_Identifier = _mapper.Map <SSG_Identifier>(identifier);

            Assert.AreEqual("1111111", sSG_Identifier.Identification);
            Assert.AreEqual("description", sSG_Identifier.Description);
            Assert.AreEqual("notes", sSG_Identifier.Notes);
            Assert.AreEqual("BCDL", sSG_Identifier.SupplierTypeCode);
            Assert.AreEqual("BC", sSG_Identifier.IssuedBy);
            Assert.AreEqual(new DateTime(2012, 1, 1), sSG_Identifier.Date1);
            Assert.AreEqual(new DateTime(2014, 1, 1), sSG_Identifier.Date2);
            Assert.AreEqual("startDate", sSG_Identifier.Date1Label);
            Assert.AreEqual("endDate", sSG_Identifier.Date2Label);
            Assert.AreEqual(IdentificationType.BCDriverLicense.Value, sSG_Identifier.IdentifierType);
            Assert.AreEqual(1, sSG_Identifier.StatusCode);
            Assert.AreEqual(0, sSG_Identifier.StateCode);
        }
示例#18
0
        public void Init()
        {
            _loggerMock = new Mock <ILogger <SearchResultService> >();
            _searchRequestServiceMock = new Mock <ISearchRequestService>();
            _mapper = new Mock <IMapper>();
            var validRequestId = Guid.NewGuid();

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

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

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

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

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

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

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

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

            _ssg_fakePerson = new PersonEntity
            {
            };

            _searchRequest = new SSG_SearchRequest
            {
                SearchRequestId = validRequestId
            };

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

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

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

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

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

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

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

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

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

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

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

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

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


            _fakeToken = new CancellationToken();

            _mapper.Setup(m => m.Map <IdentifierEntity>(It.IsAny <PersonalIdentifier>()))
            .Returns(_fakePersoneIdentifier);

            _mapper.Setup(m => m.Map <PhoneNumberEntity>(It.IsAny <Phone>()))
            .Returns(_fakePersonPhoneNumber);

            _mapper.Setup(m => m.Map <AddressEntity>(It.IsAny <Address>()))
            .Returns(_fakePersonAddress);

            _mapper.Setup(m => m.Map <AliasEntity>(It.IsAny <Name>()))
            .Returns(_fakeName);

            _mapper.Setup(m => m.Map <PersonEntity>(It.IsAny <Person>()))
            .Returns(_ssg_fakePerson);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            _sut = new SearchResultService(_searchRequestServiceMock.Object, _loggerMock.Object, _mapper.Object);
        }
        public void Init()
        {
            _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);
        }
示例#20
0
 /// <summary>
 /// Gets all the search request in `Ready for Search` status
 /// </summary>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public async Task <SSG_Identifier> CreateIdentifier(SSG_Identifier identifier, CancellationToken cancellationToken)
 {
     return(await this._oDataClient.For <SSG_Identifier>().Set(identifier).InsertEntryAsync(cancellationToken));
 }
        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);
        }
示例#22
0
        public async Task wrong_sourceId_will_get_null_ssgIdentifier()
        {
            SSG_Identifier result = await _sut.GetMatchedSourceIdentifier(_wrongIdentifier, _validSearchApiRequestGuid);

            Assert.AreEqual(null, result);
        }
示例#23
0
        public async Task null_sourceId_validSearchRequestKey_will_get_null_ssgIdentifier()
        {
            SSG_Identifier result = await _sut.GetMatchedSourceIdentifier(null, _validSearchRequestKey);

            Assert.AreEqual(null, result);
        }
        public void Init()
        {
            _testGuid         = Guid.NewGuid();
            _searchRequestKey = "fileId_SequenceNumber";
            _searchRequestKeySearchNotComplete = "fileId_SequenceNumber_NotComplete";
            _exceptionSearchRequestKey         = "exception_seqNum";
            _exceptionGuid = Guid.NewGuid();
            _loggerMock    = new Mock <ILogger <PersonSearchController> >();
            _searchApiRequestServiceMock = new Mock <ISearchApiRequestService>();
            _searchResultServiceMock     = new Mock <ISearchResultService>();
            _dataPartnerServiceMock      = new Mock <IDataPartnerService>();
            _mapper       = new Mock <IMapper>();
            _registerMock = new Mock <ISearchRequestRegister>();

            _fakeSearchApiRequest = new SSG_SearchApiRequest()
            {
                SearchApiRequestId = _testGuid
            };

            var validRequestId   = Guid.NewGuid();
            var invalidRequestId = Guid.NewGuid();

            _fakeSearchApiEvent = new SSG_SearchApiEvent {
            };

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


            _fakePersonAddress = new AddressEntity
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

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

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

            _fakePerson = new SSG_Person
            {
                SearchRequest = new SSG_SearchRequest
                {
                    SearchRequestId = validRequestId
                }
            };

            _fakeSourceIdentifier = new SSG_Identifier()
            {
                IdentifierId = Guid.NewGuid()
            };

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

            _fakePersonCompletedEvent = new PersonSearchCompleted()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                MatchedPersons = new List <PersonFound>()
                {
                    new PersonFound()
                    {
                        DateOfBirth = DateTime.Now,
                        FirstName   = "TEST1",
                        LastName    = "TEST2",
                        Identifiers = new List <PersonalIdentifier>()
                        {
                        },
                        Addresses = new List <Address>()
                        {
                        },
                        Phones = new List <Phone>()
                        {
                        },
                        Names = new List <Name>()
                        {
                        },
                        SourcePersonalIdentifier = new PersonalIdentifier()
                        {
                            Value = "1234567"
                        }
                    }
                }
            };

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


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

            _fakePersonFinalizedEvent = new PersonSearchFinalized()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                Message          = "test message"
            };

            _fakePersonSubmittedEvent = new PersonSearchSubmitted()
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Message = "the search api request has been submitted to the Data provider."
            };

            _fakePersonInformationEvent = new PersonSearchInformation
            {
                SearchRequestId  = Guid.NewGuid(),
                SearchRequestKey = _searchRequestKey,
                TimeStamp        = DateTime.Now,
                ProviderProfile  = new ProviderProfile()
                {
                    Name = "TEST PROVIDER"
                },
                Message = "Recieved info from data provider"
            };

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchAccepted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchRejected>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchFailed>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchCompleted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <SSG_SearchApiEvent>(It.IsAny <PersonSearchSubmitted>()))
            .Returns(_fakeSearchApiEvent);

            _mapper.Setup(m => m.Map <IdentifierEntity>(It.IsAny <PersonalIdentifier>()))
            .Returns(_fakePersoneIdentifier);

            _mapper.Setup(m => m.Map <PhoneNumberEntity>(It.IsAny <Phone>()))
            .Returns(_fakePersonPhoneNumber);

            _mapper.Setup(m => m.Map <AddressEntity>(It.IsAny <Address>()))
            .Returns(_fakePersonAddress);

            _mapper.Setup(m => m.Map <AliasEntity>(It.IsAny <Name>()))
            .Returns(_fakeName);

            _mapper.Setup(m => m.Map <SSG_Person>(It.IsAny <Person>()))
            .Returns(_fakePerson);


            _searchApiRequestServiceMock.Setup(x => x.GetLinkedSearchRequestIdAsync(It.Is <Guid>(x => x == _testGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Guid>(_testGuid));

            _searchApiRequestServiceMock.Setup(x => x.GetLinkedSearchRequestIdAsync(It.Is <Guid>(x => x == _exceptionGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Guid>(invalidRequestId));


            _searchApiRequestServiceMock.Setup(x => x.MarkComplete(It.Is <Guid>(x => x == _testGuid), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchApiRequest>(new SSG_SearchApiRequest()
            {
                SearchApiRequestId = _testGuid,
                SequenceNumber     = "1234567"
            }));

            _dataPartnerServiceMock
            .Setup(x => x.GetSearchApiRequestDataProvider(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchapiRequestDataProvider {
                AdaptorName = "ICBC", SearchAPIRequestId = _testGuid, NumberOfFailures = 0, TimeBetweenRetries = 10
            }));


            _dataPartnerServiceMock
            .Setup(x => x.UpdateSearchRequestApiProvider(It.IsAny <SSG_SearchapiRequestDataProvider>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchapiRequestDataProvider {
                AdaptorName = "ICBC", SearchAPIRequestId = _testGuid, NumberOfFailures = 0, TimeBetweenRetries = 10
            }));

            _searchResultServiceMock.Setup(x => x.ProcessPersonFound(It.Is <Person>(x => x.FirstName == "TEST1"), It.IsAny <ProviderProfile>(), It.IsAny <SSG_SearchRequest>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>(), It.IsAny <SSG_Identifier>()))
            .Returns(Task.FromResult <bool>(true));

            _searchApiRequestServiceMock.Setup(x => x.AddEventAsync(It.Is <Guid>(x => x == _testGuid),
                                                                    It.IsAny <SSG_SearchApiEvent>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchApiEvent>(new SSG_SearchApiEvent()
            {
                Id   = _testGuid,
                Name = "Random Event"
            }));

            _searchApiRequestServiceMock.Setup(x => x.AddEventAsync(It.Is <Guid>(x => x == _exceptionGuid),
                                                                    It.IsAny <SSG_SearchApiEvent>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception("random exception"));

            _registerMock.Setup(x => x.GetSearchApiRequest(It.Is <string>(m => m == _searchRequestKey)))
            .Returns(Task.FromResult(_fakeSearchApiRequest));
            _registerMock.Setup(x => x.GetSearchApiRequest(It.Is <string>(m => m == _searchRequestKeySearchNotComplete)))
            .Returns(Task.FromResult(_fakeSearchApiRequest));

            _registerMock.Setup(x => x.DataPartnerSearchIsComplete(It.Is <string>(m => m == _searchRequestKey)))
            .Returns(Task.FromResult(true));

            _registerMock.Setup(x => x.DataPartnerSearchIsComplete(It.Is <string>(m => m == _searchRequestKeySearchNotComplete)))
            .Returns(Task.FromResult(false));

            _registerMock.Setup(x => x.GetMatchedSourceIdentifier(It.IsAny <PersonalIdentifier>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(_fakeSourceIdentifier));

            _registerMock.Setup(x => x.RemoveSearchApiRequest(It.IsAny <Guid>()))
            .Returns(Task.FromResult(true));

            _sut = new PersonSearchController(_searchResultServiceMock.Object, _searchApiRequestServiceMock.Object, _dataPartnerServiceMock.Object, _loggerMock.Object, _mapper.Object, _registerMock.Object);
        }
        public void Init()
        {
            _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);
        }