public void ItShouldReturnCreatedBeer()
        {
            var responseBeer = new Beer(Guid.NewGuid(), "Label", "Description", 5);

            var response = new UpdateExistingBeerResponse
            {
                Beer   = responseBeer,
                Errors = null
            };

            var presenter = new ApiUpdateExistingBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            var viewModelBeer = viewModel.Data;

            Assert.Equal(responseBeer.Id.Value, viewModelBeer.Id);
            Assert.Equal(responseBeer.Label.Value, viewModelBeer.Label);
            Assert.Equal(responseBeer.Description.Value, viewModelBeer.Description);
            Assert.Equal(responseBeer.Stock.Value, viewModelBeer.Stock);
            Assert.True(viewModelBeer.Available);
            Assert.True(viewModelBeer.LastItems);
        }
        public void ItShouldReturnErrors()
        {
            var responsErrors = new List <ValidationFailure>
            {
                new ValidationFailure("Label", "Label Error"),
                new ValidationFailure("Description", "Description Error")
            };

            var response = new UpdateExistingBeerResponse
            {
                Beer   = null,
                Errors = responsErrors
            };

            var presenter = new ApiUpdateExistingBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            var viewModelErrors = viewModel.Errors?.Select(e => e).ToList();

            Assert.NotNull(viewModelErrors);
            Assert.Equal(2, viewModelErrors.Count);
            Assert.Equal(responsErrors[0].PropertyName, viewModelErrors[0].Key);
            Assert.Equal(responsErrors[0].ErrorMessage, viewModelErrors[0].Value);
            Assert.Equal(responsErrors[1].PropertyName, viewModelErrors[1].Key);
            Assert.Equal(responsErrors[1].ErrorMessage, viewModelErrors[1].Value);
        }
Esempio n. 3
0
        public void Present(UpdateExistingBeerResponse response)
        {
            var vmHttpCode = response.Beer != null ? 200 : 400;

            var vmErrors = response.Errors?.Count > 0
                ? response.Errors.Select(e =>
                                         KeyValuePair.Create(e.PropertyName, e.ErrorMessage)
                                         ).ToList()
                : null;

            var vmData =
                response.Beer != null
                    ? new ApiUpdateExistingBeerViewModel.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 ApiUpdateExistingBeerViewModel
            {
                HttpCode = vmHttpCode,
                Errors   = vmErrors,
                Data     = vmData
            };
        }
        public void ItShouldNotReturnCreatedBeer()
        {
            var response = new UpdateExistingBeerResponse
            {
                Beer   = null,
                Errors = null
            };

            var presenter = new ApiUpdateExistingBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Null(viewModel.Data);
        }
        public void ItShouldReturn400HttpCode()
        {
            var response = new UpdateExistingBeerResponse
            {
                Beer   = null,
                Errors = null
            };

            var presenter = new ApiUpdateExistingBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Equal(400, viewModel.HttpCode);
        }
        public void ItShouldNotReturnErrors()
        {
            var response = new UpdateExistingBeerResponse
            {
                Beer   = new Beer(Guid.NewGuid(), "Label", "Description", 5),
                Errors = new List <ValidationFailure>()
            };

            var presenter = new ApiUpdateExistingBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Null(viewModel.Errors);
        }
        public void ItShouldReturn200HttpCode()
        {
            var response = new UpdateExistingBeerResponse
            {
                Beer   = new Beer(Guid.NewGuid(), "Label", "Description", 0),
                Errors = null
            };

            var presenter = new ApiUpdateExistingBeerPresenter();

            presenter.Present(response);

            var viewModel = presenter.ViewModel;

            Assert.Equal(200, viewModel.HttpCode);
        }
 void IUpdateExistingBeerPresenter.Present(UpdateExistingBeerResponse response)
 {
     Response = response;
 }