Ejemplo n.º 1
0
        public IntegrationTest()
        {
            string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
            // TODO :  better way to get app path?
            var    parent = Directory.GetParent(wanted_path).Parent;
            string envdb  = Environment.GetEnvironmentVariable("MYSQL_DB");

            var webhost = new WebHostBuilder();

            if (!String.IsNullOrEmpty(envdb))
            {
                webhost.ConfigureTestServices(services => {
                    services.AddDbContext <ApplicationDbContext> (options => options.UseMySql(envdb));
                });
            }
            else
            {
                IConfigurationRoot configuration = new ConfigurationBuilder()
                                                   .SetBasePath(parent.ToString())
                                                   .AddJsonFile("app/appsettings.json")
                                                   .Build();
                webhost.UseConfiguration(configuration);
            }
            _client = new TestServer(webhost.UseStartup <Startup>()).CreateClient();
        }
        public override void Initialize()
        {
            appService = new Mock <IUsuarioAppService>();

            webHostBuilder = new WebHostBuilder();
            webHostBuilder.ConfigureTestServices(service => service.AddScoped(serviceProvider => appService.Object)).UseStartup <Startup>();
        }
        public TestClientProvider(IProvideTheName nameProvider)
        {
            var webHostBuilder = new WebHostBuilder();

            webHostBuilder.ConfigureTestServices(services => { services.AddSingleton(nameProvider); });

            var server = new TestServer(webHostBuilder.UseStartup <Startup>());

            Client = server.CreateClient();
        }
        public static TestServer Create(Action <IServiceCollection> services)
        {
            var webHostBuilder = new WebHostBuilder()
                                 .UseStartup <Startup>();

            if (services != null)
            {
                webHostBuilder.ConfigureTestServices(services);
            }

            return(new TestServer(webHostBuilder));
        }
        public void Setup()
        {
            _memoryStream = new MemoryStream();
            _db           = new LiteDatabase(_memoryStream);

            var builder = new WebHostBuilder().UseStartup <Startup>();

            builder.ConfigureTestServices(services =>
            {
                services.AddTransient(_ => _db);
            });
            _server = new TestServer(builder);
            _client = _server.CreateClient();
        }
Ejemplo n.º 6
0
        private HttpClient ArrangeClient()
        {
            var webHostBuilder = new WebHostBuilder();

            webHostBuilder
            .ConfigureTestServices(services =>
            {
                services.AddSingleton(_ => _retriever.Object);
            })
            .UseStartup <Startup>();

            var testServer = new TestServer(webHostBuilder);

            return(testServer.CreateClient());
        }
Ejemplo n.º 7
0
        public void Given()
        {
            BookingRepository = Substitute.For <IBookingRepository>();
            CarRepository     = Substitute.For <ICarRepository>();

            var webHostBuilder = new WebHostBuilder().UseStartup <Startup>();

            webHostBuilder.ConfigureTestServices(services =>
            {
                services.AddTransient(c => BookingRepository);
                services.AddTransient(c => CarRepository);
            });

            TestServer = new TestServer(webHostBuilder);
            HttpClient = TestServer.CreateClient();
        }
Ejemplo n.º 8
0
        public ExchangeControllerTests()
        {
            _requestBuilder = new Mock <IBuildExchangeRequests>();
            _calculator     = new Mock <ICalculateExchangeRates>();
            _retriever      = new Mock <IRetrieveExchangeRates>();

            var webHostBuilder = new WebHostBuilder();

            webHostBuilder
            .ConfigureTestServices(services =>
            {
                services.AddTransient(_ => _requestBuilder.Object);
                services.AddTransient(_ => _calculator.Object);
            })
            .UseStartup <Startup>();

            var testServer = new TestServer(webHostBuilder);

            _client = testServer.CreateClient();
        }
Ejemplo n.º 9
0
        public ApiFilterUnitTests()
        {
            var projectDir = Directory.GetCurrentDirectory();
            var configPath = Path.Combine(projectDir, "appsettings.json");

            var webhostBuilder = new WebHostBuilder();

            webhostBuilder.ConfigureAppConfiguration((context, conf) =>
            {
                conf.AddJsonFile(configPath);
            });
            webhostBuilder.UseStartup <Startup>();
            webhostBuilder.ConfigureTestServices(config =>
            {
                config.AddSingleton <IMockyService>(new MockProductClient());
            });

            var server = new TestServer(webhostBuilder);

            Client = server.CreateClient();
        }
Ejemplo n.º 10
0
        public ApiFixture()
        {
            DatabaseSettings = new PriceStoreDatabaseSettings
            {
                PricesCollectionName = "Prices",
                ConnectionString     = "mongodb://localhost:27017",
                DatabaseName         = "MyRetailDb_Test"
            };

            var client   = new MongoClient(DatabaseSettings.ConnectionString);
            var database = client.GetDatabase(DatabaseSettings.DatabaseName);

            Prices = database.GetCollection <DbPrice>(DatabaseSettings.PricesCollectionName);

            var builder = new WebHostBuilder()
                          .UseStartup <Startup>();

            builder.ConfigureTestServices(services =>
            {
                services.AddSingleton(DatabaseSettings);
            });

            Server = new TestServer(builder);
        }