Modify test. UserId is a Guid type
This commit is contained in:
parent
f0cb13b96e
commit
c9484a0834
@ -27,7 +27,7 @@ namespace IntegrationTests.Services.Locations
|
|||||||
return $"api/v1/locations/{id}";
|
return $"api/v1/locations/{id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string UserLocationBy(int id)
|
public static string UserLocationBy(Guid id)
|
||||||
{
|
{
|
||||||
return $"api/v1/locations/user/{id}";
|
return $"api/v1/locations/user/{id}";
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using System.Net.Http;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace IntegrationTests.Services.Locations
|
namespace IntegrationTests.Services.Locations
|
||||||
{
|
{
|
||||||
@ -18,7 +19,7 @@ namespace IntegrationTests.Services.Locations
|
|||||||
{
|
{
|
||||||
using (var server = CreateServer())
|
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");
|
var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
// Expected result
|
// Expected result
|
||||||
@ -50,7 +51,7 @@ namespace IntegrationTests.Services.Locations
|
|||||||
{
|
{
|
||||||
using (var server = CreateServer())
|
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");
|
var content = new StringContent(BuildLocationsRequest(-122.119998, 47.690876), UTF8Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
// Expected result
|
// Expected result
|
||||||
@ -82,7 +83,7 @@ namespace IntegrationTests.Services.Locations
|
|||||||
{
|
{
|
||||||
using (var server = CreateServer())
|
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");
|
var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
// Expected result
|
// Expected result
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
using IntegrationTests.Middleware;
|
using IntegrationTests.Middleware;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.eShopOnContainers.Services.Locations.API;
|
using Microsoft.eShopOnContainers.Services.Locations.API;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
public class LocationsTestsStartup : Startup
|
public class LocationsTestsStartup : Startup
|
||||||
{
|
{
|
||||||
@ -15,12 +18,29 @@
|
|||||||
{
|
{
|
||||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
app.UseMiddleware<AutoAuthorizeMiddleware>();
|
app.UseMiddleware<LocationAuthorizeMiddleware>();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
base.ConfigureAuth(app);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user