Migrate locations.functionaltest to 3.0
This commit is contained in:
parent
4d8f3cba65
commit
de36e8c09e
@ -18,10 +18,12 @@
|
||||
public string Description { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
//public GeoJsonPoint<GeoJson2DGeographicCoordinates> Location { get; private set; }
|
||||
public LocationPoint Location { get; private set; }
|
||||
public LocationPolygon Polygon { get; private set; }
|
||||
//public GeoJsonPolygon<GeoJson2DGeographicCoordinates> Polygon { get; private set; }
|
||||
|
||||
// Temporal commented in previewVersion7 of netcore and 2.9.0-beta2 of Mongo packages, review in next versions
|
||||
// public GeoJsonPoint<GeoJson2DGeographicCoordinates> Location { get; private set; }
|
||||
// public GeoJsonPolygon<GeoJson2DGeographicCoordinates> Polygon { get; private set; }
|
||||
public void SetLocation(double lon, double lat) => SetPosition(lon, lat);
|
||||
public void SetArea(List<GeoJson2DGeographicCoordinates> coordinatesList) => SetPolygon(coordinatesList);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using HealthChecks.UI.Client;
|
||||
using Locations.API.Controllers;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
@ -37,17 +38,18 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
RegisterAppInsights(services);
|
||||
|
||||
services.AddCustomHealthCheck(Configuration);
|
||||
|
||||
services.AddControllers(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||
|
||||
}).AddNewtonsoftJson();
|
||||
{
|
||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||
})
|
||||
.AddApplicationPart(typeof(LocationsController).Assembly)
|
||||
.AddNewtonsoftJson();
|
||||
|
||||
ConfigureAuthService(services);
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -13,6 +17,13 @@ namespace Locations.FunctionalTests
|
||||
{
|
||||
}
|
||||
|
||||
public override IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Added to avoid the Authorize data annotation in test environment.
|
||||
// Property "SuppressCheckForUnhandledSecurityMetadata" in appsettings.json
|
||||
services.Configure<RouteOptions>(Configuration);
|
||||
return base.ConfigureServices(services);
|
||||
}
|
||||
protected override void ConfigureAuth(IApplicationBuilder app)
|
||||
{
|
||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
|
||||
|
||||
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -12,37 +12,37 @@ namespace Locations.FunctionalTests
|
||||
public class LocationsScenarios
|
||||
: LocationsScenarioBase
|
||||
{
|
||||
//[Fact]
|
||||
//public async Task Set_new_user_seattle_location_response_ok_status_code()
|
||||
//{
|
||||
// using (var server = CreateServer())
|
||||
// {
|
||||
// var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
||||
// var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json");
|
||||
[Fact]
|
||||
public async Task Set_new_user_seattle_location_response_ok_status_code()
|
||||
{
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
||||
var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json");
|
||||
|
||||
// // Expected result
|
||||
// var expectedLocation = "SEAT";
|
||||
// Expected result
|
||||
var expectedLocation = "SEAT";
|
||||
|
||||
// // Act
|
||||
// var response = await server.CreateClient()
|
||||
// .PostAsync(Post.AddNewLocation, content);
|
||||
// Act
|
||||
var response = await server.CreateClient()
|
||||
.PostAsync(Post.AddNewLocation, content);
|
||||
|
||||
// var userLocationResponse = await server.CreateClient()
|
||||
// .GetAsync(Get.UserLocationBy(userId));
|
||||
var userLocationResponse = await server.CreateClient()
|
||||
.GetAsync(Get.UserLocationBy(userId));
|
||||
|
||||
// var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
||||
// var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
||||
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
||||
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
||||
|
||||
// var locationResponse = await server.CreateClient()
|
||||
// .GetAsync(Get.LocationBy(userLocation.LocationId));
|
||||
var locationResponse = await server.CreateClient()
|
||||
.GetAsync(Get.LocationBy(userLocation.LocationId));
|
||||
|
||||
// responseBody = await locationResponse.Content.ReadAsStringAsync();
|
||||
// var location = JsonConvert.DeserializeObject<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(responseBody);
|
||||
responseBody = await locationResponse.Content.ReadAsStringAsync();
|
||||
var location = JsonConvert.DeserializeObject<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(responseBody);
|
||||
|
||||
// // Assert
|
||||
// Assert.Equal(expectedLocation, location.Code);
|
||||
// }
|
||||
//}
|
||||
// Assert
|
||||
Assert.Equal(expectedLocation, location.Code);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Set_new_user_readmond_location_response_ok_status_code()
|
||||
@ -79,53 +79,53 @@ namespace Locations.FunctionalTests
|
||||
}
|
||||
}
|
||||
|
||||
//[Fact]
|
||||
//public async Task Set_new_user_Washington_location_response_ok_status_code()
|
||||
//{
|
||||
// using (var server = CreateServer())
|
||||
// {
|
||||
// var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
||||
// var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json");
|
||||
[Fact]
|
||||
public async Task Set_new_user_Washington_location_response_ok_status_code()
|
||||
{
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed";
|
||||
var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json");
|
||||
|
||||
// // Expected result
|
||||
// var expectedLocation = "WHT";
|
||||
// Expected result
|
||||
var expectedLocation = "WHT";
|
||||
|
||||
// // Act
|
||||
// var response = await server.CreateClient()
|
||||
// .PostAsync(Post.AddNewLocation, content);
|
||||
// Act
|
||||
var response = await server.CreateClient()
|
||||
.PostAsync(Post.AddNewLocation, content);
|
||||
|
||||
// var userLocationResponse = await server.CreateClient()
|
||||
// .GetAsync(Get.UserLocationBy(userId));
|
||||
var userLocationResponse = await server.CreateClient()
|
||||
.GetAsync(Get.UserLocationBy(userId));
|
||||
|
||||
// var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
||||
// var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
||||
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
||||
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
||||
|
||||
// var locationResponse = await server.CreateClient()
|
||||
// .GetAsync(Get.LocationBy(userLocation.LocationId));
|
||||
var locationResponse = await server.CreateClient()
|
||||
.GetAsync(Get.LocationBy(userLocation.LocationId));
|
||||
|
||||
// responseBody = await locationResponse.Content.ReadAsStringAsync();
|
||||
// var location = JsonConvert.DeserializeObject<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(responseBody);
|
||||
responseBody = await locationResponse.Content.ReadAsStringAsync();
|
||||
var location = JsonConvert.DeserializeObject<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(responseBody);
|
||||
|
||||
// // Assert
|
||||
// Assert.Equal(expectedLocation, location.Code);
|
||||
// }
|
||||
//}
|
||||
// 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);
|
||||
[Fact]
|
||||
public async Task Get_all_locations_response_ok_status_code()
|
||||
{
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var response = await server.CreateClient()
|
||||
.GetAsync(Get.Locations);
|
||||
|
||||
// var responseBody = await response.Content.ReadAsStringAsync();
|
||||
// var locations = JsonConvert.DeserializeObject<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>(responseBody);
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
var locations = JsonConvert.DeserializeObject<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>(responseBody);
|
||||
|
||||
// // Assert
|
||||
// Assert.NotEmpty(locations);
|
||||
// }
|
||||
//}
|
||||
// Assert
|
||||
Assert.NotEmpty(locations);
|
||||
}
|
||||
}
|
||||
|
||||
string BuildLocationsRequest(double lon, double lat)
|
||||
{
|
||||
|
@ -5,5 +5,6 @@
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"isTest": "true",
|
||||
"EventBusConnection": "localhost",
|
||||
"SubscriptionClientName": "Locations"
|
||||
"SubscriptionClientName": "Locations",
|
||||
"SuppressCheckForUnhandledSecurityMetadata":true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user