Example #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);
        }