diff --git a/src/Services/Location/Locations.API/Model/Core/LocationPoint.cs b/src/Services/Location/Locations.API/Model/Core/LocationPoint.cs new file mode 100644 index 000000000..48b6e32a7 --- /dev/null +++ b/src/Services/Location/Locations.API/Model/Core/LocationPoint.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Locations.API.Model.Core +{ + public class LocationPoint + { + public LocationPoint() + { + } + + public LocationPoint(double longitude, double latitude) + { + this.coordinates.Add(longitude); + this.coordinates.Add(latitude); + } + + public string type { get; private set; } = "Point"; + + public List coordinates { get; private set; } = new List(); + } +} diff --git a/src/Services/Location/Locations.API/Model/Core/LocationPolygon.cs b/src/Services/Location/Locations.API/Model/Core/LocationPolygon.cs new file mode 100644 index 000000000..18380cc79 --- /dev/null +++ b/src/Services/Location/Locations.API/Model/Core/LocationPolygon.cs @@ -0,0 +1,25 @@ +using MongoDB.Driver.GeoJsonObjectModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Locations.API.Model.Core +{ + public class LocationPolygon + { + public LocationPolygon() + { + } + + public LocationPolygon(List coordinatesList) + { + var coordinatesMapped = coordinatesList.Select(x => new List() { x.Longitude, x.Latitude }).ToList(); + this.coordinates.Add(coordinatesMapped); + } + + public string type { get; private set; } = "Polygon"; + + public List>> coordinates { get; private set; } = new List>>(); + } +} diff --git a/src/Services/Location/Locations.API/Model/Locations.cs b/src/Services/Location/Locations.API/Model/Locations.cs index 7c0580fc6..ba3dbe62c 100644 --- a/src/Services/Location/Locations.API/Model/Locations.cs +++ b/src/Services/Location/Locations.API/Model/Locations.cs @@ -1,5 +1,6 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Model { + using global::Locations.API.Model.Core; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver.GeoJsonObjectModel; @@ -17,8 +18,12 @@ public string Description { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } - public GeoJsonPoint Location { get; private set; } - public GeoJsonPolygon Polygon { get; private set; } + public LocationPoint Location { get; private set; } + public LocationPolygon 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); @@ -26,14 +31,12 @@ { Latitude = lat; Longitude = lon; - Location = new GeoJsonPoint( - new GeoJson2DGeographicCoordinates(lon, lat)); + Location = new LocationPoint(lon, lat); } private void SetPolygon(List coordinatesList) { - Polygon = new GeoJsonPolygon(new GeoJsonPolygonCoordinates( - new GeoJsonLinearRingCoordinates(coordinatesList))); + Polygon = new LocationPolygon(coordinatesList); } } } diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index 0a4e09b4e..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); @@ -154,7 +156,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { //loggerFactory.AddAzureWebAppDiagnostics(); //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); @@ -167,9 +169,9 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API app.UseCors("CorsPolicy"); + app.UseRouting(); ConfigureAuth(app); - app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); 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 dd1432b48..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 @@ -17,8 +17,7 @@ - - + @@ -26,7 +25,7 @@ all runtime; build; native; contentfiles; analyzers - + diff --git a/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs b/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs index d08f777fd..5f8c90dfd 100644 --- a/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs +++ b/src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs @@ -52,21 +52,24 @@ namespace Locations.FunctionalTests var userId = "4611ce3f-380d-4db5-8d76-87a8689058ed"; var content = new StringContent(BuildLocationsRequest(-122.119998, 47.690876), UTF8Encoding.UTF8, "application/json"); + var client = server.CreateClient(); + // 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 response = await client.PostAsync(Post.AddNewLocation, content); + + var userLocationResponse = await client.GetAsync(Get.UserLocationBy(userId)); + userLocationResponse.EnsureSuccessStatusCode(); var responseBody = await userLocationResponse.Content.ReadAsStringAsync(); var userLocation = JsonConvert.DeserializeObject(responseBody); - var locationResponse = await server.CreateClient() - .GetAsync(Get.LocationBy(userLocation.LocationId)); + Assert.NotNull(userLocation); + + var locationResponse = await client.GetAsync(Get.LocationBy(userLocation.LocationId)); responseBody = await locationResponse.Content.ReadAsStringAsync(); var location = JsonConvert.DeserializeObject(responseBody); 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 } diff --git a/src/_build/dependencies.props b/src/_build/dependencies.props index 18f81d6b3..7f81abf62 100644 --- a/src/_build/dependencies.props +++ b/src/_build/dependencies.props @@ -56,7 +56,7 @@ 1.0.0 2.2.0 3.0.0-preview6.19307.2 - 3.0.0-preview6.19307.2 + 3.0.0-preview7.19365.7 3.0.0-preview7.19365.7 3.0.0-preview7.19365.7 3.0.0-preview4-19123-01 @@ -80,10 +80,10 @@ 2.2.0 3.0.0-preview7.19362.4 16.0.1 - 2.5.0 - 2.5.0 - 2.5.0 - 2.5.0 + 2.9.0-beta2 + 2.9.0-beta2 + 2.9.0-beta2 + 2.9.0-beta2 4.10.1 12.0.2 12.0.1