Ejemplo n.º 1
0
        public GetAllBeersResponse GetAllBeers(GetAllBeersRequest getAllBeersRequest)
        {
            _logger.Debug("Entering Get All Beers");

            var response = new GetAllBeersResponse()
            {
                BaseResponse = CreateBaseResponse(getAllBeersRequest.BaseRequest)
            };

            _logger.Debug("Base Response created");

            response.BaseResponse = VerifyBaseRequest(getAllBeersRequest.BaseRequest, response.BaseResponse);

            if (response.BaseResponse.ResponseStatus == ResponseStatus.Failure)
            {
                response.Beers = null;
                return(response);
            }

            var beers = _beerRepository.GetAllBeers();

            response.Beers = beers;

            return(response);
        }
        public void ItShouldReturn204HttpCode()
        {
            var response = new GetAllBeersResponse
            {
                Beers = new List <Beer>()
            };

            var presenter = new ApiGetAllBeersPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Equal(204, viewModel.HttpCode);
        }
        public void ItShouldReturn200HttpCode()
        {
            var response = new GetAllBeersResponse
            {
                Beers = new List <Beer>
                {
                    new Beer(Guid.NewGuid(), "Label", "Description", 0)
                }
            };

            var presenter = new ApiGetAllBeersPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Equal(200, viewModel.HttpCode);
        }
 public void Present(GetAllBeersResponse response)
 {
     ViewModel = new ApiGetAllBeersViewModel
     {
         HttpCode = response.Data.Any() ? 200 : 204,
         Success  = true,
         Data     = response.Data.Select(x => new
         {
             Id           = x.Id.Value,
             Label        = x.Label.Value,
             Description  = x.Description.Value,
             Stock        = x.Stock.Value,
             Available    = x.Stock.Value > 0,
             LimitedStock = x.Stock.Value <= 50
         }),
         Page    = response.Page,
         PerPage = response.PerPage,
         Total   = response.Total
     };
 }
Ejemplo n.º 5
0
        public void Present(GetAllBeersResponse response)
        {
            var vmHttpCode = response.Beers.Count > 0 ? 200 : 204;

            var vmData = response.Beers.Select(b => new ApiGetAllBeersViewModel.Beer
            {
                Id          = b.Id.Value,
                Label       = b.Label.Value,
                Description = b.Description.Value,
                Stock       = b.Stock.Value,
                Available   = b.Stock.Value > 0,
                LastItems   = b.Stock.Value > 0 && b.Stock.Value <= 10
            }).ToList();

            ViewModel = new ApiGetAllBeersViewModel
            {
                HttpCode = vmHttpCode,
                Data     = vmData
            };
        }
        public void ItShouldReturnOneLastItemsBeer()
        {
            var response = new GetAllBeersResponse
            {
                Beers = new List <Beer>
                {
                    new Beer(Guid.NewGuid(), "Label", "Description", 5),
                    new Beer(Guid.NewGuid(), "Label", "Description", 0),
                    new Beer(Guid.NewGuid(), "Label", "Description", 0)
                }
            };

            var presenter = new ApiGetAllBeersPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            var availableBeers = viewModel.Data.Where(b => b.LastItems).ToList();

            Assert.Single(availableBeers);
        }
        public void ItShouldReturnTheSameData()
        {
            var response = new GetAllBeersResponse
            {
                Beers = new List <Beer>
                {
                    new Beer(Guid.NewGuid(), "Label", "Description", 100)
                }
            };

            var presenter = new ApiGetAllBeersPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            var responseBeers  = response.Beers.ToList();
            var viewModelBeers = viewModel.Data.ToList();

            Assert.Equal(viewModelBeers[0].Id, responseBeers[0].Id.Value);
            Assert.Equal(viewModelBeers[0].Label, responseBeers[0].Label.Value);
            Assert.Equal(viewModelBeers[0].Description, responseBeers[0].Description.Value);
            Assert.Equal(viewModelBeers[0].Stock, responseBeers[0].Stock.Value);
        }
Ejemplo n.º 8
0
 void IGetAllBersPresenter.Present(GetAllBeersResponse response)
 {
     Response = response;
 }