@@ -34,19 +34,19 @@ private static ConnectionSettings DefaultSettings(ConnectionSettings settings) =
34
34
. Ignore ( p => p . PrivateValue )
35
35
. Rename ( p => p . OnlineHandle , "nickname" )
36
36
)
37
- //We try and fetch the test name during integration tests when running fiddler to send the name
37
+ //We try and fetch the test name during integration tests when running fiddler to send the name
38
38
//as the TestMethod header, this allows us to quickly identify which test sent which request
39
39
. GlobalHeaders ( new NameValueCollection
40
40
{
41
41
{ "TestMethod" , ExpensiveTestNameForIntegrationTests ( ) }
42
42
} ) ;
43
43
44
-
44
+
45
45
public static ConnectionSettings CreateSettings (
46
- Func < ConnectionSettings , ConnectionSettings > modifySettings = null ,
47
- int port = 9200 ,
46
+ Func < ConnectionSettings , ConnectionSettings > modifySettings = null ,
47
+ int port = 9200 ,
48
48
bool forceInMemory = false ,
49
- Func < Uri , IConnectionPool > createPool = null ,
49
+ Func < Uri , IConnectionPool > createPool = null ,
50
50
Func < ConnectionSettings , IElasticsearchSerializer > serializerFactory = null
51
51
)
52
52
{
@@ -77,16 +77,29 @@ public static IConnection CreateConnection(ConnectionSettings settings = null, b
77
77
: new InMemoryConnection ( ) ;
78
78
79
79
public static IElasticClient GetFixedReturnClient (
80
- object responseJson , int statusCode = 200 , Func < ConnectionSettings , ConnectionSettings > modifySettings = null )
80
+ object response ,
81
+ int statusCode = 200 ,
82
+ Func < ConnectionSettings , ConnectionSettings > modifySettings = null ,
83
+ string contentType = "application/json" ,
84
+ Exception exception = null )
81
85
{
82
86
var serializer = new JsonNetSerializer ( new ConnectionSettings ( ) ) ;
83
87
byte [ ] fixedResult ;
84
- using ( var ms = new MemoryStream ( ) )
88
+
89
+ if ( contentType == "application/json" )
85
90
{
86
- serializer . Serialize ( responseJson , ms ) ;
87
- fixedResult = ms . ToArray ( ) ;
91
+ using ( var ms = new MemoryStream ( ) )
92
+ {
93
+ serializer . Serialize ( response , ms ) ;
94
+ fixedResult = ms . ToArray ( ) ;
95
+ }
88
96
}
89
- var connection = new InMemoryConnection ( fixedResult , statusCode ) ;
97
+ else
98
+ {
99
+ fixedResult = Encoding . UTF8 . GetBytes ( response . ToString ( ) ) ;
100
+ }
101
+
102
+ var connection = new InMemoryConnection ( fixedResult , statusCode , exception ) ;
90
103
var connectionPool = new SingleNodeConnectionPool ( new Uri ( "http://localhost:9200" ) ) ;
91
104
var defaultSettings = new ConnectionSettings ( connectionPool , connection ) ;
92
105
var settings = ( modifySettings != null ) ? modifySettings ( defaultSettings ) : defaultSettings ;
@@ -130,8 +143,8 @@ private static ITestConfiguration LoadConfiguration()
130
143
131
144
// If running the classic .NET solution, tests run from bin/{config} directory,
132
145
// but when running DNX solution, tests run from the test project root
133
- var yamlConfigurationPath = directoryInfo . Name == "Tests" &&
134
- directoryInfo . Parent != null &&
146
+ var yamlConfigurationPath = directoryInfo . Name == "Tests" &&
147
+ directoryInfo . Parent != null &&
135
148
directoryInfo . Parent . Name == "src"
136
149
? "tests.yaml"
137
150
: @"..\..\tests.yaml" ;
0 commit comments