public override void EnsureSeeded() { var csvConfig = new CsvConfiguration { Delimiter = "|", SkipEmptyRecords = true, TrimFields = true, TrimHeaders = true, WillThrowOnMissingField = false }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(SettingsContext).GetTypeInfo().Assembly); Dockets.SeedDbSetIfEmpty($"{nameof(Dockets)}"); CentralRegistries.SeedDbSetIfEmpty($"{nameof(CentralRegistries)}"); EmrSystems.SeedDbSetIfEmpty($"{nameof(EmrSystems)}"); DatabaseProtocols.SeedDbSetIfEmpty($"{nameof(DatabaseProtocols)}"); RestProtocols.SeedDbSetIfEmpty($"{nameof(RestProtocols)}"); Resources.SeedDbSetIfEmpty($"{nameof(Resources)}"); var ex = Extracts.Where(e => e.EmrSystemId.ToString() == "a62216ee-0e85-11e8-ba89-0ed5f89f718b" || e.EmrSystemId.ToString() == "a6221856-0e85-11e8-ba89-0ed5f89f718b" || e.EmrSystemId.ToString() == "a6221857-0e85-11e8-ba89-0ed5f89f718b" ); Extracts.RemoveRange(ex); Extracts.SeedFromResource($"{nameof(Extracts)}"); SaveChanges(); }
public void EntitySeederSeedFromResource_RunsExtensionMethod_WhenCalled() { #region Setup var dbSetHelperMock = new Mock <IDbSetHelper>(); dbSetHelperMock.Setup(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>())); var dbSetMock = new Mock <DbSet <Product> >(); SeederConfiguration.ResetConfiguration(assembly: typeof(SeederTests).GetTypeInfo().Assembly); SeederConfiguration.DbSetHelper = dbSetHelperMock.Object; #endregion var results = dbSetMock.Object.SeedFromResource(nameof(Product)); dbSetHelperMock.Verify(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>()), Times.Once); Assert.True(results.Exists(product => product.Code == "ABCDE")); var additionalMapping = new[] { new CsvColumnMapping <Product>("ExtraInformation", (product, extraInfo) => { product.Description = (string)extraInfo; }) }; results = dbSetMock.Object.SeedFromResource(nameof(Product), additionalMapping); dbSetHelperMock.Verify(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>()), Times.Exactly(2)); Assert.True(results.Exists(product => product.Description == "Extra Information")); }
static void Main(string[] args) { CultureInfo.CurrentCulture = new CultureInfo("en-US"); var csvConfiguration = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.CurrentCulture) { Delimiter = ",", PrepareHeaderForMatch = (s, i) => s.TrimStart().TrimEnd(), HasHeaderRecord = true, SanitizeForInjection = true, MissingFieldFound = null }; var manifestConfiguration = new ManifestConfiguration { Format = "{delimiter}{resource}{delimiter}{extension}", Delimiter = ".", Extension = "csv", ExtensionFieldName = "{extension}", ResourceFieldName = "{resource}", DelimiterFieldName = "{delimiter}" }; SeederConfiguration.ResetConfiguration(csvConfiguration, manifestConfiguration, assembly: typeof(Program).GetTypeInfo().Assembly); using (var context = new ProductsDbContext()) { //context.Products.SeedDbSetIfEmpty(nameof(context.Products)); context.Suppliers.SeedFromResource(nameof(context.Suppliers)); context.SaveChanges(); } }
public override void EnsureSeeded() { var csvConfig = new Configuration() { Delimiter = "|" }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(HtsContext).GetTypeInfo().Assembly); // MasterFacilities.SeedDbSetIfEmpty($"{nameof(MasterFacility)}"); Dockets.SeedDbSetIfEmpty($"{nameof(Docket)}"); SaveChanges(); Subscribers.SeedDbSetIfEmpty($"{nameof(Subscriber)}"); SaveChanges(); }
public override void EnsureSeeded() { var csvConfig = new CsvConfiguration { Delimiter = "|", SkipEmptyRecords = true, TrimFields = true, TrimHeaders = true, WillThrowOnMissingField = false }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(ExtractsContext).GetTypeInfo().Assembly); Validator.RemoveRange(Validator); Validator.SeedFromResource($"{nameof(Validator)}"); SaveChanges(); }
public override void EnsureSeeded() { var csvConfig = new CsvConfiguration { SkipEmptyRecords = true, TrimFields = true, TrimHeaders = true, WillThrowOnMissingField = false }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(SettingsContext).GetTypeInfo().Assembly); TestCars.SeedDbSetIfEmpty($"{nameof(TestCar)}"); TestModels.SeedDbSetIfEmpty($"{nameof(TestModel)}"); base.EnsureSeeded(); }
public void EntitySeederSeedFromResource_ThrowsException_WhenCalled() { #region Setup var dbSetHelperMock = new Mock <IDbSetHelper>(); dbSetHelperMock.Setup(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>())) .Throws(new Exception()); var dbSetMock = new Mock <DbSet <Product> >(); SeederConfiguration.ResetConfiguration(assembly: typeof(SeederTests).GetTypeInfo().Assembly); SeederConfiguration.DbSetHelper = dbSetHelperMock.Object; #endregion var exception = Assert.Throws <Exception>(() => dbSetMock.Object.SeedFromResource(nameof(Product))); dbSetHelperMock.Verify(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>()), Times.Once); Assert.Contains("Error Seeding DbSet<Product>", exception.Message); }
public override void EnsureSeeded() { var csvConfig = new CsvConfiguration { Delimiter = "|", SkipEmptyRecords = true, TrimFields = true, TrimHeaders = true, WillThrowOnMissingField = false }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(CbsContext).GetTypeInfo().Assembly); MasterFacilities.SeedDbSetIfEmpty($"{nameof(MasterFacility)}"); Dockets.SeedDbSetIfEmpty($"{nameof(Docket)}"); SaveChanges(); Subscribers.SeedDbSetIfEmpty($"{nameof(Subscriber)}"); SaveChanges(); }
public override void EnsureSeeded() { var csvConfig = new CsvConfiguration { Delimiter = "|", SkipEmptyRecords = true, TrimFields = true, TrimHeaders = true, WillThrowOnMissingField = false }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(DwhDashboardContext).GetTypeInfo().Assembly); Impersonators.SeedDbSetIfEmpty($"{nameof(Impersonator)}"); Organizations.SeedDbSetIfEmpty($"{nameof(Organization)}"); Users.SeedDbSetIfEmpty($"{nameof(User)}"); ViewConfigs.SeedDbSetIfEmpty($"{nameof(ViewConfig)}"); SaveChanges(); }
public void EntitySeederSeedDbSetIfEmpty_RunsSeedFromResource_WhenCalled() { #region Setup var dbSetHelperMock = new Mock <IDbSetHelper>(); dbSetHelperMock.Setup(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>())); dbSetHelperMock.Setup(helper => helper.Any(It.IsAny <DbSet <Product> >())).Returns(false); var dbSetMock = new Mock <DbSet <Product> >(); const string verifiableCode = "ABCDE"; SeederConfiguration.ResetConfiguration(assembly: typeof(SeederTests).GetTypeInfo().Assembly); SeederConfiguration.DbSetHelper = dbSetHelperMock.Object; #endregion var results = dbSetMock.Object.SeedDbSetIfEmpty(nameof(Product)); Assert.True(results.Exists(product => product.Code == verifiableCode)); }
public override void EnsureSeeded() { var csvConfig = new CsvConfiguration { Delimiter = "|", SkipEmptyRecords = true, TrimFields = true, TrimHeaders = true, WillThrowOnMissingField = false }; SeederConfiguration.ResetConfiguration(csvConfig, null, typeof(SettingsContext).GetTypeInfo().Assembly); Dockets.SeedDbSetIfEmpty($"{nameof(Dockets)}"); CentralRegistries.SeedDbSetIfEmpty($"{nameof(CentralRegistries)}"); EmrSystems.SeedDbSetIfEmpty($"{nameof(EmrSystems)}"); DatabaseProtocols.SeedDbSetIfEmpty($"{nameof(DatabaseProtocols)}"); Extracts.SeedDbSetIfEmpty($"{nameof(Extracts)}"); SaveChanges(); }
public void EntitySeederSeedFromResource_ThrowsException_WhenCalledWithNullAssembly() { #region Setup var dbSetHelperMock = new Mock <IDbSetHelper>(); dbSetHelperMock.Setup(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>())); var dbSetMock = new Mock <DbSet <Product> >(); SeederConfiguration.ResetConfiguration(); SeederConfiguration.DbSetHelper = dbSetHelperMock.Object; #endregion const string invalidManifestResourceName = "InvalidManifestName"; var exception = Assert.Throws <Exception>(() => dbSetMock.Object.SeedFromResource(invalidManifestResourceName)); dbSetHelperMock.Verify(helper => helper.AddOrUpdate(It.IsAny <DbSet <Product> >(), It.IsAny <Product>()), Times.Never); Assert.Contains($"Invalid assembly or manifest resource name: {invalidManifestResourceName}", exception.Message); }