Example #1
0
        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));
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }