コード例 #1
0
        public void Test1()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();


            try
            {
                var options = new DbContextOptionsBuilder <OnlineGroceryStoreContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var _context = new OnlineGroceryStoreContext(options))
                {
                    _context.Database.EnsureCreated();
                    InventorySeedData.PopulateData(_context);
                    List <InventoryPackingConfigure> aa = _context.InventoryPackingConfigure.ToList();
                    TestOnePackConfig.Add(
                        new PackBreakdownViewModel
                    {
                        packQuantity = 2,
                        packingID    = 4,
                        inventoryPackingConfigure = _context.InventoryPackingConfigure.Where(x => x.packingID == 3).First(),
                    });
                    TestOnePackConfig.Add(
                        new PackBreakdownViewModel
                    {
                        packQuantity = 2,
                        packingID    = 3,
                        inventoryPackingConfigure = _context.InventoryPackingConfigure.Where(x => x.packingID == 3).First(),
                    });

                    Assert.Equals(PackageSelectionHelper.GetPackBreakdown(2, 28, _context), TestOnePackConfig);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <OnlineGroceryStoreContext>();
                    context.Database.EnsureCreated();
                    InventorySeedData.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }