public void GetKitchenById_ValidId_ReturnsKitchen() { Kitchen expectedKitchen = _testUser.KitchenUser.FirstOrDefault()?.Kitchen; if (expectedKitchen == null) { throw new Exception("expectedKitchen not setup to test"); } Kitchen actualKitchen = _kitchenService.GetKitchenById(expectedKitchen.KitchenId, _testUser); Assert.Equal(expectedKitchen, actualKitchen); }
public async Task <ActionResult <KitchenDto> > GetKitchenAsync(long id) { Kitchen kitchen; PantryPlannerUser user; try { user = await _userManager.GetUserFromCookieOrJwtAsync(this.User); } catch (PermissionsException e) { // this will be thrown if the user is null return(Unauthorized(e.Message)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } try { kitchen = _service.GetKitchenById(id, user); return(Ok(new KitchenDto(kitchen))); } catch (ArgumentNullException e) { return(BadRequest(e.Message)); } catch (KitchenNotFoundException e) { return(NotFound(e.Message)); } catch (UserNotFoundException e) { return(NotFound(e.Message)); } catch (PermissionsException e) { return(Unauthorized(e.Message)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }