public void ExecuteReturnsResponseUsingsGatewayResults() { ListInteractionsAndChildInteractionsRequest request = new ListInteractionsAndChildInteractionsRequest() { FromDate = "2019-04-01", ToDate = "2019-04-30" }; List <Interaction> response = new List <Interaction>() { parentInteraction }; _interactionsGateway.Setup(_ => _.GetInteractionsAndChildInteractionsByDateRange(request.FromDate, request.ToDate)).Returns(response); _interactionsAndChildInteractionsUseCase.Execute(request); _interactionsGateway.Verify(gw => gw.GetInteractionsAndChildInteractionsByDateRange(request.FromDate, request.ToDate)); }
public IActionResult GetInteractionsAndChildInteractionsByDateRange([FromQuery] ListInteractionsAndChildInteractionsRequest request) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(x => x?.Errors?.Select(y => y?.ErrorMessage)))); } var interactionsAndChildInteractions = _listInteractionsAndChildInteractions.Execute(request); return(Ok(interactionsAndChildInteractions)); } //thrown when any of the gateways throws custom exception, bubbles up all the way here catch (Exception ex) when(ex is MaTReportingApiBaseException) { return(StatusCode(StatusCodes.Status500InternalServerError, $"{ex.GetType().Name.ToString()} : {ex.Message}")); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public void CanGetListOfInteractionsByDateRange() { ListInteractionsAndChildInteractionsRequest request = new ListInteractionsAndChildInteractionsRequest() { FromDate = "2019-04-01", ToDate = "2019-04-30" }; List <Interaction> response = new List <Interaction>() { parentInteraction }; _interactionsGateway.Setup(_ => _.GetInteractionsAndChildInteractionsByDateRange(request.FromDate, request.ToDate)).Returns(response); var results = _interactionsAndChildInteractionsUseCase.Execute(request); Assert.NotNull(results); Assert.True(results is ListInteractionsAndChildInteractionsResponse); Assert.True(results.Interactions.First() is Interaction); Assert.True(results.Request is ListInteractionsAndChildInteractionsRequest); Assert.Equal(response.FirstOrDefault().Name, results.Interactions.FirstOrDefault().Name); }
public ListInteractionsAndChildInteractionsResponse Execute(ListInteractionsAndChildInteractionsRequest request) { var result = _interactionsGateway.GetInteractionsAndChildInteractionsByDateRange(request.FromDate, request.ToDate); return(new ListInteractionsAndChildInteractionsResponse(request, DateTime.Now, result)); }