1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
3
4
using System . IO ;
4
5
using System . Net ;
5
6
using System . Text ;
@@ -13,23 +14,27 @@ public class InMemoryConnection : HttpConnection
13
14
private byte [ ] _fixedResultBytes = Encoding . UTF8 . GetBytes ( "{ \" USING NEST IN MEMORY CONNECTION\" : null }" ) ;
14
15
private int _statusCode ;
15
16
16
- public InMemoryConnection ( )
17
- : base ( new ConnectionConfiguration ( ) )
17
+ public List < Tuple < string , Uri , byte [ ] > > Requests = new List < Tuple < string , Uri , byte [ ] > > ( ) ;
18
+
19
+ public bool RecordRequests { get ; set ; }
20
+
21
+ public InMemoryConnection ( ) : base ( new ConnectionConfiguration ( ) )
18
22
{
19
23
20
24
}
21
- public InMemoryConnection ( IConnectionConfigurationValues settings )
22
- : base ( settings )
25
+ public InMemoryConnection ( IConnectionConfigurationValues settings ) : base ( settings )
23
26
{
24
27
_statusCode = 200 ;
25
28
}
26
29
27
- public InMemoryConnection ( IConnectionConfigurationValues settings , string fixedResult , int statusCode = 200 )
28
- : this ( settings )
30
+ public InMemoryConnection ( IConnectionConfigurationValues settings , string fixedResult , int statusCode = 200 ) : this ( settings )
29
31
{
30
32
_fixedResultBytes = Encoding . UTF8 . GetBytes ( fixedResult ) ;
31
33
_statusCode = statusCode ;
32
34
}
35
+
36
+
37
+
33
38
34
39
protected override ElasticsearchResponse < Stream > DoSynchronousRequest ( HttpWebRequest request , byte [ ] data = null , IRequestConfiguration requestSpecificConfig = null )
35
40
{
@@ -45,6 +50,12 @@ private ElasticsearchResponse<Stream> ReturnConnectionStatus(HttpWebRequest requ
45
50
cs . Response = new MemoryStream ( _fixedResultBytes ) ;
46
51
if ( this . ConnectionSettings . ConnectionStatusHandler != null )
47
52
this . ConnectionSettings . ConnectionStatusHandler ( cs ) ;
53
+
54
+ if ( this . RecordRequests )
55
+ {
56
+ this . Requests . Add ( Tuple . Create ( method , request . RequestUri , data ) ) ;
57
+ }
58
+
48
59
return cs ;
49
60
}
50
61
0 commit comments