Skip to content

Commit bf34bff

Browse files
committed
2 parents 485505a + 4e9524c commit bf34bff

7 files changed

Lines changed: 45 additions & 36 deletions

File tree

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Basket/BasketService.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ namespace eShopOnContainers.Core.Services.Basket
99
public class BasketService : IBasketService
1010
{
1111
private readonly IRequestProvider _requestProvider;
12+
private const string ApiUrlBase = "api/v1/basket";
1213

1314
public BasketService(IRequestProvider requestProvider)
1415
{
1516
_requestProvider = requestProvider;
1617
}
1718

1819
public async Task<CustomerBasket> GetBasketAsync(string guidUser, string token)
19-
{
20-
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);
21-
22-
builder.Path = guidUser;
20+
{
21+
var builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint)
22+
{
23+
Path = $"{ApiUrlBase}/{guidUser}"
24+
};
2325

24-
string uri = builder.ToString();
26+
var uri = builder.ToString();
2527

2628
CustomerBasket basket =
2729
await _requestProvider.GetAsync<CustomerBasket>(uri, token);
@@ -33,9 +35,12 @@ public async Task<CustomerBasket> GetBasketAsync(string guidUser, string token)
3335

3436
public async Task<CustomerBasket> UpdateBasketAsync(CustomerBasket customerBasket, string token)
3537
{
36-
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);
38+
var builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint)
39+
{
40+
Path = ApiUrlBase
41+
};
3742

38-
string uri = builder.ToString();
43+
var uri = builder.ToString();
3944

4045
var result = await _requestProvider.PostAsync(uri, customerBasket, token);
4146

@@ -44,20 +49,24 @@ public async Task<CustomerBasket> UpdateBasketAsync(CustomerBasket customerBaske
4449

4550
public async Task CheckoutAsync(BasketCheckout basketCheckout, string token)
4651
{
47-
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint + "/checkout");
52+
var builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint)
53+
{
54+
Path = $"{ApiUrlBase}/checkout"
55+
};
4856

49-
string uri = builder.ToString();
57+
var uri = builder.ToString();
5058

5159
await _requestProvider.PostAsync(uri, basketCheckout, token);
5260
}
5361

5462
public async Task ClearBasketAsync(string guidUser, string token)
5563
{
56-
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);
57-
58-
builder.Path = guidUser;
64+
var builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint)
65+
{
66+
Path = $"{ApiUrlBase}/{guidUser}"
67+
};
5968

60-
string uri = builder.ToString();
69+
var uri = builder.ToString();
6170

6271
await _requestProvider.DeleteAsync(uri, token);
6372
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using Microsoft.AspNetCore.Hosting;
2-
using Microsoft.AspNetCore.TestHost;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.IO;
6-
using System.Text;
7-
8-
namespace FunctionalTests.Services.Basket
1+
namespace FunctionalTests.Services.Basket
92
{
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.AspNetCore.TestHost;
5+
using System.IO;
6+
107
public class BasketScenariosBase
118
{
9+
private const string ApiUrlBase = "api/v1/basket";
10+
1211
public TestServer CreateServer()
1312
{
1413
var webHostBuilder = new WebHostBuilder();
@@ -22,14 +21,14 @@ public static class Get
2221
{
2322
public static string GetBasketByCustomer(string customerId)
2423
{
25-
return $"/{customerId}";
24+
return $"{ApiUrlBase}/{customerId}";
2625
}
2726
}
2827

2928
public static class Post
3029
{
31-
public static string CreateBasket = "/";
32-
public static string Checkout = "/checkout";
30+
public static string CreateBasket = $"{ApiUrlBase}/";
31+
public static string Checkout = $"{ApiUrlBase}/checkout";
3332
}
3433
}
35-
}
34+
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
using Microsoft.AspNetCore.Hosting;
22
using Microsoft.AspNetCore.TestHost;
3-
using Microsoft.eShopOnContainers.Services.Basket.API;
4-
using System;
5-
using System.Collections.Generic;
63
using System.IO;
7-
using System.Text;
84

95
namespace IntegrationTests.Services.Basket
106
{
117
public class BasketScenarioBase
128
{
9+
private const string ApiUrlBase = "api/v1/basket";
10+
1311
public TestServer CreateServer()
1412
{
1513
var webHostBuilder = new WebHostBuilder();
@@ -23,14 +21,14 @@ public static class Get
2321
{
2422
public static string GetBasket(int id)
2523
{
26-
return $"{id}";
24+
return $"{ApiUrlBase}/{id}";
2725
}
2826
}
2927

3028
public static class Post
3129
{
32-
public static string Basket = "";
33-
public static string CheckoutOrder = "checkout";
30+
public static string Basket = $"{ApiUrlBase}/";
31+
public static string CheckoutOrder = $"{ApiUrlBase}/checkout";
3432
}
3533
}
3634
}

test/Services/LoadTest/Basket.API/AddBasket.webtest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<FormPostParameter Name="session_state" Value="{{$HIDDEN1.session_state}}" RecordedValue="ZxRKRHGaGBxyciYNO7yxXNcHb8MxcvGDfUWuUVaCkNo.5de6fc3970ef99b7b67328e1df0e93ce" CorrelationBinding="" UrlEncode="True" />
6666
</FormPostHttpBody>
6767
</Request>
68-
<Request Method="POST" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
68+
<Request Method="POST" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/api/{{ApiVersion}}/basket" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
6969
<Headers>
7070
<Header Name="Authorization" Value="Bearer {{$HIDDEN1.access_token}} " />
7171
<Header Name="Accept" Value="application/json" />
@@ -80,6 +80,7 @@
8080
<ContextParameter Name="IdentityApiServer" Value="http://" />
8181
<ContextParameter Name="BasketApiServer" Value="http://" />
8282
<ContextParameter Name="UserId" Value="" />
83+
<ContextParameter Name="ApiVersion" Value="v1" />
8384
</ContextParameters>
8485
<ValidationRules>
8586
<ValidationRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateResponseUrl, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" DisplayName="Response URL" Description="Validates that the response URL after redirects are followed is the same as the recorded response URL. QueryString parameters are ignored." Level="Low" ExectuionOrder="BeforeDependents" />

test/Services/LoadTest/Basket.API/Checkout.webtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<FormPostParameter Name="session_state" Value="{{$HIDDEN1.session_state}}" RecordedValue="ZxRKRHGaGBxyciYNO7yxXNcHb8MxcvGDfUWuUVaCkNo.5de6fc3970ef99b7b67328e1df0e93ce" CorrelationBinding="" UrlEncode="True" />
6666
</FormPostHttpBody>
6767
</Request>
68-
<Request Method="POST" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/checkout" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
68+
<Request Method="POST" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/api/{{ApiVersion}}/checkout" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
6969
<Headers>
7070
<Header Name="Authorization" Value="Bearer {{$HIDDEN1.access_token}}" />
7171
<Header Name="Accept" Value="application/json" />

test/Services/LoadTest/Basket.API/DeleteBasket.webtest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<FormPostParameter Name="session_state" Value="{{$HIDDEN1.session_state}}" RecordedValue="ZxRKRHGaGBxyciYNO7yxXNcHb8MxcvGDfUWuUVaCkNo.5de6fc3970ef99b7b67328e1df0e93ce" CorrelationBinding="" UrlEncode="True" />
6666
</FormPostHttpBody>
6767
</Request>
68-
<Request Method="DELETE" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/{{UserId}}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
68+
<Request Method="DELETE" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/api/{{ApiVersion}}/{{UserId}}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
6969
<Headers>
7070
<Header Name="Authorization" Value="Bearer {{$HIDDEN1.access_token}} " />
7171
<Header Name="Accept" Value="application/json" />
@@ -79,6 +79,7 @@
7979
<ContextParameter Name="IdentityApiServer" Value="http://" />
8080
<ContextParameter Name="BasketApiServer" Value="http://" />
8181
<ContextParameter Name="UserId" Value="" />
82+
<ContextParameter Name="ApiVersion" Value="v1" />
8283
</ContextParameters>
8384
<ValidationRules>
8485
<ValidationRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateResponseUrl, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" DisplayName="Response URL" Description="Validates that the response URL after redirects are followed is the same as the recorded response URL. QueryString parameters are ignored." Level="Low" ExectuionOrder="BeforeDependents" />

test/Services/LoadTest/Basket.API/GetBasket.webtest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<FormPostParameter Name="session_state" Value="{{$HIDDEN1.session_state}}" RecordedValue="ZxRKRHGaGBxyciYNO7yxXNcHb8MxcvGDfUWuUVaCkNo.5de6fc3970ef99b7b67328e1df0e93ce" CorrelationBinding="" UrlEncode="True" />
6666
</FormPostHttpBody>
6767
</Request>
68-
<Request Method="GET" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/{{UserId}}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
68+
<Request Method="GET" Guid="d24fe957-0cbb-46d4-8478-974de57e5cba" Version="1.1" Url="{{BasketApiServer}}/api/{{ApiVersion}}/{{UserId}}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
6969
<Headers>
7070
<Header Name="Authorization" Value="Bearer {{$HIDDEN1.access_token}} " />
7171
<Header Name="Accept" Value="application/json" />
@@ -79,6 +79,7 @@
7979
<ContextParameter Name="IdentityApiServer" Value="http://" />
8080
<ContextParameter Name="BasketApiServer" Value="http://" />
8181
<ContextParameter Name="UserId" Value="" />
82+
<ContextParameter Name="ApiVersion" Value="v1" />
8283
</ContextParameters>
8384
<ValidationRules>
8485
<ValidationRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateResponseUrl, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" DisplayName="Response URL" Description="Validates that the response URL after redirects are followed is the same as the recorded response URL. QueryString parameters are ignored." Level="Low" ExectuionOrder="BeforeDependents" />

0 commit comments

Comments
 (0)