-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryOptionTests.cs
More file actions
170 lines (143 loc) · 5.64 KB
/
QueryOptionTests.cs
File metadata and controls
170 lines (143 loc) · 5.64 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using Couchbase.AnalyticsClient.Options;
using Couchbase.AnalyticsClient.Query;
using Couchbase.Core.Json;
using Xunit;
namespace Couchbase.AnalyticsClient.UnitTests.Internal;
public class QueryOptionTests
{
private static QueryOptions CreateBaseline()
{
return new QueryOptions()
.WithAsStreaming(false)
.WithTimeout(TimeSpan.FromSeconds(7))
.WithClientContextId("ctx-1")
.WithScanConsistency(QueryScanConsistency.NotBounded)
.WithReadOnly(true)
.WithMaxRetries(3)
.WithNamedParameters(new Dictionary<string, object> { ["a"] = 1 })
.WithNamedParameter("b", 2)
.WithPositionalParameters(["x"])
.WithPositionalParameter("y")
.WithRawParameters(new Dictionary<string, object> { ["foo"] = "bar" })
.WithRaw("baz", 9)
.WithDeserializer(new StjJsonDeserializer());
}
[Fact]
public void WithAsStreaming_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithAsStreaming(true);
Assert.NotSame(options, updated);
Assert.False(options.AsStreaming);
Assert.True(updated.AsStreaming);
}
[Fact]
public void WithTimeout_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var newTimeout = TimeSpan.FromSeconds(30);
var updated = options.WithTimeout(newTimeout);
Assert.NotSame(options, updated);
Assert.Equal(TimeSpan.FromSeconds(7), options.Timeout);
Assert.Equal(newTimeout, updated.Timeout);
}
[Fact]
public void WithClientContextId_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithClientContextId("ctx-2");
Assert.NotSame(options, updated);
Assert.Equal("ctx-1", options.ClientContextId);
Assert.Equal("ctx-2", updated.ClientContextId);
}
[Fact]
public void WithScanConsistency_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithScanConsistency(QueryScanConsistency.RequestPlus);
Assert.NotSame(options, updated);
Assert.Equal(QueryScanConsistency.NotBounded, options.ScanConsistency);
Assert.Equal(QueryScanConsistency.RequestPlus, updated.ScanConsistency);
}
[Fact]
public void WithReadOnly_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithReadOnly(false);
Assert.NotSame(options, updated);
Assert.True(options.ReadOnly);
Assert.False(updated.ReadOnly);
}
[Fact]
public void WithMaxRetries_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithMaxRetries(10);
Assert.NotSame(options, updated);
Assert.Equal((uint)3, options.MaxRetries);
Assert.Equal((uint)10, updated.MaxRetries);
}
[Fact]
public void WithNamedParameters_Replaces_Set_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var newSet = new Dictionary<string, object> { ["c"] = 3 };
var updated = options.WithNamedParameters(newSet);
Assert.NotSame(options, updated);
Assert.Contains("a", options.NamedParameters);
Assert.Contains("b", options.NamedParameters);
Assert.DoesNotContain("c", options.NamedParameters);
Assert.Single(updated.NamedParameters);
Assert.Equal(3, updated.NamedParameters["c"]);
}
[Fact]
public void WithNamedParameter_Updates_Copy_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithNamedParameter("d", 4);
Assert.NotSame(options, updated);
Assert.DoesNotContain("d", options.NamedParameters);
Assert.Equal(4, updated.NamedParameters["d"]);
Assert.Equal(2, updated.NamedParameters["b"]);
}
[Fact]
public void WithPositionalParameters_Replaces_Set_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithPositionalParameters([1, 2, 3]);
Assert.NotSame(options, updated);
Assert.Equal(["x", "y"], options.PositionalParameters);
Assert.Equal([1, 2, 3], updated.PositionalParameters);
}
[Fact]
public void WithPositionalParameter_Appends_Copy_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithPositionalParameter("z");
Assert.NotSame(options, updated);
Assert.Equal(["x", "y"], options.PositionalParameters);
Assert.Equal(["x", "y", "z"], updated.PositionalParameters);
}
[Fact]
public void WithRawParameters_Replaces_Set_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var newSet = new Dictionary<string, object> { ["alpha"] = 1 };
var updated = options.WithRawParameters(newSet);
Assert.NotSame(options, updated);
Assert.Contains("foo", options.Raw);
Assert.DoesNotContain("alpha", options.Raw);
Assert.Single(updated.Raw);
Assert.Equal(1, updated.Raw["alpha"]);
}
[Fact]
public void WithRaw_AddsOrUpdates_ReturnsNew_And_DoesNotMutatePrevious()
{
var options = CreateBaseline();
var updated = options.WithRaw("hello", "world");
Assert.NotSame(options, updated);
Assert.DoesNotContain("hello", options.Raw);
Assert.Equal("world", updated.Raw["hello"]);
Assert.Equal("bar", updated.Raw["foo"]);
}
}