Browse Source

partial checkin

features/migration-dotnet3
ericuss 5 years ago
parent
commit
4d8f3cba65
7 changed files with 145 additions and 93 deletions
  1. +24
    -0
      src/Services/Location/Locations.API/Model/Core/LocationPoint.cs
  2. +25
    -0
      src/Services/Location/Locations.API/Model/Core/LocationPolygon.cs
  3. +7
    -6
      src/Services/Location/Locations.API/Model/Locations.cs
  4. +3
    -3
      src/Services/Location/Locations.API/Startup.cs
  5. +2
    -3
      src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj
  6. +79
    -76
      src/Services/Location/Locations.FunctionalTests/LocationsScenarios.cs
  7. +5
    -5
      src/_build/dependencies.props

+ 24
- 0
src/Services/Location/Locations.API/Model/Core/LocationPoint.cs View File

@ -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<double> coordinates { get; private set; } = new List<double>();
}
}

+ 25
- 0
src/Services/Location/Locations.API/Model/Core/LocationPolygon.cs View File

@ -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<GeoJson2DGeographicCoordinates> coordinatesList)
{
var coordinatesMapped = coordinatesList.Select(x => new List<double>() { x.Longitude, x.Latitude }).ToList();
this.coordinates.Add(coordinatesMapped);
}
public string type { get; private set; } = "Polygon";
public List<List<List<double>>> coordinates { get; private set; } = new List<List<List<double>>>();
}
}

+ 7
- 6
src/Services/Location/Locations.API/Model/Locations.cs View File

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

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

@ -154,7 +154,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,10 +167,9 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
app.UseCors("CorsPolicy");
app.UseRouting();
ConfigureAuth(app);
app.UseAuthorization();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
@ -230,6 +229,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
}
app.UseAuthentication();
app.UseAuthorization();
}
private void RegisterEventBus(IServiceCollection services)


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

@ -17,8 +17,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(Microsoft_AspNetCore_Mvc_Testing)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(Microsoft_NET_Test_Sdk)" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(Microsoft_AspNetCore_TestHost)" />
<PackageReference Include="xunit" Version="$(xunit)" />
@ -26,7 +25,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>


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

@ -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()
@ -52,53 +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 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 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";
var response = await client.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 client.GetAsync(Get.UserLocationBy(userId));
userLocationResponse.EnsureSuccessStatusCode();
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
var userLocation = JsonConvert.DeserializeObject<UserLocation>(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<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>(responseBody);
@ -108,21 +79,53 @@ namespace Locations.FunctionalTests
}
}
[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)
{


+ 5
- 5
src/_build/dependencies.props View File

@ -56,7 +56,7 @@
<Microsoft_AspNetCore_HealthChecks>1.0.0</Microsoft_AspNetCore_HealthChecks>
<Microsoft_AspNetCore_Http_Abstractions>2.2.0</Microsoft_AspNetCore_Http_Abstractions>
<Microsoft_AspNetCore_Mvc_Testing>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Mvc_Testing>
<Microsoft_AspNetCore_TestHost>3.0.0-preview6.19307.2</Microsoft_AspNetCore_TestHost>
<Microsoft_AspNetCore_TestHost>3.0.0-preview7.19365.7</Microsoft_AspNetCore_TestHost>
<Microsoft_AspNetCore_Identity_EntityFrameworkCore>3.0.0-preview7.19365.7</Microsoft_AspNetCore_Identity_EntityFrameworkCore>
<Microsoft_AspNetCore_Diagnostics_EntityFrameworkCore>3.0.0-preview7.19365.7</Microsoft_AspNetCore_Diagnostics_EntityFrameworkCore>
<Microsoft_AspNetCore_Hosting_Abstractions>3.0.0-preview4-19123-01</Microsoft_AspNetCore_Hosting_Abstractions>
@ -80,10 +80,10 @@
<Microsoft_Extensions_Logging>2.2.0</Microsoft_Extensions_Logging>
<Microsoft_Extensions_Logging_AzureAppServices>3.0.0-preview7.19362.4</Microsoft_Extensions_Logging_AzureAppServices>
<Microsoft_NET_Test_Sdk>16.0.1</Microsoft_NET_Test_Sdk>
<mongocsharpdriver>2.5.0</mongocsharpdriver>
<MongoDB_Bson>2.5.0</MongoDB_Bson>
<MongoDB_Driver>2.5.0</MongoDB_Driver>
<MongoDB_Driver_Core>2.5.0</MongoDB_Driver_Core>
<mongocsharpdriver>2.9.0-beta2</mongocsharpdriver>
<MongoDB_Bson>2.9.0-beta2</MongoDB_Bson>
<MongoDB_Driver>2.9.0-beta2</MongoDB_Driver>
<MongoDB_Driver_Core>2.9.0-beta2</MongoDB_Driver_Core>
<Moq>4.10.1</Moq>
<Newtonsoft_Json>12.0.2</Newtonsoft_Json>
<Ocelot>12.0.1</Ocelot>


Loading…
Cancel
Save