From c9484a0834b5294dde7add874b809ea3a19798c5 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Mon, 12 Jun 2017 20:18:11 +0200 Subject: [PATCH] Modify test. UserId is a Guid type --- .../Locations/LocationsScenarioBase.cs | 2 +- .../Services/Locations/LocationsScenarios.cs | 7 +++--- .../Locations/LocationsTestsStartup.cs | 22 ++++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/test/Services/IntegrationTests/Services/Locations/LocationsScenarioBase.cs b/test/Services/IntegrationTests/Services/Locations/LocationsScenarioBase.cs index be3b23803..e74781e63 100644 --- a/test/Services/IntegrationTests/Services/Locations/LocationsScenarioBase.cs +++ b/test/Services/IntegrationTests/Services/Locations/LocationsScenarioBase.cs @@ -27,7 +27,7 @@ namespace IntegrationTests.Services.Locations return $"api/v1/locations/{id}"; } - public static string UserLocationBy(int id) + public static string UserLocationBy(Guid id) { return $"api/v1/locations/user/{id}"; } diff --git a/test/Services/IntegrationTests/Services/Locations/LocationsScenarios.cs b/test/Services/IntegrationTests/Services/Locations/LocationsScenarios.cs index 63437e7dc..ae69219f5 100644 --- a/test/Services/IntegrationTests/Services/Locations/LocationsScenarios.cs +++ b/test/Services/IntegrationTests/Services/Locations/LocationsScenarios.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Xunit; +using System; namespace IntegrationTests.Services.Locations { @@ -18,7 +19,7 @@ namespace IntegrationTests.Services.Locations { using (var server = CreateServer()) { - var userId = 1234; + var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed"); var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json"); // Expected result @@ -50,7 +51,7 @@ namespace IntegrationTests.Services.Locations { using (var server = CreateServer()) { - var userId = 1234; + var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed"); var content = new StringContent(BuildLocationsRequest(-122.119998, 47.690876), UTF8Encoding.UTF8, "application/json"); // Expected result @@ -82,7 +83,7 @@ namespace IntegrationTests.Services.Locations { using (var server = CreateServer()) { - var userId = 1234; + var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed"); var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json"); // Expected result diff --git a/test/Services/IntegrationTests/Services/Locations/LocationsTestsStartup.cs b/test/Services/IntegrationTests/Services/Locations/LocationsTestsStartup.cs index 0e622d854..28a51456b 100644 --- a/test/Services/IntegrationTests/Services/Locations/LocationsTestsStartup.cs +++ b/test/Services/IntegrationTests/Services/Locations/LocationsTestsStartup.cs @@ -3,7 +3,10 @@ using IntegrationTests.Middleware; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; using Microsoft.eShopOnContainers.Services.Locations.API; + using System.Security.Claims; + using System.Threading.Tasks; public class LocationsTestsStartup : Startup { @@ -15,12 +18,29 @@ { if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant()) { - app.UseMiddleware(); + app.UseMiddleware(); } else { base.ConfigureAuth(app); } } + + class LocationAuthorizeMiddleware + { + private readonly RequestDelegate _next; + public LocationAuthorizeMiddleware(RequestDelegate rd) + { + _next = rd; + } + + public async Task Invoke(HttpContext httpContext) + { + var identity = new ClaimsIdentity("cookies"); + identity.AddClaim(new Claim("sub", "4611ce3f-380d-4db5-8d76-87a8689058ed")); + httpContext.User.AddIdentity(identity); + await _next.Invoke(httpContext); + } + } } }