コード例 #1
0
        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();
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: IoTFier/EFCore.Seeder
        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();
            }
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
ファイル: TestDbContext.cs プロジェクト: palladiumkenya/cbs
        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();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: CbsContext.cs プロジェクト: palladiumkenya/cbs
        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();
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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));
        }
コード例 #11
0
ファイル: SettingsContext.cs プロジェクト: moshonk/dwapi
        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();
        }
コード例 #12
0
        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);
        }