Skip to content

Commit 7781b29

Browse files
CopilotbaseTwo
andcommitted
Add comprehensive tests for large tuple serialization - all pass
Co-authored-by: baseTwo <[email protected]>
1 parent bb84dd2 commit 7781b29

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed

Cql/CoreTests/Primitives/TypeExtensionsTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,23 @@ public void IsCqlValueTuple_ShouldReturnFalse_WhenTypeIsNotCqlValueTuple()
6868
// Assert
6969
Assert.IsFalse(result);
7070
}
71+
72+
[TestMethod]
73+
public void IsCqlValueTuple_ShouldReturnTrue_WhenTypeIsLargeCqlValueTuple()
74+
{
75+
// Arrange - Test large tuples with more than 8 items
76+
var tuple9 = (new CqlTupleMetadata([], []), "item1", 2, 3, 4, 5, 6, 7, 8, 9);
77+
var tuple10 = (new CqlTupleMetadata([], []), "item1", 2, 3, 4, 5, 6, 7, 8, 9, 10);
78+
var tuple15 = (new CqlTupleMetadata([], []), "item1", 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
79+
80+
// Act
81+
bool result9 = tuple9.GetType().IsCqlValueTuple();
82+
bool result10 = tuple10.GetType().IsCqlValueTuple();
83+
bool result15 = tuple15.GetType().IsCqlValueTuple();
84+
85+
// Assert
86+
Assert.IsTrue(result9, "9-item tuple should be recognized as CqlValueTuple");
87+
Assert.IsTrue(result10, "10-item tuple should be recognized as CqlValueTuple");
88+
Assert.IsTrue(result15, "15-item tuple should be recognized as CqlValueTuple");
89+
}
7190
}

Cql/CoreTests/Tuples/CqlTupleTests.cs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ public class CqlTupleTests
1818
private static readonly CqlTupleMetadata SimpleTupleMetadata = new([typeof(string), typeof(int)], ["Name", "Age"]);
1919
private static readonly CqlTupleMetadata NestedTupleMetadata = new([typeof(string), typeof((CqlTupleMetadata, string, int))], ["Group", "Person"]);
2020
private static readonly CqlTupleMetadata ArrayTupleMetadata = new([typeof(string[]), typeof(int[])], ["Names", "Ages"]);
21+
22+
// Large tuple metadata for testing tuples with more than 8 items
23+
private static readonly CqlTupleMetadata LargeTuple9Metadata = new([
24+
typeof(string), typeof(int), typeof(bool), typeof(double), typeof(char),
25+
typeof(byte), typeof(short), typeof(long), typeof(decimal)
26+
], ["Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9"]);
27+
28+
private static readonly CqlTupleMetadata LargeTuple10Metadata = new([
29+
typeof(string), typeof(int), typeof(bool), typeof(double), typeof(char),
30+
typeof(byte), typeof(short), typeof(long), typeof(decimal), typeof(float)
31+
], ["Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10"]);
32+
33+
private static readonly CqlTupleMetadata LargeTuple15Metadata = new([
34+
typeof(string), typeof(int), typeof(bool), typeof(double), typeof(char),
35+
typeof(byte), typeof(short), typeof(long), typeof(decimal), typeof(float),
36+
typeof(uint), typeof(ulong), typeof(ushort), typeof(sbyte), typeof(DateTime)
37+
], ["Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10",
38+
"Item11", "Item12", "Item13", "Item14", "Item15"]);
2139

2240
private static JsonSerializerOptions JsonSerializerOptions =>
2341
FhirDeserializationExtensions.JsonSerializerOptions
@@ -153,4 +171,164 @@ public void Tuple_DeserializesFromJson_ThrowNotSupported()
153171
// Assert
154172
Assert.Throws<NotSupportedException>(act);
155173
}
174+
175+
[TestMethod]
176+
public void Tuple_With9Items_CanBeCreatedAndAccessed()
177+
{
178+
// Arrange
179+
(CqlTupleMetadata, string, int, bool, double, char, byte, short, long, decimal) tuple =
180+
(LargeTuple9Metadata, "test", 42, true, 3.14, 'X', 255, 1000, 123456789L, 99.99m);
181+
182+
// Act & Assert
183+
Assert.AreEqual(LargeTuple9Metadata, tuple.Item1);
184+
Assert.AreEqual("test", tuple.Item2);
185+
Assert.AreEqual(42, tuple.Item3);
186+
Assert.AreEqual(true, tuple.Item4);
187+
Assert.AreEqual(3.14, tuple.Item5);
188+
Assert.AreEqual('X', tuple.Item6);
189+
Assert.AreEqual((byte)255, tuple.Item7);
190+
Assert.AreEqual((short)1000, tuple.Item8);
191+
Assert.AreEqual(123456789L, tuple.Item9);
192+
Assert.AreEqual(99.99m, tuple.Item10);
193+
}
194+
195+
[TestMethod]
196+
public void Tuple_With10Items_CanBeCreatedAndAccessed()
197+
{
198+
// Arrange
199+
(CqlTupleMetadata, string, int, bool, double, char, byte, short, long, decimal, float) tuple =
200+
(LargeTuple10Metadata, "test", 42, true, 3.14, 'X', 255, 1000, 123456789L, 99.99m, 1.5f);
201+
202+
// Act & Assert
203+
Assert.AreEqual(LargeTuple10Metadata, tuple.Item1);
204+
Assert.AreEqual("test", tuple.Item2);
205+
Assert.AreEqual(42, tuple.Item3);
206+
Assert.AreEqual(true, tuple.Item4);
207+
Assert.AreEqual(3.14, tuple.Item5);
208+
Assert.AreEqual('X', tuple.Item6);
209+
Assert.AreEqual((byte)255, tuple.Item7);
210+
Assert.AreEqual((short)1000, tuple.Item8);
211+
Assert.AreEqual(123456789L, tuple.Item9);
212+
Assert.AreEqual(99.99m, tuple.Item10);
213+
Assert.AreEqual(1.5f, tuple.Item11);
214+
}
215+
216+
[TestMethod]
217+
public void Tuple_With15Items_CanBeCreatedAndAccessed()
218+
{
219+
// Arrange
220+
var testDate = new DateTime(2023, 1, 1);
221+
(CqlTupleMetadata, string, int, bool, double, char, byte, short, long, decimal, float, uint, ulong, ushort, sbyte, DateTime) tuple =
222+
(LargeTuple15Metadata, "test", 42, true, 3.14, 'X', 255, 1000, 123456789L, 99.99m, 1.5f, 4000u, 9876543210ul, 500, -50, testDate);
223+
224+
// Act & Assert
225+
Assert.AreEqual(LargeTuple15Metadata, tuple.Item1);
226+
Assert.AreEqual("test", tuple.Item2);
227+
Assert.AreEqual(42, tuple.Item3);
228+
Assert.AreEqual(true, tuple.Item4);
229+
Assert.AreEqual(3.14, tuple.Item5);
230+
Assert.AreEqual('X', tuple.Item6);
231+
Assert.AreEqual((byte)255, tuple.Item7);
232+
Assert.AreEqual((short)1000, tuple.Item8);
233+
Assert.AreEqual(123456789L, tuple.Item9);
234+
Assert.AreEqual(99.99m, tuple.Item10);
235+
Assert.AreEqual(1.5f, tuple.Item11);
236+
Assert.AreEqual(4000u, tuple.Item12);
237+
Assert.AreEqual(9876543210ul, tuple.Item13);
238+
Assert.AreEqual((ushort)500, tuple.Item14);
239+
Assert.AreEqual((sbyte)-50, tuple.Item15);
240+
Assert.AreEqual(testDate, tuple.Item16);
241+
}
242+
243+
[TestMethod]
244+
public void Tuple_With9Items_SerializesToJson()
245+
{
246+
// Arrange
247+
(CqlTupleMetadata, string, int, bool, double, char, byte, short, long, decimal) tuple =
248+
(LargeTuple9Metadata, "test", 42, true, 3.14, 'X', 255, 1000, 123456789L, 99.99m);
249+
250+
// Act
251+
var json = JsonSerializer.Serialize(tuple, JsonSerializerOptions);
252+
253+
// Assert
254+
Assert.That.MultilinesAreEqual(
255+
"""
256+
{
257+
"Item1": "test",
258+
"Item2": 42,
259+
"Item3": true,
260+
"Item4": 3.14,
261+
"Item5": "X",
262+
"Item6": 255,
263+
"Item7": 1000,
264+
"Item8": 123456789,
265+
"Item9": 99.99
266+
}
267+
""",
268+
json);
269+
}
270+
271+
[TestMethod]
272+
public void Tuple_With10Items_SerializesToJson()
273+
{
274+
// Arrange
275+
(CqlTupleMetadata, string, int, bool, double, char, byte, short, long, decimal, float) tuple =
276+
(LargeTuple10Metadata, "test", 42, true, 3.14, 'X', 255, 1000, 123456789L, 99.99m, 1.5f);
277+
278+
// Act
279+
var json = JsonSerializer.Serialize(tuple, JsonSerializerOptions);
280+
281+
// Assert
282+
Assert.That.MultilinesAreEqual(
283+
"""
284+
{
285+
"Item1": "test",
286+
"Item2": 42,
287+
"Item3": true,
288+
"Item4": 3.14,
289+
"Item5": "X",
290+
"Item6": 255,
291+
"Item7": 1000,
292+
"Item8": 123456789,
293+
"Item9": 99.99,
294+
"Item10": 1.5
295+
}
296+
""",
297+
json);
298+
}
299+
300+
[TestMethod]
301+
public void Tuple_With15Items_SerializesToJson()
302+
{
303+
// Arrange
304+
var testDate = new DateTime(2023, 1, 1);
305+
(CqlTupleMetadata, string, int, bool, double, char, byte, short, long, decimal, float, uint, ulong, ushort, sbyte, DateTime) tuple =
306+
(LargeTuple15Metadata, "test", 42, true, 3.14, 'X', 255, 1000, 123456789L, 99.99m, 1.5f, 4000u, 9876543210ul, 500, -50, testDate);
307+
308+
// Act
309+
var json = JsonSerializer.Serialize(tuple, JsonSerializerOptions);
310+
311+
// Assert
312+
Assert.That.MultilinesAreEqual(
313+
"""
314+
{
315+
"Item1": "test",
316+
"Item2": 42,
317+
"Item3": true,
318+
"Item4": 3.14,
319+
"Item5": "X",
320+
"Item6": 255,
321+
"Item7": 1000,
322+
"Item8": 123456789,
323+
"Item9": 99.99,
324+
"Item10": 1.5,
325+
"Item11": 4000,
326+
"Item12": 9876543210,
327+
"Item13": 500,
328+
"Item14": -50,
329+
"Item15": "2023-01-01T00:00:00"
330+
}
331+
""",
332+
json);
333+
}
156334
}

0 commit comments

Comments
 (0)