Example #1
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Starting...");

            var optionsBuilder = new DbContextOptionsBuilder <SuperheroDbContext>();

            optionsBuilder.UseSqlServer(
                @"Server=(localdb)\mssqllocaldb;Database=dbEnumeratorSuperheros;Trusted_Connection=True;");

            using (var ctx = new SuperheroDbContext(optionsBuilder.Options))
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();
                await EnumBasedEntitySeeder.SeedEntityAsync <ComicEditorCatalogue, ComicEditor>(ctx.ComicEditors);

                await ctx.SaveChangesAsync();

                Console.WriteLine("Database create and seeded...");

                await ctx.AddAsync(new Superhero()
                {
                    Name = "Mento", Age = 30, ComicEditor = ComicEditor.Dc
                });

                await ctx.SaveChangesAsync();

                var mento = await ctx.Superheros.FirstOrDefaultAsync();

                Console.WriteLine($"Readed {mento.Name}, avaliable in {mento.ComicEditor} comics");
            }
        }
Example #2
0
        public async Task populate_enum_descriptions_using_dbset()
        {
            using (var context = _fixture.GetDbContext())
            {
                await EnumBasedEntitySeeder.SeedEntityAsync <ComicEditorCatalogue, ComicEditor>(context.ComicEditors);

                await context.SaveChangesAsync();

                (await context.ComicEditors.SingleAsync(c => c.Id == (int)ComicEditor.Dc)).Description
                .Should()
                .Be(TestUtils.GetEnumDescription(ComicEditor.Dc));
            }
        }
Example #3
0
        public async Task populate_all_enum_values_using_dbset()
        {
            using (var context = _fixture.GetDbContext())
            {
                await EnumBasedEntitySeeder.SeedEntityAsync <ComicEditorCatalogue, ComicEditor>(context.ComicEditors);

                await context.SaveChangesAsync();

                (await context.ComicEditors.CountAsync())
                .Should()
                .Be(Enum.GetValues(typeof(ComicEditor)).Length);
            }
        }