public void Initialize()
        {
            _fakeAccountHelper = new FakeAccountHelper();
            Guid validSessionId = _fakeAccountHelper.GenerateValidCredentials();

            _endpointHelper = new EndpointHelper();
            _endpointHelper.Setup()
            .SetAuthenticationToken(validSessionId.ToString());

            string responseContent = _endpointHelper.GetShoppingItems();

            _getShoppingItemResponse = JsonConvert.DeserializeObject <GetShoppingResponse>(responseContent);
        }
Пример #2
0
        public GetShoppingResponse GetShoppingItems(int?page, int?resultsPerPage)
        {
            var response = new GetShoppingResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID);
                    return(response);
                }

                ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString());
                if (user.HouseId == 0)
                {
                    response.AddError("You must belong to a household to get shopping items", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }
                Pagination pagination = new Pagination
                {
                    Page           = page ?? 0,
                    ResultsPerPage = resultsPerPage ?? int.MaxValue
                };
                response.ShoppingList = _shoppingRepository.GetAllItems(pagination, user.HouseId);
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}");
            }

            return(response);
        }