Exemple #1
0
        protected override TestServer CreateServer()
        {
            var config = ConfigurationProvider.BuildBearerConfiguration();

            return(new TestServer(new WebHostBuilder()
                                  .UseStartup <BookStoreApplication.Startup>()
                                  .UseConfiguration(config)
                                  .ConfigureTestServices((services) => {
                //https://github.com/aspnet/Hosting/issues/1012
                services.AddSingleton(provider => {
                    var bookStoreDbOptions = new DbContextOptionsBuilder <BookStoreContext>()
                                             .UseInMemoryDatabase(_BStoreDbName)
                                             .Options;
                    var bookStoreDbContext = new MockBookStoreInMemoryContext(bookStoreDbOptions, config);
                    //bookStoreDbContext.Database.EnsureDeleted();
                    return bookStoreDbContext;
                });

                services.AddSingleton(provider => {
                    var bookStoreIdentityDbOptions = new DbContextOptionsBuilder <BookStoreIdentityDbContext>()
                                                     .UseInMemoryDatabase(_BIdentityDbName)
                                                     .Options;
                    var bookStoreIdentityDbContext = new BookStoreIdentityDbContext(bookStoreIdentityDbOptions, config);
                    //bookStoreIdentityDbContext.Database.EnsureDeleted();

                    return bookStoreIdentityDbContext;
                });
                services.AddControllers().AddNewtonsoftJson(options => {
                    options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                    options.SerializerSettings.MaxDepth = 2;
                });
                services.AddScoped <IBookStoreUnitOfWorkAsync, MockBookStoreInMemoryUnitOfWork>();
                services.AddTransient <IAppDataSeeder, TDataSeeder>();
            })));
        }
Exemple #2
0
        protected override TestServer CreateServer()
        {
            var config = ConfigurationProvider.BuildBearerConfiguration();

            return(new TestServer(new WebHostBuilder()
                                  .UseStartup <BookStoreApplication.Startup>()
                                  .UseConfiguration(config)
                                  .ConfigureTestServices((services) => {
                //https://github.com/aspnet/Hosting/issues/1012
                services.AddSingleton(provider => {
                    var bookStoreDbOptions = new DbContextOptionsBuilder <BookStoreContext>()
                                             .UseSqlite("Data Source=Sharable;Mode=Memory;Cache=Shared", optionsAction => {
                        optionsAction.MigrationsHistoryTable("EFMigrations");
                    })
                                             //.UseInMemoryDatabase("IMBookStoreIdentity")
                                             .Options;
                    //var bookStoreDbContext = new MockBookStoreInMemoryContext(bookStoreDbOptions, config);
                    var bookStoreDbContext = new BookStoreContext(bookStoreDbOptions, config);
                    bookStoreDbContext.Database.EnsureDeleted();
                    bookStoreDbContext.Database.EnsureCreated();
                    bookStoreDbContext.Database.Migrate();
                    return bookStoreDbContext;
                });

                services.AddSingleton(provider => {
                    var bookStoreIdentityDbOptions = new DbContextOptionsBuilder <BookStoreIdentityDbContext>()
                                                     .UseSqlite("Data Source=Sharable;Mode=Memory;Cache=Shared")
                                                     //.UseInMemoryDatabase("IMBookStoreIdentity")
                                                     .Options;
                    var bookStoreIdentityDbContext = new BookStoreIdentityDbContext(bookStoreIdentityDbOptions, config);
                    bookStoreIdentityDbContext.Database.EnsureDeleted();
                    bookStoreIdentityDbContext.Database.EnsureCreated();
                    bookStoreIdentityDbContext.Database.Migrate();
                    return bookStoreIdentityDbContext;
                });
                services.AddControllers().AddNewtonsoftJson(options => {
                    options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                    options.SerializerSettings.MaxDepth = 2;
                });
                services.AddScoped <IBookStoreUnitOfWorkAsync, EntityBookStoreUoWAsync>();
                services.AddTransient <IAppDataSeeder, TDataSeeder>();
            })));
        }
Exemple #3
0
        protected override TestServer CreateServer()
        {
            IConfiguration config = ConfigurationProvider.BuildBearerConfiguration();

            return(new TestServer(new WebHostBuilder()
                                  .UseStartup <BookStoreApplication.Startup>()
                                  .UseConfiguration(config)
                                  .ConfigureTestServices((services) => {
                services.AddSingleton(provider => {
                    var bookStoreIdentityDbOptions = new DbContextOptionsBuilder <BookStoreIdentityDbContext>()
                                                     .UseInMemoryDatabase("IMBookStoreIdentity")
                                                     .Options;
                    var bookStoreIdentityDbContext = new BookStoreIdentityDbContext(bookStoreIdentityDbOptions, config);
                    bookStoreIdentityDbContext.Database.EnsureDeleted();
                    return bookStoreIdentityDbContext;
                });
                services.AddScoped <IBookStoreUnitOfWorkAsync, Mocks.MockBookStoreFaultyUnitOfWork>();
                services.AddTransient <IAppDataSeeder, TDataSeeder>();
            })));
        }