I am writing some tests for a system that reads from ES using ElasticSearch.NET. The program transforms a search result into a different format.
What I would like to do in the test is use a large JSON file as a mock response from ES, in order to test that the transformer works.
However, I need to create a valid ISearchResponse
instance for the transformer, and the only way I have found to mock the result is to manually create each object in the hierarchy, for example:
var aggregations = new AggregateDictionary(new Dictionary<string, IAggregate>
{
["my_aggregate"] = new BucketAggregate
{
Items = new List<IBucket>()
{
new DateHistogramBucket(new Dictionary<string, IAggregate>()
{
{
"key", new KeyedValueAggregate(){Value = 10, ValueAsString = "10"}
}
})
}.AsReadOnly()
}
});
searchResponse.Aggregations.Returns(info => new AggregateDictionary(aggregations));
However, I'd like to mock a much bigger response object, and not have to deal with precisely modeling it, as that could lead to unforeseen issues.
Is there some kind of serializer that I can use to convert a JSON object into an ElasticSearch.NET search response object, or even a single aggregation dictionary?