public void GetAllKitchensForUser_ValidUser_ReturnsCorrectResult()
        {
            List <Kitchen> expectedKitchens = _context.KitchenUser
                                              .Where(ku => ku.UserId == _testUser.Id)
                                              .Select(ku => ku.Kitchen).ToList();

            var actualKitchens = _kitchenService.GetAllKitchensForUser(_testUser);

            Assert.Equal(expectedKitchens, actualKitchens);
        }
示例#2
0
        public async Task <ActionResult <List <KitchenDto> > > GetKitchenAsync()
        {
            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
            {
                List <Kitchen> kitchens = _service.GetAllKitchensForUser(user);
                return(Ok(KitchenDto.ToList(kitchens)));
            }
            catch (ArgumentNullException e)
            {
                return(BadRequest(e.Message));
            }
            catch (UserNotFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }