示例#1
0
        public void OrderService_GetsAllProducts_GivenTheyExist()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("gets_all").Options;

            using var context = new CoffeeBoxDbContext(options);
        }
        public void InventoryService_GetsAllInventory_GivenTheyExist()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("gets_all").Options;

            using var context = new CoffeeBoxDbContext(options);
            var sut = new ProductService(context);
        }
示例#3
0
 public OrderService(
     CoffeeBoxDbContext dbContext,
     ILogger <OrderService> logger,
     IProductService productService,
     IInventoryService inventoryService)
 {
     _db               = dbContext;
     _logger           = logger;
     _productService   = productService;
     _inventoryService = inventoryService;
 }
示例#4
0
        public void ProductService_CreatesProduct_GivenNewProductObject()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("Archives_product").Options;

            using var context = new CoffeeBoxDbContext(options);
            var sut = new ProductService(context);

            sut.CreateProduct(new Product {
                Id = 7689
            });
            context.Products.Single().Id.Should().Be(7689);
        }
示例#5
0
        public void CustomerService_CreatesCustomer_GivenNewCustomerObject()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("Add_writes_to_database").Options;

            using var context = new CoffeeBoxDbContext(options);
            var sut = new CustomerService(context);

            sut.CreateCustomer(new Customer {
                Id = 66795
            });
            context.Customers.Single().Id.Should().Be(66795);
        }
示例#6
0
        public void ProductService_ArchivesProduct_GivenNewProductObject()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("Add_writes_to_database").Options;

            using var context = new CoffeeBoxDbContext(options);
            var sut = new ProductService(context);

            sut.CreateProduct(new Product {
                Id = 7
            });
            sut.ArchiveProduct(7);
            var archivedProduct = sut.GetProductById(7);

            archivedProduct.IsArchived.Should().Be(true);
        }
示例#7
0
        public void CustomerService_DeletesCustomer_GivenId()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("deletes_one")
                          .Options;

            using var context = new CoffeeBoxDbContext(options);
            var sut = new CustomerService(context);

            sut.CreateCustomer(new Customer {
                Id = 66795
            });

            sut.DeleteCustomer(66795);
            var allCustomers = sut.GetAllCustomers();

            allCustomers.Count.Should().Be(0);
        }
示例#8
0
        public void ProductService_GetProductById_GivenTheyExist()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("gets_one").Options;

            using var context = new CoffeeBoxDbContext(options);
            var sut = new ProductService(context);

            sut.CreateProduct(new Product {
                Id = 7
            });
            sut.CreateProduct(new Product {
                Id = 24
            });

            var getProductWithId = sut.GetProductById(24);

            getProductWithId.Id.Should().Be(24);
        }
示例#9
0
        public void ProductService_GetsAllProducts_GivenTheyExist()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("gets_all").Options;

            using var context = new CoffeeBoxDbContext(options);

            var sut = new ProductService(context);

            sut.CreateProduct(new Data.Models.Product {
                Id = 1
            });
            sut.CreateProduct(new Data.Models.Product {
                Id = 2
            });

            var allProducts = sut.GetAllProducts();

            allProducts.Count.Should().Be(2);
        }
示例#10
0
        public void CustomerService_GetsAllCustomers_GivenTheyExist()
        {
            var options = new DbContextOptionsBuilder <CoffeeBoxDbContext>()
                          .UseInMemoryDatabase("gets_all").Options;

            using var context = new CoffeeBoxDbContext(options);

            var sut = new CustomerService(context);

            sut.CreateCustomer(new Data.Models.Customer {
                Id = 23134
            });
            sut.CreateCustomer(new Data.Models.Customer {
                Id = 345
            });
            sut.CreateCustomer(new Data.Models.Customer {
                Id = 23
            });

            var allCustomers = sut.GetAllCustomers();

            allCustomers.Count.Should().Be(3);
        }
示例#11
0
 public InventoryService(CoffeeBoxDbContext dbContext, ILogger <InventoryService> logger)
 {
     _db     = dbContext;
     _logger = logger;
 }
示例#12
0
 public CustomerService(CoffeeBoxDbContext dbContext)
 {
     _db = dbContext;
 }
示例#13
0
 public ProductService(CoffeeBoxDbContext dbContext)
 {
     _db = dbContext;
 }