Skip to content

Commit 06f978b

Browse files
committed
Modify test. UserId is a Guid type
1 parent f217471 commit 06f978b

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

test/Services/IntegrationTests/Services/Locations/LocationsScenarioBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static string LocationBy(string id)
2727
return $"api/v1/locations/{id}";
2828
}
2929

30-
public static string UserLocationBy(int id)
30+
public static string UserLocationBy(Guid id)
3131
{
3232
return $"api/v1/locations/user/{id}";
3333
}

test/Services/IntegrationTests/Services/Locations/LocationsScenarios.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using System.Threading.Tasks;
99
using Xunit;
10+
using System;
1011

1112
namespace IntegrationTests.Services.Locations
1213
{
@@ -18,7 +19,7 @@ public async Task Set_new_user_seattle_location_response_ok_status_code()
1819
{
1920
using (var server = CreateServer())
2021
{
21-
var userId = 1234;
22+
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
2223
var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json");
2324

2425
// Expected result
@@ -50,7 +51,7 @@ public async Task Set_new_user_readmond_location_response_ok_status_code()
5051
{
5152
using (var server = CreateServer())
5253
{
53-
var userId = 1234;
54+
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
5455
var content = new StringContent(BuildLocationsRequest(-122.119998, 47.690876), UTF8Encoding.UTF8, "application/json");
5556

5657
// Expected result
@@ -82,7 +83,7 @@ public async Task Set_new_user_Washington_location_response_ok_status_code()
8283
{
8384
using (var server = CreateServer())
8485
{
85-
var userId = 1234;
86+
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
8687
var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json");
8788

8889
// Expected result

test/Services/IntegrationTests/Services/Locations/LocationsTestsStartup.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
using IntegrationTests.Middleware;
44
using Microsoft.AspNetCore.Builder;
55
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.AspNetCore.Http;
67
using Microsoft.eShopOnContainers.Services.Locations.API;
8+
using System.Security.Claims;
9+
using System.Threading.Tasks;
710

811
public class LocationsTestsStartup : Startup
912
{
@@ -15,12 +18,29 @@ protected override void ConfigureAuth(IApplicationBuilder app)
1518
{
1619
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
1720
{
18-
app.UseMiddleware<AutoAuthorizeMiddleware>();
21+
app.UseMiddleware<LocationAuthorizeMiddleware>();
1922
}
2023
else
2124
{
2225
base.ConfigureAuth(app);
2326
}
2427
}
28+
29+
class LocationAuthorizeMiddleware
30+
{
31+
private readonly RequestDelegate _next;
32+
public LocationAuthorizeMiddleware(RequestDelegate rd)
33+
{
34+
_next = rd;
35+
}
36+
37+
public async Task Invoke(HttpContext httpContext)
38+
{
39+
var identity = new ClaimsIdentity("cookies");
40+
identity.AddClaim(new Claim("sub", "4611ce3f-380d-4db5-8d76-87a8689058ed"));
41+
httpContext.User.AddIdentity(identity);
42+
await _next.Invoke(httpContext);
43+
}
44+
}
2545
}
2646
}

0 commit comments

Comments
 (0)