44using System . Net ;
55using System . Net . Http ;
66using System . Threading . Tasks ;
7+ using MovieProject . Logic . DTO . MovieProject . Logic . Proxy . DTO ;
8+ using Newtonsoft . Json ;
79using SystemTestingTools ;
810using Xunit ;
911
@@ -15,7 +17,8 @@ public class GetUserHappyTests
1517 {
1618 private readonly TestServerFixture Fixture ;
1719
18- private static string Url = "https://jsonplaceholder.typicode.com/users" ;
20+ private static string GetUrl = "https://jsonplaceholder.typicode.com/users" ;
21+ private static string SearchUrl = "https://jsonplaceholder.typicode.com/searchUsers" ;
1922
2023 public GetUserHappyTests ( TestServerFixture fixture )
2124 {
@@ -35,7 +38,7 @@ public async Task When_UserAsksForUserList_Then_ReturnListProperly()
3538 dto [ 0 ] . Name = "Changed in code" ;
3639 } ) ;
3740
38- client . AppendHttpCallStub ( HttpMethod . Get , new System . Uri ( Url ) , response ) ;
41+ client . AppendHttpCallStub ( HttpMethod . Get , new System . Uri ( GetUrl ) , response ) ;
3942
4043 // act
4144 var httpResponse = await client . GetAsync ( "/api/users" ) ;
@@ -49,7 +52,7 @@ public async Task When_UserAsksForUserList_Then_ReturnListProperly()
4952 // assert outgoing
5053 var outgoingRequests = client . GetSessionOutgoingRequests ( ) ;
5154 outgoingRequests . Count . Should ( ) . Be ( 1 ) ;
52- outgoingRequests [ 0 ] . GetEndpoint ( ) . Should ( ) . Be ( $ "GET { Url } ") ;
55+ outgoingRequests [ 0 ] . GetEndpoint ( ) . Should ( ) . Be ( $ "GET { GetUrl } ") ;
5356 outgoingRequests [ 0 ] . GetHeaderValue ( "Referer" ) . Should ( ) . Be ( MovieProject . Logic . Constants . Website ) ;
5457
5558 // assert return
@@ -69,5 +72,49 @@ public async Task When_UserAsksForUserList_Then_ReturnListProperly()
6972 list [ 9 ] . Should ( ) . Be ( "Patricia Lebsack" ) ;
7073 }
7174 }
75+
76+ [ Fact ]
77+ public async Task When_UserSearchesWithValidParameters_Then_ReturnListProperly ( )
78+ {
79+ // arrange
80+ var complexParameter = new UserSearchModel
81+ {
82+ Username = "Bret" ,
83+ } ;
84+ var serialisedComplexParameters = JsonConvert . SerializeObject ( complexParameter ) ;
85+ var expectedResponse = new List < string > ( )
86+ {
87+ "Leanne Graham"
88+ } ;
89+
90+ var client = Fixture . Server . CreateClient ( ) ;
91+ client . CreateSession ( ) ;
92+ var response = ResponseFactory . FromFiddlerLikeResponseFile ( $ "{ Fixture . StubsFolder } /UserApi/Real_Responses/Happy/200_SearchListUsers.txt") ;
93+
94+ client . AppendHttpCallStub ( HttpMethod . Get , new System . Uri ( @$ "{ SearchUrl } ?userSearchModel={ serialisedComplexParameters } ") , response ) ;
95+
96+ // act
97+ var httpResponse = await client . GetAsync ( "/api/users" ) ;
98+
99+ using ( new AssertionScope ( ) )
100+ {
101+ // assert logs
102+ var logs = client . GetSessionLogs ( ) ;
103+ logs . Should ( ) . BeEmpty ( ) ;
104+
105+ // assert outgoing
106+ var outgoingRequests = client . GetSessionOutgoingRequests ( ) ;
107+ outgoingRequests . Count . Should ( ) . Be ( 1 ) ;
108+ outgoingRequests [ 0 ] . GetEndpoint ( ) . Should ( ) . Be ( $ "GET { SearchUrl } ") ;
109+ outgoingRequests [ 0 ] . GetHeaderValue ( "Referer" ) . Should ( ) . Be ( MovieProject . Logic . Constants . Website ) ;
110+
111+ // assert return
112+ httpResponse . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
113+
114+ var list = await httpResponse . ReadJsonBody < List < string > > ( ) ;
115+ list . Count . Should ( ) . Be ( 1 ) ;
116+ list . Should ( ) . BeEquivalentTo ( expectedResponse ) ;
117+ }
118+ }
72119 }
73120}
0 commit comments