diff --git a/src/Services/Location/Locations.API/Model/Locations.cs b/src/Services/Location/Locations.API/Model/Locations.cs index ae6672345..ba3dbe62c 100644 --- a/src/Services/Location/Locations.API/Model/Locations.cs +++ b/src/Services/Location/Locations.API/Model/Locations.cs @@ -18,10 +18,12 @@ public string Description { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } - //public GeoJsonPoint Location { get; private set; } public LocationPoint Location { get; private set; } public LocationPolygon Polygon { get; private set; } - //public GeoJsonPolygon Polygon { get; private set; } + + // Temporal commented in previewVersion7 of netcore and 2.9.0-beta2 of Mongo packages, review in next versions + // public GeoJsonPoint Location { get; private set; } + // public GeoJsonPolygon Polygon { get; private set; } public void SetLocation(double lon, double lat) => SetPosition(lon, lat); public void SetArea(List coordinatesList) => SetPolygon(coordinatesList); diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index 3620da209..5deaae52d 100644 --- a/src/Services/Location/Locations.API/Startup.cs +++ b/src/Services/Location/Locations.API/Startup.cs @@ -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); diff --git a/src/Services/Location/Locations.FunctionalTests/LocationTestsStartup.cs b/src/Services/Location/Locations.FunctionalTests/LocationTestsStartup.cs index 21d0814a0..08bf2ffa5 100644 --- a/src/Services/Location/Locations.FunctionalTests/LocationTestsStartup.cs +++ b/src/Services/Location/Locations.FunctionalTests/LocationTestsStartup.cs @@ -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(Configuration); + return base.ConfigureServices(services); + } protected override void ConfigureAuth(IApplicationBuilder app) { if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant()) diff --git a/src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj b/src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj index 788f44ede..8b60d0001 100644 --- a/src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj +++ b/src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj @@ -2,7 +2,7 @@ $(NetCoreTargetVersion) - + false false diff --git a/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs b/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs index 6e625a257..5f8c90dfd 100644 --- a/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs +++ b/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs @@ -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(responseBody); + var responseBody = await userLocationResponse.Content.ReadAsStringAsync(); + var userLocation = JsonConvert.DeserializeObject(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(responseBody); + responseBody = await locationResponse.Content.ReadAsStringAsync(); + var location = JsonConvert.DeserializeObject(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"); - - // // 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(responseBody); - - // var locationResponse = await server.CreateClient() - // .GetAsync(Get.LocationBy(userLocation.LocationId)); - - // responseBody = await locationResponse.Content.ReadAsStringAsync(); - // var location = JsonConvert.DeserializeObject(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>(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(responseBody); + + var locationResponse = await server.CreateClient() + .GetAsync(Get.LocationBy(userLocation.LocationId)); + + responseBody = await locationResponse.Content.ReadAsStringAsync(); + var location = JsonConvert.DeserializeObject(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>(responseBody); + + // Assert + Assert.NotEmpty(locations); + } + } string BuildLocationsRequest(double lon, double lat) { diff --git a/src/Services/Location/Locations.FunctionalTests/appsettings.json b/src/Services/Location/Locations.FunctionalTests/appsettings.json index 398cd54c0..6880b2ee1 100644 --- a/src/Services/Location/Locations.FunctionalTests/appsettings.json +++ b/src/Services/Location/Locations.FunctionalTests/appsettings.json @@ -5,5 +5,6 @@ "IdentityUrl": "http://localhost:5105", "isTest": "true", "EventBusConnection": "localhost", - "SubscriptionClientName": "Locations" + "SubscriptionClientName": "Locations", + "SuppressCheckForUnhandledSecurityMetadata":true }