public void SetUp()
        {
            string[] args = new string[0];

            TestDbContextFactory factory = new TestDbContextFactory();

            this.dbContext = factory.CreateDbContext(args);
            TestDbInitializer.Seed(this.dbContext);
        }
Exemplo n.º 2
0
        public TestServerFixture([NotNull] ITestOutputHelper output)
        {
            Output = output ?? throw new ArgumentNullException(nameof(output));

            _initialData   = new List <KeyValuePair <string, string> >();
            _configuration = new BehaviorSubject <IEnumerable <KeyValuePair <string, string> > >(_initialData);

            var hostBuilder = new HostBuilder()
                              .UseEnvironment("Development")
                              .UseContentRoot(Directory.GetCurrentDirectory())
                              .ConfigureAppConfiguration((hostingContext, builder) =>
            {
                builder
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .AddObservableConfiguration(_configuration);
            })
                              .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                              .ConfigureLogging(builder =>
            {
                builder.ClearProviders();
                builder.AddXunitLogger(Output);
                builder.AddInMemoryLogger(Logs);
            })
                              .ConfigureWebHost(builder =>
            {
                builder
                .UseStartup <TestStartup>()
                .BasedOn <Startup>()        //Internal extension to re set the correct ApplicationKey
                .UseTestServer();
            });

            Host   = hostBuilder.Start();
            Server = Host.GetTestServer();
            Client = Host.GetTestClient();

            using (var scope = Host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                TestDbInitializer.Seed(services, Output);

                var storageService = services.GetRequiredService <IStorageService>();
                Task.Run(async() => await storageService.CreateIfNotExistsAsync());
            }
        }
Exemplo n.º 3
0
        public TestServerFixture(ITestOutputHelper output)
        {
            Output = output;

            var hostBuilder = new HostBuilder()
                              .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                              .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddXunit(Output);
            })
                              .ConfigureWebHost(webHost =>
            {
                webHost
                .UseStartup <TestStartup>()
                .BasedOn <Startup>()        //Internal extension to re set the correct ApplicationKey
                .UseTestServer();
            });

            Host   = hostBuilder.Start();
            Server = Host.GetTestServer();
            Client = Host.GetTestClient();

            using (var scope = Host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    TestDbInitializer.Seed(services, Output);
                }
                catch (Exception ex)
                {
                    Output.WriteLine("HOST: " + ex.Message);
                }
            }
        }