コード例 #1
0
        public async Task DeleteShippingMethodShouldDelete()
        {
            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();

            await service.DeleteShippingMethodAsync(shipping.Id);

            var shippingMethodDB = context.ShippingMethods.FirstOrDefault();

            Assert.Null(shippingMethodDB);
        }