public override InMemoryTestStore CreateTestStore()
     => InMemoryTestStore.GetOrCreateShared(DatabaseName, () =>
         {
             using (var context = new DataAnnotationContext(_options))
             {
                 DataAnnotationModelInitializer.Seed(context);
             }
         });
Esempio n. 2
0
        public override DataAnnotationContext CreateContext(SqlServerTestStore testStore)
        {
            var options = new DbContextOptionsBuilder(_options)
                          .UseSqlServer(testStore.Connection, b => b.ApplyConfiguration())
                          .Options;

            var context = new DataAnnotationContext(options);

            context.Database.UseTransaction(testStore.Transaction);
            return(context);
        }
Esempio n. 3
0
        public override DataAnnotationContext CreateContext(SqliteTestStore testStore)
        {
            var optionsBuilder = new DbContextOptionsBuilder(_options)
                                 .UseSqlite(
                testStore.Connection,
                b => b.SuppressForeignKeyEnforcement());

            var context = new DataAnnotationContext(optionsBuilder.Options);

            context.Database.UseTransaction(testStore.Transaction);
            return(context);
        }
Esempio n. 4
0
        public override SqliteTestStore CreateTestStore()
        => SqliteTestStore.GetOrCreateShared(DatabaseName, () =>
        {
            var optionsBuilder = new DbContextOptionsBuilder(_options)
                                 .UseSqlite(_connectionString);

            using (var context = new DataAnnotationContext(optionsBuilder.Options))
            {
                context.Database.EnsureClean();
                DataAnnotationModelInitializer.Seed(context);
            }
        });
Esempio n. 5
0
        public override SqlServerTestStore CreateTestStore()
        => SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
        {
            var options = new DbContextOptionsBuilder(_options)
                          .UseSqlServer(_connectionString, b => b.ApplyConfiguration())
                          .Options;

            using (var context = new DataAnnotationContext(options))
            {
                context.Database.EnsureCreated();
                DataAnnotationModelInitializer.Seed(context);
            }
        });
        public static void Seed(DataAnnotationContext context)
        {
            context.Ones.Add(new One {
                RequiredColumn = "First", RowVersion = new Guid("00000001-0000-0000-0000-000000000001")
            });
            context.Ones.Add(new One {
                RequiredColumn = "Second", RowVersion = new Guid("00000001-0000-0000-0000-000000000001")
            });

            context.Twos.Add(new Two {
                Data = "First"
            });
            context.Twos.Add(new Two {
                Data = "Second"
            });

            context.Books.Add(new Book {
                Id = "Book1"
            });

            context.SaveChanges();
        }