Ejemplo n.º 1
0
        public async Task <IActionResult> Submitted(string key, [FromBody] PersonSearchSubmitted personSearchSubmitted)
        {
            using (LogContext.PushProperty("SearchRequestKey", personSearchSubmitted?.SearchRequestKey))
                using (LogContext.PushProperty("DataPartner", personSearchSubmitted?.ProviderProfile.Name))
                {
                    _logger.LogInformation($"Received new event for SearchApiRequest");

                    var token = new CancellationTokenSource();

                    try
                    {
                        var searchApiEvent = _mapper.Map <SSG_SearchApiEvent>(personSearchSubmitted);
                        _logger.LogDebug($"Attempting to create a new event for SearchApiRequest [{key}]");
                        SSG_SearchApiRequest request = await _register.GetSearchApiRequest(key);

                        await _searchApiRequestService.AddEventAsync(request.SearchApiRequestId, searchApiEvent, token.Token);

                        _logger.LogInformation($"Successfully created submitted event for SearchApiRequest [{key}]");
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.Message);
                        return(BadRequest());
                    }

                    return(Ok());
                }
        }
Ejemplo n.º 2
0
        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);
        }