2017-06-08 17:33:55 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.ViewModel;
|
2017-06-09 12:16:57 +02:00
|
|
|
|
using Location = Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations;
|
|
|
|
|
using System.Collections.Generic;
|
2017-06-01 20:16:19 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xunit;
|
2017-06-12 20:18:11 +02:00
|
|
|
|
using System;
|
2017-06-01 20:16:19 +02:00
|
|
|
|
|
|
|
|
|
namespace IntegrationTests.Services.Locations
|
|
|
|
|
{
|
|
|
|
|
public class LocationsScenarios
|
|
|
|
|
: LocationsScenarioBase
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
2017-06-08 17:33:55 +02:00
|
|
|
|
public async Task Set_new_user_seattle_location_response_ok_status_code()
|
2017-06-01 20:16:19 +02:00
|
|
|
|
{
|
|
|
|
|
using (var server = CreateServer())
|
|
|
|
|
{
|
2017-06-13 18:00:09 +02:00
|
|
|
|
var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
2017-06-08 17:33:55 +02:00
|
|
|
|
var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json");
|
2017-06-01 20:16:19 +02:00
|
|
|
|
|
2017-06-09 12:16:57 +02:00
|
|
|
|
// Expected result
|
|
|
|
|
var expectedLocation = "SEAT";
|
|
|
|
|
|
|
|
|
|
// Act
|
2017-06-01 20:16:19 +02:00
|
|
|
|
var response = await server.CreateClient()
|
|
|
|
|
.PostAsync(Post.AddNewLocation, content);
|
|
|
|
|
|
2017-06-09 12:16:57 +02:00
|
|
|
|
var userLocationResponse = await server.CreateClient()
|
|
|
|
|
.GetAsync(Get.UserLocationBy(userId));
|
|
|
|
|
|
|
|
|
|
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
|
|
|
|
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
|
|
|
|
|
|
|
|
|
var locationResponse = await server.CreateClient()
|
|
|
|
|
.GetAsync(Get.LocationBy(userLocation.LocationId));
|
|
|
|
|
|
|
|
|
|
responseBody = await locationResponse.Content.ReadAsStringAsync();
|
|
|
|
|
var location = JsonConvert.DeserializeObject<Location>(responseBody);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.Equal(expectedLocation, location.Code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Set_new_user_readmond_location_response_ok_status_code()
|
|
|
|
|
{
|
|
|
|
|
using (var server = CreateServer())
|
|
|
|
|
{
|
2017-06-13 18:00:09 +02:00
|
|
|
|
var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
2017-06-09 12:16:57 +02:00
|
|
|
|
var content = new StringContent(BuildLocationsRequest(-122.119998, 47.690876), UTF8Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
|
|
|
// Expected result
|
|
|
|
|
var expectedLocation = "REDM";
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var response = await server.CreateClient()
|
|
|
|
|
.PostAsync(Post.AddNewLocation, content);
|
|
|
|
|
|
|
|
|
|
var userLocationResponse = await server.CreateClient()
|
|
|
|
|
.GetAsync(Get.UserLocationBy(userId));
|
|
|
|
|
|
|
|
|
|
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
|
|
|
|
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
|
|
|
|
|
|
|
|
|
var locationResponse = await server.CreateClient()
|
|
|
|
|
.GetAsync(Get.LocationBy(userLocation.LocationId));
|
|
|
|
|
|
|
|
|
|
responseBody = await locationResponse.Content.ReadAsStringAsync();
|
|
|
|
|
var location = JsonConvert.DeserializeObject<Location>(responseBody);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.Equal(expectedLocation, location.Code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Set_new_user_Washington_location_response_ok_status_code()
|
|
|
|
|
{
|
|
|
|
|
using (var server = CreateServer())
|
|
|
|
|
{
|
2017-06-13 18:00:09 +02:00
|
|
|
|
var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
2017-06-09 12:16:57 +02:00
|
|
|
|
var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
|
|
|
// Expected result
|
|
|
|
|
var expectedLocation = "WHT";
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var response = await server.CreateClient()
|
|
|
|
|
.PostAsync(Post.AddNewLocation, content);
|
2017-06-08 17:33:55 +02:00
|
|
|
|
|
|
|
|
|
var userLocationResponse = await server.CreateClient()
|
2017-06-09 12:16:57 +02:00
|
|
|
|
.GetAsync(Get.UserLocationBy(userId));
|
2017-06-08 17:33:55 +02:00
|
|
|
|
|
|
|
|
|
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
|
|
|
|
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
|
|
|
|
|
2017-06-09 12:16:57 +02:00
|
|
|
|
var locationResponse = await server.CreateClient()
|
|
|
|
|
.GetAsync(Get.LocationBy(userLocation.LocationId));
|
|
|
|
|
|
|
|
|
|
responseBody = await locationResponse.Content.ReadAsStringAsync();
|
|
|
|
|
var location = JsonConvert.DeserializeObject<Location>(responseBody);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.Equal(expectedLocation, location.Code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Get_all_locations_response_ok_status_code()
|
|
|
|
|
{
|
|
|
|
|
using (var server = CreateServer())
|
|
|
|
|
{
|
|
|
|
|
var response = await server.CreateClient()
|
|
|
|
|
.GetAsync(Get.Locations);
|
2017-06-08 17:33:55 +02:00
|
|
|
|
|
2017-06-09 12:16:57 +02:00
|
|
|
|
var responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var locations = JsonConvert.DeserializeObject<List<Location>>(responseBody);
|
2017-06-08 17:33:55 +02:00
|
|
|
|
|
2017-06-09 12:16:57 +02:00
|
|
|
|
// Assert
|
|
|
|
|
Assert.NotEmpty(locations);
|
2017-06-01 20:16:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-08 17:33:55 +02:00
|
|
|
|
string BuildLocationsRequest(double lon, double lat)
|
2017-06-01 20:16:19 +02:00
|
|
|
|
{
|
|
|
|
|
var location = new LocationRequest()
|
|
|
|
|
{
|
2017-06-08 17:33:55 +02:00
|
|
|
|
Longitude = lon,
|
|
|
|
|
Latitude = lat
|
|
|
|
|
};
|
2017-06-01 20:16:19 +02:00
|
|
|
|
return JsonConvert.SerializeObject(location);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|