public static async Task LogsDebugMessagesDuringExecution()
        {
            var client = Substitute.For<IElasticsearchClient>();

            var responseString = BuildResponseString(2, 1, 1, 0.3141, "testIndex", "testType", "testId");
            var spyLog = new SpyLog();

            client.SearchAsync<string>(
                    "SearchIndex",
                    "abc123",
                    @"{""size"":2112,""timeout"":""10s""}",
                    Arg.Any<Func<SearchRequestParameters, SearchRequestParameters>>())
                .Returns(Task.FromResult(ElasticsearchResponse<string>.Create(
                    new ConnectionConfiguration(),
                    200,
                    "_search",
                    "http://localhost/SearchIndex/abc123/_search",
                    new byte[0],
                    responseString)));

            var localConnection = new ElasticNetConnection(client, index: "SearchIndex");
            var request = new SearchRequest { DocumentType = "abc123", Size = 2112 };
            var formatter = new SearchRequestFormatter(localConnection, mapping, request);

            await localConnection.SearchAsync(
                formatter.Body,
                request,
                CancellationToken.None,
                spyLog);

            Assert.Equal(4, spyLog.Entries.Count);
            Assert.Equal(@"Request: POST http://localhost/SearchIndex/abc123/_search", spyLog.Entries[0].Message);
            Assert.Equal(@"Body:" + '\n' + @"{""size"":2112,""timeout"":""10s""}", spyLog.Entries[1].Message);
            Assert.True(new Regex(@"Response: 200 OK \(in \d+ms\)").Match(spyLog.Entries[2].Message).Success);
            Assert.True(new Regex(@"Deserialized \d+ characters into 1 hits in \d+ms").Match(spyLog.Entries[3].Message).Success);
        }
        public static async void SearchAsyncThrowsTaskCancelledExceptionWithAlreadyCancelledCancellationToken()
        {
            var client = Substitute.For<IElasticsearchClient>();

            var spyLog = new SpyLog();
            var localConnection = new ElasticNetConnection(client, "SearchIndex");
            var request = new SearchRequest { DocumentType = "docType" };
            var formatter = new SearchRequestFormatter(localConnection, mapping, request);

            var ex = await Record.ExceptionAsync(() => localConnection.SearchAsync(
                formatter.Body,
                request,
                new CancellationToken(true),
                spyLog));

            Assert.IsType<TaskCanceledException>(ex);
        }