public void GetQuotation_WholesalerNotExist_ThrowException()
        {
            QuotationCommand command = new QuotationCommand()
            {
                WholesalerId = 70,
                TotalPrice   = 100,
                Items        = new List <ItemCommand>
                {
                    new ItemCommand()
                    {
                        BeerId = 1, Quantity = 10
                    },
                    new ItemCommand()
                    {
                        BeerId = 2, Quantity = 5
                    }
                }
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.GetQuotation(command);
                action.Should().ThrowExactly <NotFindObjectException>().WithMessage(ExceptionMessage.WHOLESALER_NOT_EXIST);
            }
        }
        public void GetQuotation_CheckDuplicateOrder_ThrowException()
        {
            QuotationCommand command = new QuotationCommand()
            {
                WholesalerId = 1,
                TotalPrice   = 100,
                Items        = new List <ItemCommand>
                {
                    new ItemCommand()
                    {
                        BeerId = 7, Quantity = 10
                    },
                    new ItemCommand()
                    {
                        BeerId = 7, Quantity = 3
                    }
                }
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.GetQuotation(command);
                action.Should().ThrowExactly <DuplicateItemException>().WithMessage(ExceptionMessage.DUPLICATE_ITEM);
            }
        }
 private void Seed()
 {
     using (var context = new BrasserieContext(ContextOptions))
     {
         context.Database.EnsureDeleted();
         context.Database.EnsureCreated();
     }
 }
        public void AddBeer_CommandIsNull_ThrowException()
        {
            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.AddNewBeerToWholesaler(null);
                action.Should().ThrowExactly <HttpBodyException>().WithMessage(ExceptionMessage.COMMAND_IS_NULL);
            }
        }
Example #5
0
        private BrasserieContext InitializeContext()
        {
            var options = new DbContextOptionsBuilder <BrasserieContext>()
                          .UseInMemoryDatabase(databaseName: "BrasserieContextDatabase")
                          .Options;

            var context = new BrasserieContext(options);

            context.Database.EnsureDeleted();
            return(context);
        }
        public void AddBeer_WholesalerNotExist_ThrowException()
        {
            SellBeerCommand command = new SellBeerCommand()
            {
                BeerId = 2, WholesalerId = 7, Stock = 10
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.AddNewBeerToWholesaler(command);
                action.Should().ThrowExactly <NotFindObjectException>().WithMessage(ExceptionMessage.WHOLESALER_NOT_EXIST);
            }
        }
        public void AddBeer_DuplicateBeer_ThrowException()
        {
            SellBeerCommand command = new SellBeerCommand()
            {
                BeerId = 1, WholesalerId = 1, Stock = 10
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.AddNewBeerToWholesaler(command);
                action.Should().ThrowExactly <DuplicateItemException>().WithMessage(ExceptionMessage.ALREADY_SELL);
            }
        }
        public void AddBeer_StockIsNegative_ThrowException()
        {
            SellBeerCommand command = new SellBeerCommand()
            {
                BeerId = 1, WholesalerId = 2, Stock = -10
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.AddNewBeerToWholesaler(command);
                action.Should().ThrowExactly <HttpBodyException>().WithMessage(ExceptionMessage.NEGATIVE_STOCK);
            }
        }
        public void UpdateStock_Stock_IsOk()
        {
            UpdateStockCommand command = new UpdateStockCommand()
            {
                BeerId = 1, WholesalerId = 1, Stock = 9
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                var actual = wholesalerService.UpdateWholesalerBeer(command);
                actual.Stock.Should().Be(9);
            }
        }
        public void AddBeer_CommandNameIsNull_ThrowException()
        {
            using (var context = new BrasserieContext(ContextOptions))
            {
                var service = new BeerService(context);
                CreateBeerCommand createBeer = new CreateBeerCommand()
                {
                    Price             = 10,
                    AlcoholPercentage = 10,
                    BrewerId          = 1
                };

                Action action = () => service.CreateBeer(createBeer);
                action.Should().ThrowExactly <HttpBodyException>().WithMessage(ExceptionMessage.NAME_BEER_NOT_EXIST);
            }
        }
 public void AddBeer_CommandAmountIsNegative_ThrowException()
 {
     using (var context = new BrasserieContext(ContextOptions))
     {
         var service = new BeerService(context);
         CreateBeerCommand createBeer = new CreateBeerCommand()
         {
             Name              = "Jaja",
             Price             = -10.00,
             AlcoholPercentage = 17.00,
             BrewerId          = 1
         };
         Action action = () => service.CreateBeer(createBeer);
         action.Should().ThrowExactly <HttpBodyException>().WithMessage(ExceptionMessage.PRICE_NULL_OR_NEGATIVE);
     }
 }
        public void AddBeer_BrewerNotExist_ThrowException()
        {
            using (var context = new BrasserieContext(ContextOptions))
            {
                var service = new BeerService(context);
                CreateBeerCommand createBeer = new CreateBeerCommand()
                {
                    Name              = "Xavier",
                    Price             = 10.00,
                    AlcoholPercentage = 1.00,
                    BrewerId          = 40
                };

                Action action = () => service.CreateBeer(createBeer);
                action.Should().ThrowExactly <NotFindObjectException>().WithMessage(ExceptionMessage.BREWER_NOT_EXIST);
            }
        }
        public void GetQuotation_CommandItemIsNull_ThrowException()
        {
            QuotationCommand command = new QuotationCommand()
            {
                WholesalerId = 1,
                TotalPrice   = 100,
                Items        = null
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.GetQuotation(command);
                action.Should().ThrowExactly <HttpBodyException>().WithMessage(ExceptionMessage.COMMAND_IS_NULL);
            }
        }
        public void AddBeerToWholesaler_OK()
        {
            SellBeerCommand command = new SellBeerCommand()
            {
                BeerId = 5, WholesalerId = 2, Stock = 1000
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                var actual = wholesalerService.AddNewBeerToWholesaler(command);

                actual.BeerId.Should().Be(command.BeerId);
                actual.WholesalerId.Should().Be(command.WholesalerId);
                actual.Stock.Should().Be(command.Stock);
            }
        }
        public void AddBeer_Ok()
        {
            using (var context = new BrasserieContext(ContextOptions))
            {
                var service = new BeerService(context);
                CreateBeerCommand createBeer = new CreateBeerCommand()
                {
                    Name              = "Xavier",
                    Price             = 10.00,
                    AlcoholPercentage = 1.00,
                    BrewerId          = 1
                };

                var beer = service.CreateBeer(createBeer);

                beer.Name.Should().Be("Xavier");
                beer.Price.Should().Be(10);
                beer.Brewer.Name.Should().Be("Abbaye de Leffe");
            }
        }
        public void GetQuotation_Discount20_IsOk()
        {
            var expect = 44.00;
            QuotationCommand command = new QuotationCommand()
            {
                WholesalerId = 1,
                Items        = new List <ItemCommand>
                {
                    new ItemCommand()
                    {
                        BeerId   = 1,
                        Quantity = 25
                    }
                }
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                var actual = wholesalerService.GetQuotation(command);
                actual.Should().Be(expect);
            }
        }
        public void GetQuotation_StockNotEnough_ThrowException()
        {
            QuotationCommand command = new QuotationCommand()
            {
                WholesalerId = 1,
                TotalPrice   = 100,
                Items        = new List <ItemCommand>
                {
                    new ItemCommand()
                    {
                        BeerId   = 1,
                        Quantity = 40
                    }
                }
            };

            using (var context = new BrasserieContext(ContextOptions))
            {
                var wholesalerService = new WholesalerService(context);

                Action action = () => wholesalerService.GetQuotation(command);
                action.Should().ThrowExactly <NotEnoughQuantityException>().WithMessage(ExceptionMessage.ENOUGH_STOCK);
            }
        }
Example #18
0
 public WholesalerRepository(BrasserieContext brasserieContext)
 {
     _brasserieContext = brasserieContext;
 }
Example #19
0
 public BeerService(BrasserieContext brasserieContext)
 {
     _brasserieContext = brasserieContext;
 }
 public WholesalerService(BrasserieContext brasserieContext)
 {
     _brasserieContext = brasserieContext;
 }
 public GrossisteService(BrasserieContext brasserieContext)
 {
     _brasserieContext = brasserieContext;
 }
 public BrewerRepository(BrasserieContext brasserieContext)
 {
     _brasserieContext = brasserieContext;
 }
 public BrasserieService(BrasserieContext brasserieContext, IMapper mapper)
 {
     _brasserieContext = brasserieContext;
     _mapper           = mapper;
 }