public void Init() { _loggerMock = new Mock <ILogger <AgencyResponseService> >(); _searchResponseServiceMock = new Mock <ISearchResponseService>(); _mapper = new Mock <IMapper>(); _mapper.Setup(m => m.Map <Person>(It.IsAny <SSG_SearchRequestResponse>())) .Returns(new Person()); _searchResponseServiceMock.Setup(x => x.GetSearchResponse(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult <SSG_SearchRequestResponse>(new SSG_SearchRequestResponse() { })); _ready = new SearchResponseReady() { Activity = "RequestClosed", ActivityDate = DateTime.Now, Agency = "agency", FileId = "fileId", AgencyFileId = "referId", FSOName = "fso", ResponseGuid = Guid.NewGuid().ToString() }; _sut = new AgencyResponseService(_searchResponseServiceMock.Object, _loggerMock.Object, _mapper.Object); }
public async Task <Person> GetSearchRequestResponse(SearchResponseReady searchResponseReady) { if (Guid.Parse(searchResponseReady.ResponseGuid) == Guid.Empty) { return(null); } var cts = new CancellationTokenSource(); SSG_SearchRequestResponse sr; try { sr = await _searchResponseService.GetSearchResponse(Guid.Parse(searchResponseReady.ResponseGuid), cts.Token); } catch (Exception ex) { throw ex; } if (sr == null) { return(null); } Person person = _mapper.Map <Person>(sr); return(person); }
public async Task wrong_fileId_GetSearchResponseReady_will_return_null() { _cacheServiceMock.Setup(x => x.Get(It.Is <string>(m => m == $"{Keys.REDIS_KEY_PREFIX}{Keys.REDIS_RESPONSE_KEY_PREFIX}invalidFileId_referenceId"))) .Returns(Task.FromResult <string>(null)); SearchResponseReady result = await _sut.GetSearchResponseReady("invalidFileId", "referenceId"); Assert.AreEqual(null, result); }
public async Task valid_fileId_GetSearchResponseReady_will_return_successfully() { Guid apiGuid = Guid.NewGuid(); SearchResponseReady ready = new SearchResponseReady { ApiCallGuid = apiGuid }; _cacheServiceMock.Setup(x => x.Get(It.Is <string>(m => m == $"{Keys.REDIS_KEY_PREFIX}{Keys.REDIS_RESPONSE_KEY_PREFIX}fileId_referenceId"))) .Returns(Task.FromResult(JsonConvert.SerializeObject(ready))); SearchResponseReady result = await _sut.GetSearchResponseReady("fileId", "referenceId"); Assert.AreEqual(apiGuid, result.ApiCallGuid); }
public void SetUp() { _sut = new SearchResponseReadyValidator(); _ready = new SearchResponseReady() { Activity = "RequestClosed", ActivityDate = DateTime.Now, Agency = "agency", FileId = "fileId", AgencyFileId = "referId", FSOName = "fso", ResponseGuid = Guid.NewGuid().ToString() }; }
public async Task <IActionResult> NotificationAcknowledged(string requestId, [FromBody] Acknowledgement ack) { using (LogContext.PushProperty("AgencyCode", $"{ack?.ProviderProfile.Name}")) using (LogContext.PushProperty("SearchRequestKey", $"{ack?.SearchRequestKey}")) { if ((string.IsNullOrEmpty(ack?.RequestId) || string.IsNullOrEmpty(ack?.SearchRequestKey)) && ack.NotificationType == BcGov.Fams3.SearchApi.Contracts.SearchRequest.NotificationType.RequestClosed) { return(StatusCode(StatusCodes.Status400BadRequest)); } _logger.LogInformation("Get NotificationAcknowledged"); try { SearchResponseReady ready = await _register.GetSearchResponseReady(ack.SearchRequestKey, ack.RequestId); if (ready == null) { return(StatusCode(StatusCodes.Status500InternalServerError)); } bool isAmendment = false; if (ack.SearchRequestKey.Contains("-")) { isAmendment = true; } await _agencyRequestService.ProcessNotificationAcknowledgement(ack, ready.ApiCallGuid, isAmendment); await _register.DeleteSearchResponseReady(ack.SearchRequestKey, ack.RequestId); } catch (AgencyRequestException ex) { _logger.LogInformation(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, new { ReasonCode = ex.Message, Message = ex.InnerException?.Message })); } catch (Exception ex) { if (ex is Simple.OData.Client.WebRequestException) { _logger.LogError(((Simple.OData.Client.WebRequestException)ex).Response); } _logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status504GatewayTimeout, new { ReasonCode = "error", Message = "error" })); } _logger.LogInformation("NotificationAcknowledged successfully"); return(Ok()); } }
private SearchRequestNotification BuildSearchRequestNotification(SearchResponseReady searchResponseReady, Person person) { return (new SearchRequestNotification() { AgencyFileId = searchResponseReady.AgencyFileId, FileId = searchResponseReady.FileId, ActivityDate = searchResponseReady.ActivityDate, Acvitity = searchResponseReady.Activity, EstimatedCompletionDate = null, PositionInQueue = null, Person = person, Agency = searchResponseReady.Agency, FSOName = searchResponseReady.FSOName }); }
public void Init() { _loggerMock = new Mock <ILogger <AgencyResponseController> >(); _agencyResponseServiceMock = new Mock <IAgencyResponseService>(); _agencyWebhookMock = new Mock <IAgencyNotificationWebhook <SearchRequestNotification> >(); _ready = new SearchResponseReady() { Activity = "RequestClosed", ActivityDate = DateTime.Now, Agency = "agency", FileId = "fileId", AgencyFileId = "referId", FSOName = "fso", ResponseGuid = Guid.NewGuid().ToString() }; _sut = new AgencyResponseController(_loggerMock.Object, _agencyResponseServiceMock.Object, _agencyWebhookMock.Object); }
public async Task <IActionResult> ResponseReady([FromBody] SearchResponseReady searchResponseReady) { using (LogContext.PushProperty("RequestRef", $"{searchResponseReady?.AgencyFileId}")) using (LogContext.PushProperty("AgencyCode", $"{searchResponseReady?.Agency}")) { _logger.LogInformation("Get searchResponseReady"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Person p = await _agencyResponseService.GetSearchRequestResponse(searchResponseReady); if (p == null) { return(BadRequest("wrong response guid")); } await _agencyNotifier.SendNotificationAsync( BuildSearchRequestNotification(searchResponseReady, p), (new CancellationTokenSource()).Token ); await _register.RegisterResponseApiCall(searchResponseReady); return(Ok()); } catch (Exception e) { _logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError, new { Message = e.Message })); } } }
public async Task <bool> RegisterResponseApiCall(SearchResponseReady ready) { await _cache.Save($"{Keys.REDIS_KEY_PREFIX}{Keys.REDIS_RESPONSE_KEY_PREFIX}{ready.FileId}_{ready.AgencyFileId}", ready); return(true); }