Skip to content

Commit a5f3b97

Browse files
committed
Merge branch 'feature/orgtestprojects' into dev
2 parents b6e7029 + d7d4dd4 commit a5f3b97

143 files changed

Lines changed: 2082 additions & 1041 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eShopOnContainers-ServicesAndWebApps.sln

Lines changed: 526 additions & 259 deletions
Large diffs are not rendered by default.

eShopOnContainers.sln

Lines changed: 526 additions & 205 deletions
Large diffs are not rendered by default.

src/Services/Basket/Basket.API/Controllers/BasketController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public async Task<IActionResult> Post([FromBody]CustomerBasket value)
5959
public async Task<IActionResult> Checkout([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
6060
{
6161
var userId = _identitySvc.GetUserIdentity();
62-
var userName = User.FindFirst(x => x.Type == "unique_name").Value;
62+
6363

6464
basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
6565
guid : basketCheckout.RequestId;
@@ -71,6 +71,8 @@ public async Task<IActionResult> Checkout([FromBody]BasketCheckout basketCheckou
7171
return BadRequest();
7272
}
7373

74+
var userName = User.FindFirst(x => x.Type == "unique_name").Value;
75+
7476
var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street,
7577
basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,
7678
basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.AspNetCore.Http;
2+
using System.Security.Claims;
3+
using System.Threading.Tasks;
4+
5+
namespace Basket.FunctionalTests.Base
6+
{
7+
class AutoAuthorizeMiddleware
8+
{
9+
public const string IDENTITY_ID = "9e3163b9-1ae6-4652-9dc6-7898ab7b7a00";
10+
11+
private readonly RequestDelegate _next;
12+
13+
public AutoAuthorizeMiddleware(RequestDelegate rd)
14+
{
15+
_next = rd;
16+
}
17+
18+
public async Task Invoke(HttpContext httpContext)
19+
{
20+
var identity = new ClaimsIdentity("cookies");
21+
22+
identity.AddClaim(new Claim("sub", IDENTITY_ID));
23+
identity.AddClaim(new Claim("unique_name", IDENTITY_ID));
24+
25+
httpContext.User.AddIdentity(identity);
26+
27+
await _next.Invoke(httpContext);
28+
}
29+
}
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.AspNetCore.TestHost;
3+
using Microsoft.Extensions.Configuration;
4+
using System.IO;
5+
using System.Reflection;
6+
7+
namespace Basket.FunctionalTests.Base
8+
{
9+
public class BasketScenarioBase
10+
{
11+
private const string ApiUrlBase = "api/v1/basket";
12+
13+
public TestServer CreateServer()
14+
{
15+
var path = Assembly.GetAssembly(typeof(BasketScenarioBase))
16+
.Location;
17+
18+
var hostBuilder = new WebHostBuilder()
19+
.UseContentRoot(Path.GetDirectoryName(path))
20+
.ConfigureAppConfiguration(cb =>
21+
{
22+
cb.AddJsonFile("appsettings.json", optional: false)
23+
.AddEnvironmentVariables();
24+
}).UseStartup<BasketTestsStartup>();
25+
26+
return new TestServer(hostBuilder);
27+
}
28+
29+
public static class Get
30+
{
31+
public static string GetBasket(int id)
32+
{
33+
return $"{ApiUrlBase}/{id}";
34+
}
35+
}
36+
37+
public static class Post
38+
{
39+
public static string Basket = $"{ApiUrlBase}/";
40+
public static string CheckoutOrder = $"{ApiUrlBase}/checkout";
41+
}
42+
}
43+
}

test/Services/FunctionalTests/Services/Basket/BasketTestsStartup.cs renamed to src/Services/Basket/Basket.FunctionalTests/Base/BasketTestStartup.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using FunctionalTests.Middleware;
2-
using Microsoft.AspNetCore.Builder;
3-
using Microsoft.AspNetCore.Hosting;
1+
using Microsoft.AspNetCore.Builder;
42
using Microsoft.eShopOnContainers.Services.Basket.API;
53
using Microsoft.Extensions.Configuration;
64

7-
namespace FunctionalTests.Services.Basket
5+
namespace Basket.FunctionalTests.Base
86
{
9-
public class BasketTestsStartup : Startup
7+
class BasketTestsStartup : Startup
108
{
11-
public BasketTestsStartup(IConfiguration configuration) : base(configuration)
9+
public BasketTestsStartup(IConfiguration env) : base(env)
1210
{
1311
}
1412

@@ -22,6 +20,6 @@ protected override void ConfigureAuth(IApplicationBuilder app)
2220
{
2321
base.ConfigureAuth(app);
2422
}
25-
}
23+
}
2624
}
2725
}

test/Services/IntegrationTests/Services/Extensions/HttpClientExtensions.cs renamed to src/Services/Basket/Basket.FunctionalTests/Base/HttpClientExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using Microsoft.AspNetCore.TestHost;
22
using System;
3-
using System.Collections.Generic;
43
using System.Net.Http;
5-
using System.Text;
64

7-
namespace IntegrationTests.Services.Extensions
5+
namespace Basket.FunctionalTests.Base
86
{
97
static class HttpClientExtensions
108
{
119
public static HttpClient CreateIdempotentClient(this TestServer server)
1210
{
1311
var client = server.CreateClient();
12+
1413
client.DefaultRequestHeaders.Add("x-requestid", Guid.NewGuid().ToString());
14+
1515
return client;
1616
}
1717
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<None Remove="appsettings.json" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<Content Include="appsettings.json">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</Content>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
21+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.0" />
22+
<PackageReference Include="xunit" Version="2.3.1" />
23+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
24+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
25+
<PackageReference Include="Moq" Version="4.8.1" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\..\..\Web\WebMVC\WebMVC.csproj" />
30+
<ProjectReference Include="..\..\Location\Locations.API\Locations.API.csproj" />
31+
<ProjectReference Include="..\Basket.API\Basket.API.csproj" />
32+
</ItemGroup>
33+
</Project>

test/Services/IntegrationTests/Services/Basket/BasketScenarios.cs renamed to src/Services/Basket/Basket.FunctionalTests/BasketScenarios.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using IntegrationTests.Services.Extensions;
1+
using Basket.FunctionalTests.Base;
22
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
33
using Newtonsoft.Json;
44
using System;
@@ -8,7 +8,7 @@
88
using WebMVC.Models;
99
using Xunit;
1010

11-
namespace IntegrationTests.Services.Basket
11+
namespace Basket.FunctionalTests
1212
{
1313
public class BasketScenarios
1414
: BasketScenarioBase
@@ -17,7 +17,7 @@ public class BasketScenarios
1717
public async Task Post_basket_and_response_ok_status_code()
1818
{
1919
using (var server = CreateServer())
20-
{
20+
{
2121
var content = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
2222
var response = await server.CreateClient()
2323
.PostAsync(Post.Basket, content);
@@ -44,10 +44,12 @@ public async Task Send_Checkout_basket_and_response_ok_status_code()
4444
using (var server = CreateServer())
4545
{
4646
var contentBasket = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
47+
4748
await server.CreateClient()
4849
.PostAsync(Post.Basket, contentBasket);
4950

5051
var contentCheckout = new StringContent(BuildCheckout(), UTF8Encoding.UTF8, "application/json");
52+
5153
var response = await server.CreateIdempotentClient()
5254
.PostAsync(Post.CheckoutOrder, contentCheckout);
5355

@@ -57,7 +59,7 @@ await server.CreateClient()
5759

5860
string BuildBasket()
5961
{
60-
var order = new CustomerBasket("1234");
62+
var order = new CustomerBasket(AutoAuthorizeMiddleware.IDENTITY_ID);
6163

6264
order.Items.Add(new BasketItem
6365
{

test/Services/IntegrationTests/Services/Basket/RedisBasketRepositoryTests.cs renamed to src/Services/Basket/Basket.FunctionalTests/RedisBasketRepositoryTests.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
namespace IntegrationTests.Services.Basket
2-
{
3-
using Microsoft.eShopOnContainers.Services.Basket.API;
4-
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
5-
using Microsoft.Extensions.Logging;
6-
using Microsoft.Extensions.Options;
7-
using System.Collections.Generic;
8-
using System.Threading.Tasks;
9-
using Xunit;
10-
using Moq;
11-
using StackExchange.Redis;
1+
using Microsoft.eShopOnContainers.Services.Basket.API;
2+
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
3+
using Microsoft.Extensions.Logging;
4+
using Microsoft.Extensions.Options;
5+
using Moq;
6+
using StackExchange.Redis;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Xunit;
1212

13+
namespace Basket.FunctionalTests
14+
{
1315
public class RedisBasketRepositoryTests
1416
{
1517
private Mock<IOptionsSnapshot<BasketSettings>> _optionsMock;
@@ -55,7 +57,7 @@ public async Task Delete_Basket_return_null()
5557

5658
RedisBasketRepository BuildBasketRepository()
5759
{
58-
var loggerFactory = new LoggerFactory();
60+
var loggerFactory = new LoggerFactory();
5961
var configuration = ConfigurationOptions.Parse("127.0.0.1", true);
6062
configuration.ResolveDns = true;
6163
return new RedisBasketRepository(loggerFactory, ConnectionMultiplexer.Connect(configuration));

0 commit comments

Comments
 (0)