-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example to display error of AppendHttpCallStub when there are q…
…uery params with curly brackets * Added complex parameter logic as example in controller, service and proxy. * Re-added previously overwritten test * Separated tests to different files
- Loading branch information
Showing
8 changed files
with
190 additions
and
3 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Examples/MovieProject/MovieProject.Logic/DTO/UserSearchModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace MovieProject.Logic.DTO | ||
{ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MovieProject.Logic.Proxy.DTO | ||
{ | ||
|
||
public class UserSearchModel | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("username")] | ||
public string Username { get; set; } | ||
|
||
[JsonPropertyName("email")] | ||
public string Email { get; set; } | ||
|
||
[JsonPropertyName("phone")] | ||
public string Phone { get; set; } | ||
|
||
[JsonPropertyName("website")] | ||
public string Website { get; set; } | ||
} | ||
|
||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Examples/MovieProject/MovieProject.Logic/Extensions/UserMapperExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using MovieProject.Logic.Proxy.DTO; | ||
|
||
namespace MovieProject.Logic.Extensions | ||
{ | ||
public static class UserMapperExtensions | ||
{ | ||
public static UserSearchModel MapUserSearchModelDtoToProxyDto( | ||
this DTO.MovieProject.Logic.Proxy.DTO.UserSearchModel searchModel) | ||
{ | ||
return new UserSearchModel | ||
{ | ||
Name = searchModel.Name, | ||
Username = searchModel.Username, | ||
Email = searchModel.Email, | ||
Phone = searchModel.Phone, | ||
Website = searchModel.Website | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Examples/MovieProject/MovieProject.Logic/Proxy/DTO/UserSearchModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MovieProject.Logic.Proxy.DTO | ||
{ | ||
|
||
public class UserSearchModel | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("username")] | ||
public string Username { get; set; } | ||
|
||
[JsonPropertyName("email")] | ||
public string Email { get; set; } | ||
|
||
[JsonPropertyName("phone")] | ||
public string Phone { get; set; } | ||
|
||
[JsonPropertyName("website")] | ||
public string Website { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...ct/MovieProject.Tests/MovieProject.IsolatedTests/ComponentTesting/SearchUserHappyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using IsolatedTests.ComponentTestings; | ||
using MovieProject.Logic.DTO.MovieProject.Logic.Proxy.DTO; | ||
using Newtonsoft.Json; | ||
using SystemTestingTools; | ||
using Xunit; | ||
|
||
namespace MovieProject.IsolatedTests.ComponentTesting | ||
{ | ||
[Collection("SharedServer collection")] | ||
[Trait("Project", "User Component Tests (Happy)")] | ||
public class SearchUserHappyTests | ||
{ | ||
private readonly TestServerFixture Fixture; | ||
|
||
private static string Url = "https://jsonplaceholder.typicode.com/searchUsers"; | ||
|
||
public SearchUserHappyTests(TestServerFixture fixture) | ||
{ | ||
Fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task When_UserSearchesWithValidParameters_Then_ReturnListProperly() | ||
{ | ||
// arrange | ||
var complexParameter = new UserSearchModel | ||
{ | ||
Username = "Bret", | ||
}; | ||
var serialisedComplexParameters = JsonConvert.SerializeObject(complexParameter); | ||
var expectedResponse = new List<string>() | ||
{ | ||
"Leanne Graham" | ||
}; | ||
|
||
var client = Fixture.Server.CreateClient(); | ||
client.CreateSession(); | ||
var response = ResponseFactory.FromFiddlerLikeResponseFile($"{Fixture.StubsFolder}/UserApi/Real_Responses/Happy/200_SearchListUsers.txt"); | ||
|
||
client.AppendHttpCallStub(HttpMethod.Get, new System.Uri(@$"{Url}?userSearchModel={serialisedComplexParameters}"), response); | ||
|
||
// act | ||
var httpResponse = await client.GetAsync("/api/users"); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
// assert logs | ||
var logs = client.GetSessionLogs(); | ||
logs.Should().BeEmpty(); | ||
|
||
// assert outgoing | ||
var outgoingRequests = client.GetSessionOutgoingRequests(); | ||
outgoingRequests.Count.Should().Be(1); | ||
outgoingRequests[0].GetEndpoint().Should().Be($"GET {Url}"); | ||
outgoingRequests[0].GetHeaderValue("Referer").Should().Be(MovieProject.Logic.Constants.Website); | ||
|
||
// assert return | ||
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
var list = await httpResponse.ReadJsonBody<List<string>>(); | ||
list.Count.Should().Be(1); | ||
list.Should().BeEquivalentTo(expectedResponse); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters