Beispiel #1
0
        public void Execute(GetOneBeerRequest request, IGetOneBeerPresenter presenter)
        {
            var beer = _catalog.GetOneBeer(request.Id);

            var response = new GetOneBeerResponse
            {
                Data = beer
            };

            presenter.Present(response);
        }
        public void ItShouldReturnLastItems()
        {
            var response = new GetOneBeerResponse
            {
                Beer = new Beer(Guid.NewGuid(), "Label", "Description", 5)
            };

            var presenter = new ApiGetOneBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.True(viewModel.Data.LastItems);
        }
        public void ItShouldReturn404HttpCode()
        {
            var response = new GetOneBeerResponse
            {
                Beer = null
            };

            var presenter = new ApiGetOneBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Equal(404, viewModel.HttpCode);
        }
        public void ItShouldReturn200HttpCode()
        {
            var response = new GetOneBeerResponse
            {
                Beer = new Beer(Guid.NewGuid(), "Label", "Description", 0)
            };

            var presenter = new ApiGetOneBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Equal(200, viewModel.HttpCode);
        }
 public void Present(GetOneBeerResponse response)
 {
     ViewModel = new ApiGetOneBeerViewModel
     {
         HttpCode = response.Data == null ? 404 : 200,
         Success  = response.Data != null,
         Data     = response.Data == null
             ? null
             : new
         {
             Id           = response.Data.Id.Value,
             Label        = response.Data.Label.Value,
             Description  = response.Data.Description.Value,
             Stock        = response.Data.Stock.Value,
             Available    = response.Data.Stock.Value > 0,
             LimitedStock = response.Data.Stock.Value <= 50
         }
     };
 }
        public void ItShouldReturnTheSameData()
        {
            var response = new GetOneBeerResponse
            {
                Beer = new Beer(Guid.NewGuid(), "Label", "Description", 100)
            };

            var presenter = new ApiGetOneBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            var responseBeer  = response.Beer;
            var viewModelBeer = viewModel.Data;

            Assert.Equal(viewModelBeer.Id, responseBeer.Id.Value);
            Assert.Equal(viewModelBeer.Label, responseBeer.Label.Value);
            Assert.Equal(viewModelBeer.Description, responseBeer.Description.Value);
            Assert.Equal(viewModelBeer.Stock, responseBeer.Stock.Value);
        }
Beispiel #7
0
        public void Present(GetOneBeerResponse response)
        {
            var vmHttpCode = response.Beer != null ? 200 : 404;

            var vmData = response.Beer != null
                ? new ApiGetOneBeerViewModel.Beer
            {
                Id          = response.Beer.Id.Value,
                Label       = response.Beer.Label.Value,
                Description = response.Beer.Description.Value,
                Stock       = response.Beer.Stock.Value,
                Available   = response.Beer.Stock.Value > 0,
                LastItems   = response.Beer.Stock.Value > 0 && response.Beer.Stock.Value <= 10
            }
                : null;

            ViewModel = new ApiGetOneBeerViewModel
            {
                HttpCode = vmHttpCode,
                Data     = vmData
            };
        }
 void IGetOneBeerPresenter.Present(GetOneBeerResponse response)
 {
     Response = response;
 }