public async Task <ObjectResult> Open([FromBody] DrawRequest request) { IEnumerable <OpenDraw> response = null; try { // If the basic request has not been supplied properly, exit straight away if (!request.IsValid()) { return(BadRequestResult()); } response = await _lottoDrawService.GetOpenDraws(request); } catch (InvalidDataException ide) { return(BadRequest($"Invalid Request: {ide.Message}")); } catch (Exception ex) // In the case of an internal server error, return a general 500 (generally would log this). { Console.WriteLine(ex.Message); return(StatusCode(500, response)); } return(new OkObjectResult(response)); }
public void GetOpenDraws_WithNullOrEmptyDrawsReturned_ThrowsAppropriateError() { // Arrange var request = LottoDrawData.ValidDrawRequest; ConfigureOpenRepository(LottoDrawData.NullOpenDrawsResponse, request); _lottoDrawService = new LottoDrawService(_openRepoMock.Object, _currentRepoMock.Object); // Act // Assert Assert.Throws <InvalidDataException>(() => _lottoDrawService.GetOpenDraws(request)); }
public async Task GetOpenDraws_WithValidRequest_ReturnsValidResponseWithoutErrors() { // Arrange var request = LottoDrawData.ValidDrawRequest; ConfigureOpenRepository(LottoDrawData.ValidOpenDrawsResponse, request); _lottoDrawService = new LottoDrawService(_openRepoMock.Object, _currentRepoMock.Object); // Act var openDraws = await _lottoDrawService.GetOpenDraws(request); // Assert Assert.That(openDraws, Is.Not.Null.Or.Empty); var openDrawsList = openDraws.ToList(); Assert.That(openDrawsList.Count, Is.GreaterThan(0)); }