We are running multiple unit tests, each of them creates it's own instance of ElasticClient. Some of the tests use "StringEnumConverter" to convert enums, other will use the default convertor (into integers). The problem is that it seems the settings of connection is cached somewhere and it's only the first test that decides how enums will be converted.
This is not a threading issue, since we are running the tests sequentially.
The constructor of the TestBase class looks like this:
public TestsBase(bool serializeEnumsToString = false)
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(
node,
defaultIndex: "my-application" + Guid.NewGuid().ToString()
);
if (serializeEnumsToString)
{
Console.Write("Setting up the enums convertor");
settings.AddContractJsonConverters(type =>
{
// TypeCheck to return StringEnumConverter for Enums and Nullable<T> where T : Enum
if (type.IsEnum ||
(type.IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>) &&
type.GetGenericArguments().First().IsEnum))
{
return new StringEnumConverter();
}
return null;
});
}
client = new ElasticClient(settings);
}
Is it possible that there is a cache (on appdomain level?) that would be used any time new instance of ElasticClient is created?