Example #1
0
        public void ThrowBusinessExceptionWholesalerDoesNotExist()
        {
            var breweryId   = 0;
            var breweryRepo = new BreweryRepository(_context, null);

            Assert.That(() => BusinessRequirements.EnsureBreweryExistsAsync(breweryId, breweryRepo),
                        Throws.TypeOf <BusinessException>().With.Message.EqualTo("BREWERY_MUST_EXIST")
                        );
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] DTOs.CreateBeer beer, ApiVersion version = null)
        {
            if (version is null)
            {
                version = ApiVersion.Default;
            }

            await BusinessRequirements.EnsureBreweryExistsAsync(beer.BreweryId, _breweryRepository);

            DTOs.Beer newBeer = beer.Clone();
            var       entity  = await _repository.AddAsync(newBeer);

            await _repository.SaveChangesAsync();

            newBeer.Id = entity.Id;

            return(CreatedAtAction(nameof(GetById), new { id = newBeer.Id.ToString(), version = $"{version}" }, newBeer));
        }