public void Test_RequestID() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; Assert.AreEqual("ca692d83-1e09-4a87-ab66-cfd9f2c4a898", response.RequestId.ToString()); }
public void Test_ClientContextID() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; Assert.AreEqual("7::8", response.ClientContextId); }
public void Test_Any() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; Assert.IsTrue(response.Any()); }
public void Test_Count() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; Assert.AreEqual(10, response.Count()); }
public void Test_Success_ErrorQuery() { var stream = ResourceHelper.ReadResourceAsStream("Data\\errors_and_warnings.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; Assert.AreEqual(false, response.Success); }
public void Test_Success_SuccessfulQuery_BeforeEnumeration() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; Assert.AreEqual(true, response.Success); }
public void Test_Enumeration_BreweriesAndBeers() { var stream = ResourceHelper.ReadResourceAsStream("Data\\success_5.json"); var response = new StreamingQueryResult <dynamic> { ResponseStream = stream }; Assert.IsTrue(response.Any()); }
public void Test_Enumeration_NoClientId() { var stream = ResourceHelper.ReadResourceAsStream("Data\\no_client_id.json"); var response = new StreamingQueryResult <dynamic> { ResponseStream = stream }; Assert.IsNull(response.ClientContextId); }
public void Test_Enumeration_Errors() { var stream = ResourceHelper.ReadResourceAsStream("Data\\errors_and_warnings.json"); var response = new StreamingQueryResult <dynamic> { ResponseStream = stream }; Assert.IsNotEmpty(response.Errors); }
public void Test_Enumeration_ZeroResults() { var stream = ResourceHelper.ReadResourceAsStream("Data\\success_0.json"); var response = new StreamingQueryResult <dynamic> { ResponseStream = stream }; Assert.IsFalse(response.Any()); }
public void Test_First() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; var first = response.First(); Assert.IsNotNull(first); }
public async Task GetAsyncEnumerator_HasNotInitialized_InvalidOperationException() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-200-success.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); // Act/Assert await Assert.ThrowsAsync <InvalidOperationException>(() => streamingResult.ToListAsync().AsTask()); }
public void Test_Success() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; response.ForceRead(); Assert.AreEqual(true, response.Success); }
public void Test_Enumeration_ParseError() { var stream = ResourceHelper.ReadResourceAsStream("Data\\parse_error.json"); var response = new StreamingQueryResult <dynamic> { ResponseStream = stream }; response.ForceRead(); Assert.AreEqual(response.Errors.First().Name, "parse_error"); }
public void Test_Success_SuccessfulQuery_AfterEnumeration() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; // ReSharper disable once UnusedVariable var temp = response.ToList(); Assert.AreEqual(true, response.Success); }
public async Task GetAsyncEnumerator_ErrorAfterResults_13014_Throws_AuthenticationException(string filename) { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(filename); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer(), ErrorContextFactory); streamingResult.Success = true; // In this scenario we're getting a 200, so Success will be set to true await streamingResult.InitializeAsync(); // Act/Assert await Assert.ThrowsAsync <AuthenticationFailureException>(() => streamingResult.ToListAsync().AsTask()); }
public void Test_Enumeration_NoPretty() { var stream = ResourceHelper.ReadResourceAsStream("Data\\no_pretty.json"); var response = new StreamingQueryResult <dynamic> { ResponseStream = stream }; foreach (var item in response) { Assert.IsNotNull(item); } }
public async Task GetAsyncEnumerator_CalledTwice_StreamAlreadyReadException() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-200-success.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer(), ErrorContextFactory); await streamingResult.InitializeAsync(); // Act/Assert await streamingResult.ToListAsync(); await Assert.ThrowsAsync <StreamAlreadyReadException>(() => streamingResult.ToListAsync().AsTask()); }
public async Task GetAsyncEnumerator_CalledTwice_StreamAlreadyReadException(string filename) { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(filename); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); await streamingResult.InitializeAsync(); // Act/Assert await streamingResult.ToListAsync(); await Assert.ThrowsAsync <StreamAlreadyReadException>(() => streamingResult.ToListAsync().AsTask()); }
public void Test_Metrics() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; response.ForceRead(); Assert.AreEqual("90.385425ms", response.Metrics.ElaspedTime); Assert.AreEqual("90.322896ms", response.Metrics.ExecutionTime); Assert.AreEqual(10, response.Metrics.ResultCount); Assert.AreEqual(7262, response.Metrics.ResultSize); }
public async Task GetAsyncEnumerator_NoResults_Empty() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-n1ql-error-response-400.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); await streamingResult.InitializeAsync(); // Act var result = await streamingResult.ToListAsync(); // Assert Assert.Empty(result); }
public async Task ShouldRetry_Handles_Retry_Cases(string fileName, bool enableEnhancedPreparedStatements, bool shouldRetry) { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(fileName); using var blockResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); await blockResult.InitializeAsync().ConfigureAwait(false); // Act var actual = blockResult.ShouldRetry(enableEnhancedPreparedStatements); // Assert Assert.Equal(shouldRetry, actual); }
public async Task GetAsyncEnumerator_NoResults_Empty() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-200-success-empty.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer(), ErrorContextFactory); await streamingResult.InitializeAsync(); // Act var result = await streamingResult.ToListAsync(); // Assert Assert.Empty(result); }
public async Task InitializeAsync_Success_PreResultFieldsPresent() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-200-success.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); // Act await streamingResult.InitializeAsync(); // Assert Assert.Equal("b7a6b094-4699-4edb-b576-9092ab1404cb", streamingResult.MetaData.RequestId); Assert.Equal("1e6df61d-29ef-4821-9e49-02b3edd06ce5", streamingResult.MetaData.ClientContextId); Assert.NotNull(streamingResult.MetaData.Signature); }
public async Task InitializeAsync_NoResults_HasErrors(string filename, QueryStatus expectedStatus) { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(filename); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer(), ErrorContextFactory); // Act await streamingResult.InitializeAsync(); // Assert Assert.False(streamingResult.Success); Assert.Equal(expectedStatus, streamingResult.MetaData.Status); Assert.NotEmpty(streamingResult.Errors); }
public async Task GetAsyncEnumerator_HasInitialized_GetsResults() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-200-success.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); await streamingResult.InitializeAsync(); // Act var result = await streamingResult.ToListAsync(); // Assert Assert.True(streamingResult.Success); Assert.Equal(QueryStatus.Success, streamingResult.MetaData.Status); Assert.NotEmpty(result); }
public async Task InitializeAsync_Error_CreateIndexInternalServerError() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-create-index-500.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); // Act await streamingResult.InitializeAsync(); // Assert Assert.Equal("d5017926-d7a4-41bf-bb13-b788885f9c08", streamingResult.MetaData.RequestId); Assert.NotEmpty(streamingResult.Errors); Assert.Equal(QueryStatus.Errors, streamingResult.MetaData.Status); Assert.NotNull(streamingResult.MetaData.Metrics); }
public async Task InitializeAsync_Error_AllResultFieldsPresent() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-n1ql-error-response-400.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer()); // Act await streamingResult.InitializeAsync(); // Assert Assert.Equal("922edd9a-23d7-4053-8d60-91f7cbc22c83", streamingResult.MetaData.RequestId); Assert.NotEmpty(streamingResult.Errors); Assert.Equal(QueryStatus.Fatal, streamingResult.MetaData.Status); Assert.NotNull(streamingResult.MetaData.Metrics); Assert.Equal("134.7944us", streamingResult.MetaData.Metrics.ElaspedTime); }
public void Test_SecondEnumeration_AfterRegularRead_ThrowsStreamAlreadyReadException() { var stream = ResourceHelper.ReadResourceAsStream("Data\\n1ql-response.json"); var response = new StreamingQueryResult <Beer> { ResponseStream = stream }; //read the results var count = 0; foreach (var beer in response) { count++; } Assert.AreEqual(10, count); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Assert.Throws <StreamAlreadyReadException>(() => response.ToList()); }
public async Task InitializeAsync_ErrorAfterEmptyResults_HasErrors() { // Arrange using var stream = ResourceHelper.ReadResourceAsStream(@"Documents\Query\query-200-errors-after-empty-results.json"); using var streamingResult = new StreamingQueryResult <dynamic>(stream, new DefaultSerializer(), ErrorContextFactory); streamingResult.Success = true; // In this scenario we're getting a 200, so Success will be set to true await streamingResult.InitializeAsync(); // Act await streamingResult.InitializeAsync(); // Assert Assert.False(streamingResult.Success); Assert.Equal(QueryStatus.Fatal, streamingResult.MetaData.Status); Assert.NotEmpty(streamingResult.Errors); }