@@ -34,19 +34,19 @@ private static ConnectionSettings DefaultSettings(ConnectionSettings settings) =
3434 . Ignore ( p => p . PrivateValue )
3535 . Rename ( p => p . OnlineHandle , "nickname" )
3636 )
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
3838 //as the TestMethod header, this allows us to quickly identify which test sent which request
3939 . GlobalHeaders ( new NameValueCollection
4040 {
4141 { "TestMethod" , ExpensiveTestNameForIntegrationTests ( ) }
4242 } ) ;
4343
44-
44+
4545 public static ConnectionSettings CreateSettings (
46- Func < ConnectionSettings , ConnectionSettings > modifySettings = null ,
47- int port = 9200 ,
46+ Func < ConnectionSettings , ConnectionSettings > modifySettings = null ,
47+ int port = 9200 ,
4848 bool forceInMemory = false ,
49- Func < Uri , IConnectionPool > createPool = null ,
49+ Func < Uri , IConnectionPool > createPool = null ,
5050 Func < ConnectionSettings , IElasticsearchSerializer > serializerFactory = null
5151 )
5252 {
@@ -77,16 +77,29 @@ public static IConnection CreateConnection(ConnectionSettings settings = null, b
7777 : new InMemoryConnection ( ) ;
7878
7979 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 )
8185 {
8286 var serializer = new JsonNetSerializer ( new ConnectionSettings ( ) ) ;
8387 byte [ ] fixedResult ;
84- using ( var ms = new MemoryStream ( ) )
88+
89+ if ( contentType == "application/json" )
8590 {
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+ }
8896 }
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 ) ;
90103 var connectionPool = new SingleNodeConnectionPool ( new Uri ( "http://localhost:9200" ) ) ;
91104 var defaultSettings = new ConnectionSettings ( connectionPool , connection ) ;
92105 var settings = ( modifySettings != null ) ? modifySettings ( defaultSettings ) : defaultSettings ;
@@ -130,8 +143,8 @@ private static ITestConfiguration LoadConfiguration()
130143
131144 // If running the classic .NET solution, tests run from bin/{config} directory,
132145 // 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 &&
135148 directoryInfo . Parent . Name == "src"
136149 ? "tests.yaml"
137150 : @"..\..\tests.yaml" ;
0 commit comments