Beispiel #1
0
        public ActionResult CreateNewBeer([FromBody] CreateNewBeerRequest request)
        {
            var useCase = new CreateNewBeer(_catalog);

            var presenter = new ApiCreateNewBeerPresenter();

            useCase.Execute(request, presenter);

            var viewModel = presenter.ViewModel;

            if (viewModel.HttpCode == 201)
            {
                return(Created($"/beers/{viewModel.Data.Id}", viewModel));
            }
            return(BadRequest(viewModel));
        }
        public void ItShouldReturnAnErrorWithNegativeStock()
        {
            var request = new CreateNewBeerRequest
            {
                Label       = "Sample Label",
                Description = "Sample Description",
                Stock       = -1
            };

            var createNewBeerUseCase = new CreateNewBeer(_catalog);

            createNewBeerUseCase.Execute(request, this);

            Assert.Null(Response.Beer);
            Assert.NotNull(Response.Errors);
            Assert.Equal(1, Response.Errors.Count);
            Assert.Equal("Stock", Response.Errors.FirstOrDefault().PropertyName);
        }
        public void ItShouldReturnANewBeer()
        {
            var request = new CreateNewBeerRequest
            {
                Label       = "Sample Label",
                Description = "Sample Description",
                Stock       = 0
            };

            var createNewBeerUseCase = new CreateNewBeer(_catalog);

            createNewBeerUseCase.Execute(request, this);

            Assert.IsType <Beer>(Response.Beer);
            Assert.IsType <Guid>(Response.Beer.Id.Value);
            Assert.Equal("Sample Label", Response.Beer.Label.Value);
            Assert.Equal("Sample Description", Response.Beer.Description.Value);
            Assert.Equal(0, Response.Beer.Stock.Value);
            Assert.Null(Response.Errors);
        }
        public void ItShouldReturnMultipleErrorsWithBadProperties()
        {
            var request = new CreateNewBeerRequest
            {
                Label       = "Sa",
                Description = "Sa",
                Stock       = -1
            };

            var createNewBeerUseCase = new CreateNewBeer(_catalog);

            createNewBeerUseCase.Execute(request, this);

            Assert.Null(Response.Beer);
            Assert.NotNull(Response.Errors);

            var badProperties = Response.Errors.Select(e => e.PropertyName).ToList();

            Assert.Equal(3, badProperties.Count);
            Assert.Contains("Label", badProperties);
            Assert.Contains("Description", badProperties);
            Assert.Contains("Stock", badProperties);
        }