Modify test. UserId is a Guid type
This commit is contained in:
parent
f21747109b
commit
06f978bc97
@ -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}";
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<AutoAuthorizeMiddleware>();
|
||||
app.UseMiddleware<LocationAuthorizeMiddleware>();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user