Skip to content

Commit ecd77d4

Browse files
committed
Fixing issue with query strings containing curly brackets, and adjust associated test
1 parent 2f115ba commit ecd77d4

6 files changed

Lines changed: 23 additions & 16 deletions

File tree

Examples/MovieProject/MovieProject.Logic/DTO/UserSearchModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class UserSearchModel
1010
[JsonPropertyName("name")]
1111
public string Name { get; set; }
1212

13-
[JsonPropertyName("username")]
13+
1414
public string Username { get; set; }
1515

1616
[JsonPropertyName("email")]

Examples/MovieProject/MovieProject.Logic/Proxy/UserProxy.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public UserProxy(HttpClient client,
4343

4444
public async Task<DTO.User[]> GetSearchUsers(UserSearchModel searchModel)
4545
{
46-
string serialisedQueryParameter = JsonSerializer.Serialize(searchModel);
47-
string route = $"searchUsers?userSearchModel={serialisedQueryParameter}";
46+
string route = $"searchUsers?Username={searchModel.Username}";
4847

4948
var result = await Send(HttpMethod.Get, route, (DTO.User[] users, HttpStatusCode status) =>
5049
{

Examples/MovieProject/MovieProject.Tests/MovieProject.IsolatedTests/ComponentTesting/SearchUserHappyTests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@ public async Task When_UserSearchesWithValidParameters_Then_ReturnListProperly()
3434
Username = "Bret",
3535
};
3636
var serialisedComplexParameters = JsonConvert.SerializeObject(complexParameter);
37-
var expectedResponse = new List<string>()
38-
{
39-
"Leanne Graham"
40-
};
4137

4238
var client = Fixture.Server.CreateClient();
4339
client.CreateSession();
4440
var response = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/UserApi/Real_Responses/Happy/200_SearchListUsers.txt");
4541

46-
client.AppendHttpCallStub(HttpMethod.Get, new System.Uri(@$"{Url}?userSearchModel={serialisedComplexParameters}"), response);
42+
var uri = new System.Uri(@$"{Url}?Username=Bret");
43+
client.AppendHttpCallStub(HttpMethod.Get, uri, response);
4744

4845
// act
49-
var httpResponse = await client.GetAsync("/api/users");
46+
var httpResponse = await client.GetAsync($"/api/searchUsers?jsonSearchModel={serialisedComplexParameters}");
5047

5148
using (new AssertionScope())
5249
{
@@ -57,12 +54,18 @@ public async Task When_UserSearchesWithValidParameters_Then_ReturnListProperly()
5754
// assert outgoing
5855
var outgoingRequests = client.GetSessionOutgoingRequests();
5956
outgoingRequests.Count.Should().Be(1);
60-
outgoingRequests[0].GetEndpoint().Should().Be($"GET {Url}");
57+
outgoingRequests[0].GetEndpoint().Should().Be($"GET {Url}?Username=Bret");
6158
outgoingRequests[0].GetHeaderValue("Referer").Should().Be(MovieProject.Logic.Constants.Website);
6259

6360
// assert return
6461
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
6562

63+
var expectedResponse = new List<string>()
64+
{
65+
"Leanne Graham"
66+
};
67+
68+
6669
var list = await httpResponse.ReadJsonBody<List<string>>();
6770
list.Count.Should().Be(1);
6871
list.Should().BeEquivalentTo(expectedResponse);

Examples/MovieProject/MovieProject.Web/Controllers/UserController.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using MovieProject.Logic.DTO.MovieProject.Logic.Proxy.DTO;
66
using MovieProject.Logic.Extensions;
77
using MovieProject.Logic.Service;
8+
using Newtonsoft.Json;
89

910
namespace MovieProject.Web.Controllers
1011
{
@@ -26,10 +27,12 @@ public async Task<List<string>> GetUsers()
2627
return await _userService.GetUsers();
2728
}
2829

29-
[HttpPost("searchUsers")]
30-
public async Task<List<string>> GetSearchUsers([FromBody] UserSearchModel searchModel)
30+
[HttpGet("searchUsers")]
31+
public async Task<List<string>> GetSearchUsers(string jsonSearchModel)
3132
{
32-
var proxyDtoSearchModel = searchModel.MapUserSearchModelDtoToProxyDto();
33+
var proxyDtoSearchModel = JsonConvert.DeserializeObject<Logic.Proxy.DTO.UserSearchModel>(jsonSearchModel);
34+
35+
3336
// second controller with separate dependency used for testing SystemTestingTools
3437
return await _userService.GetSearchUsers(proxyDtoSearchModel);
3538
}

Tool/SystemTestingTools/Extensions/HttpRequestMessageExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using Microsoft.AspNetCore.WebUtilities;
1+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
2+
using Microsoft.AspNetCore.WebUtilities;
23
using System;
34
using System.Collections.Generic;
45
using System.Net.Http;
6+
using System.Security.Policy;
57
using System.Text.Json;
68
using System.Threading.Tasks;
79
using SystemTestingTools.Internal;
@@ -27,7 +29,7 @@ public static List<DateTime> GetDatesSent(this HttpRequestMessage request)
2729
/// </summary>
2830
public static string GetEndpoint(this HttpRequestMessage request)
2931
{
30-
var endpoint = string.Format($"{request.Method} {request.RequestUri}");
32+
var endpoint = string.Format("{0} {1}", request.Method, request.RequestUri);
3133
return endpoint;
3234
}
3335

Tool/SystemTestingTools/Internal/StubEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public StubEndpoint(HttpMethod httpMethod, Uri url, Exception exception, Diction
3535
private void SetEndpoint(HttpMethod httpMethod, Uri url)
3636
{
3737
if (url == null) throw new ArgumentNullException(nameof(url));
38-
endpoint = string.Format($"{httpMethod} {url}");
38+
endpoint = string.Format("{0} {1}", httpMethod, url);
3939
}
4040

4141
public bool IsMatch(HttpRequestMessage request)

0 commit comments

Comments
 (0)