示例#1
0
        public async void CanDeleteBasketProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("GetBasektProduct").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService     inventoryService     = new InventoryService(context);
                BasketProductService basketProductService = new BasketProductService(context);
                BasketService        basketService        = new BasketService(context);
                Basket basket = new Basket();
                await basketService.CreateBasketAsync(basket);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await basketProductService.AddBasketProduct(product.ID, 3, basket.ID);

                var basketProduct = await basketProductService.GetBasketProductByID(basket.ID, product.ID);

                await basketProductService.DeleteBasketProductByID(basket.ID, product.ID);

                var actual = await basketProductService.GetBasketProductByID(basket.ID, product.ID);

                Assert.Null(actual);
            }
        }
示例#2
0
        public async void CanDeleteCheckoutProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("GetBasektProduct").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService       inventoryService       = new InventoryService(context);
                CheckoutProductService checkoutProductService = new CheckoutProductService(context);
                CheckoutService        checkoutService        = new CheckoutService(context);
                Checkout checkout = new Checkout();
                await checkoutService.CreateCheckoutAsync(checkout);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await checkoutProductService.AddCheckoutProduct(product.ID, 3, checkout.ID);

                var checkoutProduct = await checkoutProductService.GetCheckoutProductByID(checkout.ID, product.ID);

                await checkoutProductService.DeleteCheckoutProductByID(checkout.ID, product.ID);

                var actual = await checkoutProductService.GetCheckoutProductByID(checkout.ID, product.ID);

                Assert.Null(actual);
            }
        }
示例#3
0
        public async void CanCreateBasket()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                Basket        basket        = new Basket();
                BasketService basketService = new BasketService(context);
                await basketService.CreateBasketAsync(basket);

                var expected = await context.Baskets.FirstOrDefaultAsync(b => b.ID == basket.ID);

                Assert.Equal(expected, basket);
            }
        }
示例#4
0
        public async void CanGetProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService inventoryService = new InventoryService(context);
                Product          product          = new Product();
                await inventoryService.CreateProduct(product);

                var expected = await inventoryService.GetProductByID(product.ID);

                Assert.Equal(expected, product);
            }
        }
示例#5
0
        public async void CanCreateCheckout()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                Checkout        checkout        = new Checkout();
                CheckoutService checkoutService = new CheckoutService(context);
                await checkoutService.CreateCheckoutAsync(checkout);

                var expected = await context.Checkouts.FirstOrDefaultAsync(b => b.ID == checkout.ID);

                Assert.Equal(expected, checkout);
            }
        }
示例#6
0
        public async void CanGetCheckout()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                Checkout checkout = new Checkout();
                checkout.UserID = "userString";
                CheckoutService checkoutService = new CheckoutService(context);
                await checkoutService.CreateCheckoutAsync(checkout);

                var expected = await checkoutService.GetCheckoutByUserId(checkout.UserID, checkout.ID);

                Assert.Equal(expected, checkout);
            }
        }
示例#7
0
        public async void CanGetBasket()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                Basket basket = new Basket();
                basket.UserID = "userString";
                BasketService basketService = new BasketService(context);
                await basketService.CreateBasketAsync(basket);

                var expected = await basketService.GetBasketByUserId("userString");

                Assert.Equal(expected, basket);
            }
        }
示例#8
0
        public async void CanUpdateBasket()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                Basket basket = new Basket();
                basket.UserID = "userString";
                BasketService basketService = new BasketService(context);
                await basketService.CreateBasketAsync(basket);

                basket.UserID = "new string";
                await basketService.UpdateBasketAsync(basket);

                Assert.Equal("new string", basket.UserID);
            }
        }
示例#9
0
        public async void CanUpdateCheckout()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                Checkout checkout = new Checkout();
                checkout.UserID = "userString";
                CheckoutService checkoutService = new CheckoutService(context);
                await checkoutService.CreateCheckoutAsync(checkout);

                checkout.UserID = "new string";
                await checkoutService.UpdateCheckoutAsync(checkout);

                Assert.Equal("new string", checkout.UserID);
            }
        }
示例#10
0
        public async void CanGetAllProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("check2").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService inventoryService = new InventoryService(context);
                Product          product          = new Product();
                await inventoryService.CreateProduct(product);

                var expected = await inventoryService.GetAllProducts();

                Assert.Equal(new List <Product> {
                    product
                }, expected);
            }
        }
示例#11
0
        public async void CanUpdateProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("check3").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService inventoryService = new InventoryService(context);
                Product          product          = new Product();
                product.Name = "flower";
                await inventoryService.CreateProduct(product);

                product.Name = "sunflower";
                await inventoryService.Update(product);

                var expected = await inventoryService.GetProductByID(product.ID);

                Assert.Equal("sunflower", expected.Name);
            }
        }
示例#12
0
        public async void CanCreateCheckoutProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService       inventoryService       = new InventoryService(context);
                CheckoutProductService checkoutProductService = new CheckoutProductService(context);
                CheckoutService        checkoutService        = new CheckoutService(context);
                Checkout checkout = new Checkout();
                await checkoutService.CreateCheckoutAsync(checkout);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await checkoutProductService.AddCheckoutProduct(product.ID, 3, checkout.ID);

                var expected = await context.CheckoutProducts.FirstOrDefaultAsync(p => p.CheckoutID == checkout.ID && p.ProductID == product.ID);

                Assert.NotNull(expected);
            }
        }
示例#13
0
        public async void CanCreateBasketProduct()
        {
            DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options;

            using (NurseryDbContext context = new NurseryDbContext(options))
            {
                InventoryService     inventoryService     = new InventoryService(context);
                BasketProductService basketProductService = new BasketProductService(context);
                BasketService        basketService        = new BasketService(context);
                Basket basket = new Basket();
                await basketService.CreateBasketAsync(basket);

                Product product = new Product();
                await inventoryService.CreateProduct(product);

                await basketProductService.AddBasketProduct(product.ID, 3, basket.ID);

                var expected = await context.BasketProducts.FirstOrDefaultAsync(p => p.BasketID == basket.ID && p.ProductID == product.ID);

                Assert.NotNull(expected);
            }
        }
示例#14
0
 public ChildService(NurseryDbContext context)
 {
     _context = context;
 }
 public NurseryDbContextSeedData(NurseryDbContext context, UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager)
 {
     _context = context;
     _userManager = userManager;
     _roleManager = roleManager;
 }
示例#16
0
 /// <summary>
 /// Constructor method that connects the service to the app's databases through its matching context.
 /// </summary>
 /// <param name="context">DbContext connection to the NurseryDb</param>
 public BasketService(NurseryDbContext context)
 {
     _context = context;
 }
示例#17
0
 /// <summary>
 /// Constructor method that connects the service to the app's databases through its matching context.
 /// </summary>
 /// <param name="context">DbContext connection to the NurseryDb</param>
 public CheckoutService(NurseryDbContext context)
 {
     _context = context;
 }
示例#18
0
 public NurseriesRepository(NurseryDbContext context, ILogger<NurseriesRepository> logger)
 {
     _context = context;
     _logger = logger;
 }
示例#19
0
 /// <summary>
 /// Constructor method that connects the service to the app's databases through its matching context.
 /// </summary>
 /// <param name="context">DbContext connection to the NurseryDb</param>
 public InventoryService(NurseryDbContext context)
 {
     _context = context;
 }
示例#20
0
 /// <summary>
 /// Constructor method that connects the service to the app's databases through its matching context.
 /// </summary>
 /// <param name="context">DbContext connection to the NurseryDb</param>
 public ShopService(NurseryDbContext context)
 {
     _context = context;
 }
示例#21
0
 public RegisterService(NurseryDbContext context)
 {
     _context = context;
 }