public void Delete_ValidKitchen_ReturnsKitchenDeleted() { Kitchen kitchenToDelete = _testUser.KitchenUser.FirstOrDefault()?.Kitchen; if (kitchenToDelete == null) { throw new Exception("kitchen is not setup for testing"); } var result = _kitchenService.DeleteKitchen(kitchenToDelete.KitchenId, _testUser); Assert.Equal(kitchenToDelete, result); }
public async Task <ActionResult <KitchenDto> > DeleteKitchenAsync(long id) { PantryPlannerUser user = null; 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 deletedKitchen = _service.DeleteKitchen(id, user); if (deletedKitchen == null) { return(NotFound()); } return(Ok(new KitchenDto(deletedKitchen))); } catch (ArgumentNullException e) { return(BadRequest(e.Message)); } catch (PermissionsException e) { return(Unauthorized(e.Message)); } catch (KitchenNotFoundException e) { return(NotFound(e.Message)); } catch (InvalidOperationException e) { return(UnprocessableEntity(e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }