public TelegramServiceTest() { // Prepare Database // _connectionSettings = TestHelper.GetConnectionSettings(); _migrationRunner = new MigrationRunner(_connectionSettings.BuildConnectionString()); _migrationRunner.RunMigrationsUp(); }
public YafControllerFullTest(ServiceAppTestFixture factory, ITestOutputHelper output) { factory.Output = output; _factory = factory; // Prepare Database // var config = _factory.Services.GetRequiredService <IConnectionSettings>(); _migrationRunner = new MigrationRunner(config.BuildConnectionString()); _migrationRunner.RunMigrationsUp(); // Mock web requests // var faceSettings = _factory.Services.GetRequiredService <FaceSettings>(); var openWeatherResponse = "{\"coord\":{\"lon\":-94.8,\"lat\":38.88},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"base\":\"stations\",\"main\":{\"temp\":4.28,\"feels_like\":0.13,\"temp_min\":3,\"temp_max\":5.56,\"pressure\":1034,\"humidity\":51},\"visibility\":16093,\"wind\":{\"speed\":2.21,\"deg\":169},\"clouds\":{\"all\":1},\"dt\":1584811457,\"sys\":{\"type\":1,\"id\":5188,\"country\":\"US\",\"sunrise\":1584793213,\"sunset\":1584837126},\"timezone\":-18000,\"id\":4276614,\"name\":\"Olathe\",\"cod\":200}"; var darkSkyResponse = "{\"currently\":{\"time\":1584864023,\"summary\":\"Possible Drizzle\",\"icon\":\"rain\",\"precipIntensity\":0.2386,\"precipProbability\":0.4,\"precipType\":\"rain\",\"temperature\":9.39,\"apparentTemperature\":8.3,\"dewPoint\":9.39,\"humidity\":1,\"pressure\":1010.8,\"windSpeed\":2.22,\"windGust\":3.63,\"windBearing\":71,\"cloudCover\":0.52,\"uvIndex\":1,\"visibility\":16.093,\"ozone\":391.9},\"offset\":1}"; var locationResponse = "{\"resourceSets\": [{\"resources\": [{\"name\": \"Olathe, KS\", \"address\": { \"adminDistrict\": \"KS\",\"adminDistrict2\": \"Johnson Co.\",\"countryRegion\": \"United States\",\"formattedAddress\": \"Olathe, KS\",\"locality\": \"Olathe\"}}]}]}"; var ccResponse = "{\"BTC_DKK\": 1.2}"; _lat = (decimal)38.855652; _lon = (decimal) - 94.799712; _handler = new Mock <HttpMessageHandler>(); _handler.SetupRequest(HttpMethod.Get, faceSettings.BuildOpenWeatherUrl(_lat, _lon)) .ReturnsResponse(openWeatherResponse, "application/json"); _handler.SetupRequest(HttpMethod.Get, faceSettings.BuildDarkSkyUrl(_lat, _lon, "test-key")) .ReturnsResponse(darkSkyResponse, "application/json"); _handler.SetupRequest(HttpMethod.Get, faceSettings.BuildDarkSkyUrl(_lat, _lon, "wrong-key")) .ReturnsResponse(HttpStatusCode.Unauthorized); _handler.SetupRequest(HttpMethod.Get, faceSettings.BuildLocationUrl(_lat, _lon)) .ReturnsResponse(locationResponse, "application/json"); _handler.SetupRequest(HttpMethod.Get, faceSettings.BuildOpenWeatherUrl(0, 0)) .ReturnsResponse(HttpStatusCode.BadRequest); _handler.SetupRequest(HttpMethod.Get, faceSettings.BuildCurrencyConverterUrl("BTC", "DKK")) .ReturnsResponse(ccResponse, "application/json"); var httpFactory = _handler.CreateClientFactory(); // Set Mock services on DI // _client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { services.AddSingleton(_ => httpFactory); }); }) .CreateClient(); }