-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockingAnalyticsResultTests.cs
More file actions
66 lines (54 loc) · 1.97 KB
/
BlockingAnalyticsResultTests.cs
File metadata and controls
66 lines (54 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Couchbase.AnalyticsClient.Internal.Results;
using Couchbase.Core.Json;
using Xunit;
namespace Couchbase.AnalyticsClient.UnitTests.Internal;
public class BlockingAnalyticsResultTest
{
[Fact]
public async Task InitializeAsync_ShouldReadResponseStream()
{
// Arrange
var json = File.ReadAllBytes("JsonDocuments/analyticsResponse.json");
var stream = new MemoryStream(json);
var result = new BlockingAnalyticsResult(stream, new StjJsonDeserializer());
// Act
await result.InitializeAsync();
// Assert
// No exception should be thrown, and the method should complete successfully.
}
[Fact]
public async Task Error_23000_ShouldHaveErrorMessageAndCode()
{
// Arrange
var json = File.ReadAllBytes("JsonDocuments/error-23000-response.json");
var stream = new MemoryStream(json);
var result = new BlockingAnalyticsResult(stream, new StjJsonDeserializer());
// Act
await result.InitializeAsync();
// Assert
Assert.Single(result.Errors);
var error = result.Errors[0];
Assert.Equal("Enterprise Analytics is temporarily unavailable", error.Message);
Assert.Equal(23000, error.Code);
Assert.True(error.Retriable);
}
[Fact]
public async Task GetAsyncEnumerator_ShouldThrowNotImplementedException()
{
// Arrange
var stream = new MemoryStream();
var result = new BlockingAnalyticsResult(stream, new StjJsonDeserializer());
// Act & Assert
await Assert.ThrowsAsync<InvalidOperationException>(async () => await result.GetAsyncEnumerator().MoveNextAsync().ConfigureAwait(false));
}
[Fact]
public void Constructor_ShouldInitializeProperties()
{
// Arrange
var stream = new MemoryStream();
// Act
var result = new BlockingAnalyticsResult(stream, new StjJsonDeserializer());
// Assert
Assert.NotNull(result);
}
}