public async Task <IActionResult> Get(string id) { try{ var row = await _itemRepo.GetRowById(id); return(Ok(row.Item)); } catch (KeyNotFoundException ex) { return(NotFound()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public async Task GetRowById_NotFoundEx() { var airTableClient = new Mock <AirTableClientProvider>(""); airTableClient.Setup(a => a.GetStringAsync(It.IsAny <string>())).ReturnsAsync(JsonConvert.SerializeObject(new AirTableResponse { Records = new List <AirTableResponseItem> { } })); var itemRepo = new ItemRepo(airTableClient.Object); var exception = await Record.ExceptionAsync(async() => await itemRepo.GetRowById("")); Assert.NotNull(exception); Assert.IsType <KeyNotFoundException>(exception); }
public async Task GetRowById_Return() { var airTableClient = new Mock <AirTableClientProvider>(""); airTableClient.Setup(a => a.GetStringAsync(It.IsAny <string>())).ReturnsAsync(JsonConvert.SerializeObject(new AirTableResponse { Records = new List <AirTableResponseItem> { _activeItem } })); var itemRepo = new ItemRepo(airTableClient.Object); var response = await itemRepo.GetRowById(""); Assert.NotNull(response); Assert.Equal(_activeItem.Id, response.Id); }