예제 #1
0
        public async Task AddShippingMethodShouldNotCreateNewMethodIfExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var mockInventoryService = new Mock <IInventoryService>();
            var service         = new ShippingService(context, mockInventoryService.Object);
            var shippingService = "FedEx";
            var carrier         = new Carrier {
                Name = shippingService
            };

            context.Carriers.Add(carrier);
            var shipping = new ShippingMethod {
                Carrier = carrier, CarrierId = carrier.Id, Name = shippingService
            };

            context.ShippingMethods.Add(shipping);
            await context.SaveChangesAsync();

            var id = await service.AddShippingMethodAsync(carrier.Id, shippingService);

            var shippingMethodDB = context.ShippingMethods.FirstOrDefault();

            Assert.Equal(shippingService, shippingMethodDB.Name);
            Assert.Equal(id, shippingMethodDB.Id);
        }
예제 #2
0
        public async Task CreateCustomerShouldUpdateExistingCustomer()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            context.Customers.Add(new Customer {
                Email = "*****@*****.**", FirstName = "Pesho", LastName = "Peshov", PhoneNumber = "000000"
            });
            await context.SaveChangesAsync();

            var service = new CustomersService(context);
            var model   = new CustomerViewModel {
                Email = "*****@*****.**", FirstName = "Test", LastName = "Testov", PhoneNumber = "123451234"
            };

            await service.CreateOrUpdateCustomerAsync(model);

            var dbCustomer = context.Customers.FirstOrDefault();

            Assert.NotNull(dbCustomer);
            Assert.Equal("*****@*****.**", dbCustomer.Email);
            Assert.Equal("Test", dbCustomer.FirstName);
            Assert.Equal("Testov", dbCustomer.LastName);
            Assert.Equal("123451234", dbCustomer.PhoneNumber);
        }
예제 #3
0
 public OrdersService(WHMSDbContext context, IInventoryService inventoryService, ICustomersService customersService)
 {
     this.context          = context;
     this.inventoryService = inventoryService;
     this.customersService = customersService;
     this.mapper           = AutoMapperConfig.MapperInstance;
 }
예제 #4
0
        public async Task AddOrderShouldCreateNewOrder()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };

            context.Warehouses.Add(warehouse);

            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var mockCustomersService = new Mock <ICustomersService>();

            var service = new OrdersService(context, mockInventoryService.Object, mockCustomersService.Object);

            var model = new AddOrderInputModel {
                Channel = 0, Customer = new CustomerViewModel {
                }, SourceOrderId = "test",
            };
            await service.AddOrderAsync(model);

            var dbOrder = context.Orders.FirstOrDefault();

            Assert.NotNull(dbOrder);
        }
예제 #5
0
        public async Task SeedAsync(WHMSDbContext dbContext, IServiceProvider serviceProvider)
        {
            var userManager   = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
            var configuration = serviceProvider.GetRequiredService <IConfiguration>();

            await SeedAdminAsync(userManager, configuration, GlobalConstants.AdministratorRoleName);
        }
예제 #6
0
        public async Task GetAvailableInventoryShouldReturnPositiveWithPositiveAggregateInventoryInWarehouse()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };
            var productWarehouse = new ProductWarehouse
            {
                Product               = product,
                Warehouse             = warehouse,
                AggregateQuantity     = 10,
                TotalPhysicalQuanitiy = 10,
                ReservedQuantity      = 0,
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            context.ProductWarehouses.Add(productWarehouse);
            await context.SaveChangesAsync();

            var service            = new InventoryService(context);
            var availableInventory = service.GetProductAvailableInventory(product.Id);
            var expected           = 10;

            Assert.Equal(expected, availableInventory);
        }
예제 #7
0
        public async Task EditProductShouldEditProperties()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var product = new Product
            {
                ProductName      = "Test Product",
                ShortDescription = "Test Product",
                WebsitePrice     = 23,
            };

            context.Products.Add(product);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var service = new ProductsService(context, mockInventoryService.Object);

            var editedProduct = new ProductDetailsInputModel {
                Id = product.Id, ProductName = "Edited", ShortDescription = "Edited", WebsitePrice = 100,
            };
            await service.EditProductAsync <ProductDetailsViewModel, ProductDetailsInputModel>(editedProduct);

            var dbProduct = context.Products.FirstOrDefault();

            Assert.Equal(editedProduct.ProductName, dbProduct.ProductName);
            Assert.Equal(editedProduct.ShortDescription, dbProduct.ShortDescription);
            Assert.Equal(editedProduct.WebsitePrice, dbProduct.WebsitePrice);
        }
예제 #8
0
        public async Task AdjustInventoryShouldAdjustInventoryCorrectlyWhenProductWarehouseDoesntExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            await context.SaveChangesAsync();

            var service    = new InventoryService(context);
            var adjustment = new ProductAdjustmentInputModel {
                ProductId = product.Id, Qty = 10, WarehouseId = warehouse.Id
            };
            await service.AdjustInventoryAsync(adjustment);

            var productWarehouse = context.ProductWarehouses.FirstOrDefault();
            var expected         = 10;

            Assert.NotNull(productWarehouse);
            Assert.Equal(expected, productWarehouse.AggregateQuantity);
        }
예제 #9
0
        public async Task GetAllProductsWithFiltersAndPaging()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            for (int i = 0; i < 100; i++)
            {
                var product = new Product
                {
                    ProductName      = "Test Product",
                    ShortDescription = "Test Product",
                    WebsitePrice     = 23,
                    BrandId          = i % 2,
                };
                context.Products.Add(product);
            }

            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var service = new ProductsService(context, mockInventoryService.Object);

            var filter = new ProductFilterInputModel {
                BrandId = 1
            };
            var products = service.GetAllProducts <ProductDetailsViewModel>(filter);

            Assert.Equal(GlobalConstants.PageSize, products.Count());
            foreach (var item in products)
            {
                Assert.Equal(1, item.BrandId);
            }
        }
예제 #10
0
        public async Task GetAllWarehousesShouldReturnAllWarehouses()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            for (int i = 0; i < 5; i++)
            {
                await context.Warehouses.AddAsync(new Warehouse
                {
                    Address = new Address
                    {
                        City          = "Test",
                        StreetAddress = "Test",
                        ZIP           = "test",
                        Country       = "Test",
                    },
                    Name = "Test",
                });
            }

            await context.SaveChangesAsync();

            var service = new WarehouseService(context);

            var warehouses       = service.GetAllWarehouses <WarehouseViewModel>();
            var warehousessCount = warehouses.ToList().Count();
            var exepcetedCount   = context.Warehouses.Count();

            Assert.Equal(exepcetedCount, warehousessCount);
        }
예제 #11
0
        public async Task RecalcualteAvaialbleInventoryShouldCreateProductWarehouseIfItDoesntExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);

            await context.SaveChangesAsync();

            var service = new InventoryService(context);
            await service.RecalculateAvailableInventoryAsync(product.Id);

            var productWarehouse = context.ProductWarehouses.FirstOrDefault();

            Assert.NotNull(productWarehouse);
            Assert.Equal(0, productWarehouse.AggregateQuantity);
        }
예제 #12
0
        public async Task GetProductWarehousesShouldReturnCorrectInfoWhenProductWarehouseDoesNotExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address
                {
                    City          = "Test",
                    StreetAddress = "Test",
                    ZIP           = "test",
                    Country       = "Test",
                },
                Name = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            await context.SaveChangesAsync();

            var service = new WarehouseService(context);
            var serviceProductWarehouse = service.GetProductWarehouseInfo(product.Id).FirstOrDefault();

            Assert.Equal(product.Id, serviceProductWarehouse.ProductId);
            Assert.Equal(warehouse.Name, serviceProductWarehouse.WarehouseName);
            Assert.Equal(0, serviceProductWarehouse.TotalPhysicalQuanitity);
            Assert.Equal(0, serviceProductWarehouse.AggregateQuantity);
            Assert.Equal(0, serviceProductWarehouse.ReservedQuantity);
        }
예제 #13
0
        public async Task CreateWarehouseShouldCreateNewWarehouse()
        {
            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly);
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var service = new WarehouseService(context);

            var warehouse = new WarehouseViewModel
            {
                Address = new AddressViewModel
                {
                    City          = "Test",
                    StreetAddress = "Test",
                    Zip           = "test",
                    Country       = "Test",
                },
                Name       = "Test",
                IsSellable = true,
            };

            await service.CreateWarehouseAsync(warehouse);

            var warehouseCount = context.Warehouses.Count();
            var expectedCount  = 1;

            Assert.Equal(expectedCount, warehouseCount);
        }
예제 #14
0
        public async Task GetProductsCountTestWithouitFilter()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            for (int i = 0; i < 100; i++)
            {
                var product = new Product
                {
                    ProductName      = "Test Product",
                    ShortDescription = "Test Product",
                    WebsitePrice     = 23,
                    BrandId          = i % 2,
                };
                context.Products.Add(product);
            }

            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var service = new ProductsService(context, mockInventoryService.Object);

            var productsCount = service.GetAllProductsCount();

            Assert.Equal(100, productsCount);
        }
예제 #15
0
        public async Task GetProductImagesTest()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var product = new Product
            {
                ProductName      = "Test Product",
                ShortDescription = "Test Product",
            };

            context.Products.Add(product);
            await context.SaveChangesAsync();

            context.Images.Add(new Image {
                ProductId = product.Id, Url = "https://c8.alamy.com/comp/D8RWP0/url-of-web-browser-D8RWP0.jpg"
            });
            context.SaveChanges();
            var mockInventoryService = new Mock <IInventoryService>();
            var service = new ProductsService(context, mockInventoryService.Object);

            var images = service.GetProductImages <ImageViewModel>(product.Id);

            Assert.True(images.Count() == 1);
        }
예제 #16
0
        public async Task DeleteOrderShouldDeleteOrder()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };

            context.Warehouses.Add(warehouse);

            var order = new Order {
                WarehouseId = warehouse.Id
            };

            context.Orders.Add(order);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var mockCustomersService = new Mock <ICustomersService>();

            var service = new OrdersService(context, mockInventoryService.Object, mockCustomersService.Object);

            await service.DeleteOrderAsync(order.Id);

            var dbOrder = context.Orders.FirstOrDefault();

            Assert.Null(dbOrder);
        }
예제 #17
0
        public async Task SeedAsync(WHMSDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(ApplicationDbContextSeeder));

            var seeders = new List <ISeeder>
            {
                new RolesSeeder(),
                new ConditionsSeeder(),
                new CarriersSeeder(),
                new ShippingMethodsSeeder(),
                new AdminSeeder(),
                new WarehouseSeeder(),
            };

            foreach (var seeder in seeders)
            {
                await seeder.SeedAsync(dbContext, serviceProvider);

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
예제 #18
0
        public async Task AddOrderItemsShouldUpdateQtyIfItemsIsAlreadyAdded()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };
            var productWarehouse = new ProductWarehouse
            {
                Product               = product,
                Warehouse             = warehouse,
                AggregateQuantity     = 0,
                TotalPhysicalQuanitiy = 10,
                ReservedQuantity      = 5,
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            context.ProductWarehouses.Add(productWarehouse);
            var order = new Order {
                WarehouseId = warehouse.Id
            };

            context.Orders.Add(order);
            var orderItem = new OrderItem {
                OrderId = order.Id, ProductId = product.Id, Qty = 3
            };

            context.Orders.Add(order);
            context.OrderItems.Add(orderItem);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var mockOrdersService    = new Mock <IOrdersService>();
            var service = new OrderItemsService(context, mockInventoryService.Object, mockOrdersService.Object);
            var model   = new AddOrderItemsInputModel {
                OrderId = order.Id, OrderItems = new List <AddOrderItemViewModel> {
                    new AddOrderItemViewModel {
                        ProductId = product.Id, Price = 100, Qty = -30
                    }
                }
            };

            var id = await service.AddOrderItemAsync(model);

            var orderItemDB = context.OrderItems.FirstOrDefault();

            Assert.Null(orderItemDB);
        }
예제 #19
0
        public async Task DeletePaymentShouldAddPaymentAndUpdateStatus()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };
            var productWarehouse = new ProductWarehouse
            {
                Product               = product,
                Warehouse             = warehouse,
                AggregateQuantity     = 0,
                TotalPhysicalQuanitiy = 10,
                ReservedQuantity      = 5,
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            context.ProductWarehouses.Add(productWarehouse);
            var order = new Order {
                WarehouseId = warehouse.Id, GrandTotal = 100
            };

            context.Orders.Add(order);
            var orderItem = new OrderItem {
                OrderId = order.Id, ProductId = product.Id, Qty = 3
            };

            context.Orders.Add(order);
            context.OrderItems.Add(orderItem);
            var payment = new Payment {
                Amount = 100, OrderId = order.Id,
            };

            context.Payments.Add(payment);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var mockCustomersService = new Mock <ICustomersService>();

            var service = new OrdersService(context, mockInventoryService.Object, mockCustomersService.Object);
            await service.DeletePaymentAsync(payment.Id);

            var paymentDb = context.Payments.FirstOrDefault();

            Assert.Null(paymentDb);
            Assert.True(order.PaymentStatus == PaymentStatus.NoPayment);
        }
예제 #20
0
        public async Task RecalcInventoryAfterUnshipping()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };
            var productWarehouse = new ProductWarehouse
            {
                Product               = product,
                Warehouse             = warehouse,
                AggregateQuantity     = 0,
                TotalPhysicalQuanitiy = 10,
                ReservedQuantity      = 5,
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            context.ProductWarehouses.Add(productWarehouse);

            await context.SaveChangesAsync();

            var order = new Order {
                WarehouseId = warehouse.Id, ShippingStatus = ShippingStatus.Unshipped
            };

            context.Orders.Add(order);
            var orderItem = new OrderItem {
                ProductId = product.Id, Qty = 5, OrderId = order.Id, Order = order
            };

            context.OrderItems.Add(orderItem);
            await context.SaveChangesAsync();

            var service = new InventoryService(context);
            await service.RecalculateInventoryAfterUnshippingAsync(product.Id, warehouse.Id);

            productWarehouse = context.ProductWarehouses.FirstOrDefault();
            var expected         = 5;
            var expectedPhysical = 15;

            Assert.Equal(expected, productWarehouse.ReservedQuantity);
            Assert.Equal(expectedPhysical, productWarehouse.TotalPhysicalQuanitiy);
        }
예제 #21
0
        public async Task DeleteBrandShouldDeleteExistingBrand()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            await context.Brands.AddAsync(new Brand { Id = 10 });

            var service = new BrandsService(context);

            var success = await service.DeleteBrandAsync(10);

            Assert.True(success);
        }
예제 #22
0
        public async Task AddOrderItemsShouldAddNewItemsToOrderWhenAddingItemsFromProduct()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };
            var productWarehouse = new ProductWarehouse
            {
                Product               = product,
                Warehouse             = warehouse,
                AggregateQuantity     = 0,
                TotalPhysicalQuanitiy = 10,
                ReservedQuantity      = 5,
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            context.ProductWarehouses.Add(productWarehouse);
            var order = new Order {
                WarehouseId = warehouse.Id
            };

            context.Orders.Add(order);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var mockOrdersService    = new Mock <IOrdersService>();
            var service = new OrderItemsService(context, mockInventoryService.Object, mockOrdersService.Object);
            var model   = new AddProductToOrderInputModel {
                OrderId = order.Id, ProductId = product.Id, Qty = 10
            };

            var id = await service.AddOrderItemAsync(model);

            var orderItemDB = context.OrderItems.FirstOrDefault();

            Assert.NotNull(orderItemDB);
            Assert.Equal(order.Id, id);
            Assert.True(orderItemDB.OrderId == order.Id);
            Assert.True(orderItemDB.ProductId == product.Id);
        }
예제 #23
0
        public async Task CancelOrderShouldSetOrderStatusToCancelled()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var warehouse = new Warehouse
            {
                Address = new Address {
                },
                Name    = "Test",
            };
            var product = new Product
            {
                ProductName = "Test Product",
            };
            var productWarehouse = new ProductWarehouse
            {
                Product               = product,
                Warehouse             = warehouse,
                AggregateQuantity     = 0,
                TotalPhysicalQuanitiy = 10,
                ReservedQuantity      = 5,
            };

            context.Warehouses.Add(warehouse);
            context.Products.Add(product);
            context.ProductWarehouses.Add(productWarehouse);
            var order = new Order {
                WarehouseId = warehouse.Id
            };

            context.Orders.Add(order);
            var orderItem = new OrderItem {
                OrderId = order.Id, ProductId = product.Id, Qty = 3
            };

            context.Orders.Add(order);
            context.OrderItems.Add(orderItem);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var mockCustomersService = new Mock <ICustomersService>();

            var service = new OrdersService(context, mockInventoryService.Object, mockCustomersService.Object);

            await service.CancelOrderAsync(order.Id);

            Assert.True(order.OrderStatus == OrderStatus.Cancelled);
            mockInventoryService.Verify(x => x.RecalculateAvailableInventoryAsync(It.IsAny <int>()), Times.AtLeastOnce);
        }
예제 #24
0
        public async Task SeedAsync(WHMSDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.Warehouses.Any())
            {
                return;
            }

            await dbContext.Warehouses.AddAsync(new Warehouse()
            {
                Name = "Default Warehouse", Address = new Address {
                    StreetAddress = "Default Warehouse"
                }, IsSellable = true
            });
        }
예제 #25
0
        public async Task DeleteBrandShouldReturnFalseBrandDoesNotExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            await context.Brands.AddAsync(new Brand { Name = "Test" });

            await context.SaveChangesAsync();

            var service = new BrandsService(context);

            var success = await service.DeleteBrandAsync(20);

            Assert.False(success);
        }
예제 #26
0
        public async Task CreateBrandShouldCreateNewBrand()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: "TestDB").Options;

            using var context = new WHMSDbContext(options);
            var service = new BrandsService(context);

            var brandId = await service.CreateBrandAsync("TestBrand");

            var brandsCount   = service.GetAllBrandsCount();
            var expectedCount = 1;

            Assert.Equal(expectedCount, brandsCount);
            Assert.Equal(1, brandId);
        }
예제 #27
0
        public async Task CreateManufacturerShouldCreateNewManufacturer()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var service = new ManufacturersService(context);

            var manufacturerId = await service.CreateManufacturerAsync("TestManufacturer");

            var manufacturersCount = service.GetAllManufacturersCount();
            var expectedCount      = 1;

            Assert.Equal(expectedCount, manufacturersCount);
            Assert.Equal(1, manufacturerId);
        }
예제 #28
0
        public async Task AddCarrierShouldCreateNewCarrierIfItDoesntExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var mockInventoryService = new Mock <IInventoryService>();
            var service = new ShippingService(context, mockInventoryService.Object);

            var carrierName = "FedEx";
            await service.AddCarrierAsync(carrierName);

            var carrierDb = context.Carriers.FirstOrDefault();

            Assert.NotNull(carrierDb);
            Assert.Equal(carrierName, carrierDb.Name);
        }
예제 #29
0
        public async Task GetCustomersCountShouldBeCorrect()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            context.Customers.Add(new Customer {
                Email = "*****@*****.**", FirstName = "Pesho", LastName = "Peshov", PhoneNumber = "000000", Address = new Address {
                }
            });
            await context.SaveChangesAsync();

            var service = new CustomersService(context);

            var count = service.CustomersCount();

            Assert.Equal(1, count);
        }
예제 #30
0
        public async Task CreateConditionShouldCreateNewCondition()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var service = new ConditionsService(context);

            var testCondition = new ConditionViewModel {
                Name = "Test", Description = "Description"
            };
            var conditionId = await service.CreateProductConditionAsync(testCondition);

            var condition = context.ProductConditions.FirstOrDefault();

            Assert.Equal(condition.Id, conditionId);
            Assert.Equal(condition.Name, testCondition.Name);
            Assert.Equal(condition.Description, testCondition.Description);
        }