コード例 #1
0
        public static void AddStockToShops(this CompanyDbContext context, string [] lines)
        {
            foreach (var line in lines)
            {
                var colonIndex = line.IndexOf(':');
                var shopName   = line.Substring(0, colonIndex);
                var shop       = context.Tenants.IgnoreQueryFilters().OfType <RetailOutlet>()
                                 .SingleOrDefault(x => x.Name == shopName);
                if (shop == null)
                {
                    throw new ApplicationException($"Could not find a shop of name '{shopName}'");
                }

                var eachStock = from stockAndPrice in line.Substring(colonIndex + 1).Split(',')
                                let parts = stockAndPrice.Split('|').Select(x => x.Trim()).ToArray()
                                            select new { Name = parts[0], Price = decimal.Parse(parts[1]) };
                foreach (var stock in eachStock)
                {
                    var newStock = new ShopStock {
                        Name = stock.Name, NumInStock = 5, RetailPrice = stock.Price, Shop = shop
                    };
                    newStock.SetShopLevelDataKey(shop.DataKey);
                    context.Add(newStock);
                }
            }
        }
コード例 #2
0
        public void TestDataKeyNotSetIfProvidedKeyIsNull()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CompanyDbContext>();

            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider(null)))
            {
                context.Database.EnsureCreated();
                var company = Company.AddTenantToDatabaseWithSaveChanges("TestCompany", PaidForModules.None, context);
                var shop    = RetailOutlet.AddTenantToDatabaseWithSaveChanges("TestShop", company, context);
                var stock   = new ShopStock {
                    Name = "dress", Shop = shop
                };
                stock.SetShopLevelDataKey("accessKey*");
                context.Add(stock);
                context.SaveChanges();
            }
            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider("accessKey*")))
            {
                //ATTEMPT
                var stocksFiltered = context.ShopStocks.ToList();

                //VERIFY
                stocksFiltered.Count.ShouldEqual(1);
            }
        }