public void Seed(CatalogDBContext context) { AddCatalogTypes(context); AddCatalogBrands(context); AddCatalogItems(context); AddCatalogItemPictures(); }
public void DetectionHooks_AreCalled() { // Arrange var hook = new TestChangeDetectorHook(); var hooks = new IChangeDetectorHook[] { hook }; var changeDetector = new ExtendedChangeDetector(hooks); var services = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .AddSingleton <IChangeDetector>(sp => changeDetector); var serviceProvider = services.BuildServiceProvider(); using (var context = new CatalogDBContext(serviceProvider)) { // MA - We have to add a entity, otherwise no change tracking entries will be tested. context.Add(new Product()); // Act context.ChangeTracker.DetectChanges(); // Assert Assert.Equal(true, hook.DetectingChangesCalled); Assert.Equal(true, hook.DetectingEntryChangesCalled); Assert.Equal(true, hook.DetectedEntryChangesCalled); Assert.Equal(true, hook.DetectedChangesCalled); } }
private void AddCatalogItems(CatalogDBContext context) { var preconfiguredItems = _dataSettings.UseCustomizationData ? GetCatalogItemsFromFile(context) : PreconfiguredData.GetPreconfiguredCatalogItems(); foreach (var item in preconfiguredItems) { if (context.CatalogItems.FirstOrDefault(x => x.Name.Equals(item.Name)) == null) { item.Id = 0; context.CatalogItems.Add(item); } } context.SaveChanges(); }
private void AddCatalogBrands(CatalogDBContext context) { var preconfiguredBrands = _dataSettings.UseCustomizationData ? GetCatalogBrandsFromFile() : PreconfiguredData.GetPreconfiguredCatalogBrands(); foreach (var brand in preconfiguredBrands) { if (context.CatalogBrands.FirstOrDefault(x => x.Id.Equals(brand.Id)) == null) { brand.Id = brand.Id; context.CatalogBrands.Add(brand); } } context.SaveChanges(); }
private void AddCatalogTypes(CatalogDBContext context) { var preconfiguredTypes = _dataSettings.UseCustomizationData ? GetCatalogTypesFromFile() : PreconfiguredData.GetPreconfiguredCatalogTypes(); foreach (var type in preconfiguredTypes) { if (context.CatalogTypes.FirstOrDefault(x => x.Id.Equals(type.Id)) == null) { type.Id = type.Id; context.CatalogTypes.Add(type); } } context.SaveChanges(); }
public int GetNextSequenceValue(CatalogDBContext db) { lock (sequenceLock) { if (remainningLoIds == 0) { var rawQuery = db.Database.SqlQuery <Int64>("SELECT NEXT VALUE FOR catalog_hilo;"); sequenceId = (int)rawQuery.Single(); remainningLoIds = HiLoIncrement - 1; return(sequenceId); } else { remainningLoIds--; return(++sequenceId); } } }
IEnumerable <CatalogItem> GetCatalogItemsFromFile(CatalogDBContext context) { var contentRootPath = _webHostEnvironment.ContentRootPath; string csvFileCatalogItems = Path.Combine(contentRootPath, "Setup", "CatalogItems.csv"); if (!File.Exists(csvFileCatalogItems)) { return(PreconfiguredData.GetPreconfiguredCatalogItems()); } string[] csvheaders; string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "pictureFileName" }; string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" }; csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders); var catalogTypeIdLookup = context.CatalogTypes.ToDictionary(ct => ct.Type, ct => ct.Id); var catalogBrandIdLookup = context.CatalogBrands.ToDictionary(ct => ct.Brand, ct => ct.Id); return(File.ReadAllLines(csvFileCatalogItems) .Skip(1) // skip header row .Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")) .Select(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup)) .Where(x => x != null)); }
public CatalogService(CatalogDBContext db, CatalogItemHiLoGenerator indexGenerator) { this.db = db; this.indexGenerator = indexGenerator; }
public CatalogController(CatalogDBContext context) { _context = context; }
public CategoryRepository(CatalogDBContext context) { this.context = context; }
public Repository(CatalogDBContext context) { this.context = context; this.dBSet = context.Set <T>(); }
public CatalogService(CatalogDBContext db) { this.db = db; }
public ProductRepository(CatalogDBContext context) { this.context = context; }
public ProviderRepository(CatalogDBContext context) { this.context = context; }
public UnitOfWork() { context = new CatalogDBContext(); }