Browse Source

Migrate locations.functionaltest to 3.0

features/migration-dotnet3
ericuss 5 years ago
parent
commit
de36e8c09e
6 changed files with 97 additions and 81 deletions
  1. +4
    -2
      src/Services/Location/Locations.API/Model/Locations.cs
  2. +7
    -5
      src/Services/Location/Locations.API/Startup.cs
  3. +12
    -1
      src/Services/Location/Locations.FunctionalTests/LocationTestsStartup.cs
  4. +1
    -1
      src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj
  5. +71
    -71
      src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs
  6. +2
    -1
      src/Services/Location/Locations.FunctionalTests/appsettings.json

+ 4
- 2
src/Services/Location/Locations.API/Model/Locations.cs View File

@ -18,10 +18,12 @@
public string Description { get; set; } public string Description { get; set; }
public double Latitude { get; set; } public double Latitude { get; set; }
public double Longitude { get; set; } public double Longitude { get; set; }
//public GeoJsonPoint<GeoJson2DGeographicCoordinates> Location { get; private set; }
public LocationPoint Location { get; private set; } public LocationPoint Location { get; private set; }
public LocationPolygon Polygon { 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 SetLocation(double lon, double lat) => SetPosition(lon, lat);
public void SetArea(List<GeoJson2DGeographicCoordinates> coordinatesList) => SetPolygon(coordinatesList); public void SetArea(List<GeoJson2DGeographicCoordinates> coordinatesList) => SetPolygon(coordinatesList);


+ 7
- 5
src/Services/Location/Locations.API/Startup.cs View File

@ -1,6 +1,7 @@
using Autofac; using Autofac;
using Autofac.Extensions.DependencyInjection; using Autofac.Extensions.DependencyInjection;
using HealthChecks.UI.Client; using HealthChecks.UI.Client;
using Locations.API.Controllers;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Diagnostics.HealthChecks;
@ -37,17 +38,18 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
public IServiceProvider ConfigureServices(IServiceCollection services)
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{ {
RegisterAppInsights(services); RegisterAppInsights(services);
services.AddCustomHealthCheck(Configuration); services.AddCustomHealthCheck(Configuration);
services.AddControllers(options => services.AddControllers(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddNewtonsoftJson();
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.AddApplicationPart(typeof(LocationsController).Assembly)
.AddNewtonsoftJson();
ConfigureAuthService(services); ConfigureAuthService(services);


+ 12
- 1
src/Services/Location/Locations.FunctionalTests/LocationTestsStartup.cs View File

@ -1,7 +1,11 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.eShopOnContainers.Services.Locations.API; using Microsoft.eShopOnContainers.Services.Locations.API;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; 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) protected override void ConfigureAuth(IApplicationBuilder app)
{ {
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant()) if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())


+ 1
- 1
src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(NetCoreTargetVersion)</TargetFramework> <TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>


+ 71
- 71
src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs View File

@ -12,37 +12,37 @@ namespace Locations.FunctionalTests
public class LocationsScenarios public class LocationsScenarios
: LocationsScenarioBase : 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] [Fact]
public async Task Set_new_user_readmond_location_response_ok_status_code() 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");
// // Expected result
// var expectedLocation = "WHT";
// // 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<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(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);
// var responseBody = await response.Content.ReadAsStringAsync();
// var locations = JsonConvert.DeserializeObject<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>(responseBody);
// // Assert
// Assert.NotEmpty(locations);
// }
//}
[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";
// 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<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(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);
var responseBody = await response.Content.ReadAsStringAsync();
var locations = JsonConvert.DeserializeObject<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>(responseBody);
// Assert
Assert.NotEmpty(locations);
}
}
string BuildLocationsRequest(double lon, double lat) string BuildLocationsRequest(double lon, double lat)
{ {


+ 2
- 1
src/Services/Location/Locations.FunctionalTests/appsettings.json View File

@ -5,5 +5,6 @@
"IdentityUrl": "http://localhost:5105", "IdentityUrl": "http://localhost:5105",
"isTest": "true", "isTest": "true",
"EventBusConnection": "localhost", "EventBusConnection": "localhost",
"SubscriptionClientName": "Locations"
"SubscriptionClientName": "Locations",
"SuppressCheckForUnhandledSecurityMetadata":true
} }

Loading…
Cancel
Save