public async Task SaveDbShouldCorrectlyGetDataFromQuery() { // Arrange // var connectionSettings = _factory.Services.GetRequiredService <IConnectionSettings>(); var dbConnection = new DataConnectionFactory(connectionSettings.GetDataProvider(), connectionSettings.BuildConnectionString()) .Create(); var dataProvider = new PostgresDataProvider( TestHelper.GetLoggerMock <PostgresDataProvider>().Object, new DataConnectionFactory(connectionSettings), MapperConfig.CreateMapper(), null); var watchRequest = new WatchRequest { DeviceId = "device-id", DeviceName = "device-name", Version = "version", CiqVersion = "ciq-version", Framework = "framework", WeatherProvider = "weather-provider", DarkskyKey = "dark-key", Lat = (decimal)1.1, Lon = (decimal)2.2, BaseCurrency = "USD", TargetCurrency = "EUR" }; // Act // await dataProvider.SaveRequestInfo(watchRequest, new WeatherInfo { WindSpeed = (decimal)5.5, Temperature = (decimal)4.4 }, new LocationInfo { CityName = "city-name" }, new ExchangeRateInfo { ExchangeRate = (decimal)3.3 }); // Assert // var actualDevice = await dbConnection.GetTable <DeviceData>().SingleAsync(d => d.DeviceId == watchRequest.DeviceId); var actualRequest = await dbConnection.GetTable <RequestData>().SingleAsync(r => r.DeviceDataId == actualDevice.Id); Assert.Equal("device-name", actualDevice.DeviceName); Assert.Equal("device-id", actualDevice.DeviceId); Assert.Equal(watchRequest.Framework, actualRequest.Framework); Assert.Equal(watchRequest.CiqVersion, actualRequest.CiqVersion); Assert.Equal(watchRequest.Version, actualRequest.Version); Assert.Equal(watchRequest.Lon, actualRequest.Lon); Assert.Equal(watchRequest.Lat, actualRequest.Lat); Assert.Equal(watchRequest.BaseCurrency, actualRequest.BaseCurrency); Assert.Equal(watchRequest.TargetCurrency, actualRequest.TargetCurrency); Assert.Equal((decimal)4.4, actualRequest.Temperature); Assert.Equal("city-name", actualRequest.CityName); Assert.Equal((decimal)3.3, actualRequest.ExchangeRate); }
public async Task RoutesRequestShouldReturnRoutes(string baseUrl) { // Arrange // var time = DateTime.Now; var connectionSettings = _factory.Services.GetRequiredService <IConnectionSettings>(); var dbConnection = new DataConnectionFactory(connectionSettings.GetDataProvider(), connectionSettings.BuildConnectionString()) .Create(); var publicId = "testiddd"; var yasUser = new YasUser { PublicId = publicId, TelegramId = 0 }; var userId = await dbConnection.GetTable <YasUser>().DataContext.InsertWithInt64IdentityAsync(yasUser); var yasRoute = new YasRoute { RouteName = "test-name", UserId = userId, UploadTime = time.ToUniversalTime() }; var routeId = await dbConnection.GetTable <YasRoute>().DataContext.InsertWithInt64IdentityAsync(yasRoute); var wayPoint = new YasWaypoint { Latitude = 1, Longitude = 2, Name = "wp-1", OrderId = 0, RouteId = routeId }; await dbConnection.GetTable <YasWaypoint>().DataContext.InsertWithInt64IdentityAsync(wayPoint); var faceSetting = _factory.Services.GetRequiredService <FaceSettings>(); var url = $"{baseUrl}{publicId}"; // Act // var response = await _client.GetAsync(url); // Assert // response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); var expected = "[{\"routeId\":1,\"userId\":1,\"RouteName\":\"test-name\",\"RouteDate\":\"" + time.ToString("yyyy-MM-ddTHH\\:mm\\:ss.FFFFFFzzz") + "\",\"WayPoints\":[{\"waypointId\":1,\"routeId\":1,\"name\":\"wp-1\",\"Lat\":1,\"Lon\":2}]}]"; Assert.Equal(expected, result); }
public async void RequestToDarkSkyAndCurrencyShouldStoredInDatabase() { // Arrange // var deviceId = "test-device21"; var faceSetting = _factory.Services.GetRequiredService <FaceSettings>(); var url = $"/api/v2/YAFace?apiToken={faceSetting.AuthSettings.Token}&lat={_lat}&lon={_lon}&did={deviceId}&av=0.9.204&fw=5.0&ciqv=3.1.6&dn=unknown&wapiKey=test-key&wp=DarkSky&bc=BTC&tc=DKK"; var connectionSettings = _factory.Services.GetRequiredService <IConnectionSettings>(); var dbConnection = new DataConnectionFactory(connectionSettings.GetDataProvider(), connectionSettings.BuildConnectionString()) .Create(); // Act // var response = await _client.GetAsync(url); // Assert // response.EnsureSuccessStatusCode(); var actualDevice = await dbConnection.GetTable <DeviceData>().SingleAsync(d => d.DeviceId == deviceId); var actualRequest = await dbConnection.GetTable <RequestData>().SingleAsync(r => r.DeviceDataId == actualDevice.Id); Assert.Equal("unknown", actualDevice.DeviceName); Assert.Equal(deviceId, actualDevice.DeviceId); Assert.Equal("5.0", actualRequest.Framework); Assert.Equal("3.1.6", actualRequest.CiqVersion); Assert.Equal("0.9.204", actualRequest.Version); Assert.Equal(_lon, actualRequest.Lon); Assert.Equal(_lat, actualRequest.Lat); Assert.Equal("BTC", actualRequest.BaseCurrency); Assert.Equal("DKK", actualRequest.TargetCurrency); Assert.Equal((decimal)9.39, actualRequest.Temperature); Assert.Equal((decimal)2.22, actualRequest.WindSpeed); Assert.Equal((decimal)0.4, actualRequest.PrecipProbability); Assert.Equal("Olathe, KS", actualRequest.CityName); Assert.Equal((decimal)1.2, actualRequest.ExchangeRate); _handler.VerifyRequest(HttpMethod.Get, _ => _.RequestUri.Host.Contains("free.currconv.com"), Times.Once()); _handler.VerifyRequest(HttpMethod.Get, _ => _.RequestUri.Host.Contains("api.darksky.net"), Times.Once()); _handler.VerifyRequest(HttpMethod.Get, _ => _.RequestUri.Host.Contains("dev.virtualearth.net"), Times.Once()); _handler.VerifyRequest(HttpMethod.Get, _ => _.RequestUri.Host.Contains("api.openweathermap.org"), Times.Never()); }