-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamingAnalyticsResultTests.cs
More file actions
86 lines (71 loc) · 2.41 KB
/
StreamingAnalyticsResultTests.cs
File metadata and controls
86 lines (71 loc) · 2.41 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Text.Json;
using Couchbase.AnalyticsClient.Internal.Results;
using Couchbase.AnalyticsClient.Json;
using Couchbase.Core.Json;
using Moq;
using Xunit;
using Xunit.Abstractions;
namespace Couchbase.AnalyticsClient.UnitTests.Internal;
public class StreamingAnalyticsResultTests
{
private readonly ITestOutputHelper _output;
public StreamingAnalyticsResultTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public async Task StreamingAnalyticsResult_DeserializesCorrectly()
{
var json = File.ReadAllBytes("JsonDocuments/analyticsResponse.json");
var stream = new MemoryStream(json);
var analyticsResult = new StreamingAnalyticsResult(stream,new StjJsonDeserializer(), new Mock<IDisposable?>().Object);
await analyticsResult.InitializeAsync(CancellationToken.None);
var airlines = await analyticsResult.ToListAsync();
Assert.NotNull(airlines);
Assert.NotEmpty(airlines);
}
public class Root
{
public Airline airline { get; set; }
}
public class Airline
{
public int id { get; set; }
public string type { get; set; }
public string name { get; set; }
public string iata { get; set; }
public string icao { get; set; }
public string callsign { get; set; }
public string country { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
[Fact]
public void Constructor_InitializesCorrectly()
{
// Arrange
var mockStream = new MemoryStream();
var mockDisposable = new Mock<IDeserializer>();
// Act
var result = new StreamingAnalyticsResult(mockStream, mockDisposable.Object);
// Assert
Assert.NotNull(result);
}
[Fact]
public async Task InitializeAsync_CompletesSuccessfully()
{
// Arrange
var mockStream = new MemoryStream();
var mockSerializer = new Mock<IDeserializer>();
mockSerializer.Setup(x=>x.CreateJsonStreamReader(It.IsAny<Stream>(),
It.IsAny<CancellationToken>()))
.Returns(new Mock<IJsonStreamReader>().Object);
var result = new StreamingAnalyticsResult(mockStream, mockSerializer.Object);
// Act
await result.InitializeAsync();
// Assert
Assert.True(true); // No exception should be thrown
}
}