Skip to content

Commit 83a5842

Browse files
committed
test: enumeration support (complex type)
1 parent 25c8c6e commit 83a5842

File tree

1 file changed

+84
-6
lines changed

1 file changed

+84
-6
lines changed

tests/QueryableValues.SqlServer.Tests/Integration/ComplexTypeTests.cs

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class ComplexTypeTests
1313
{
1414
protected readonly IMyDbContext _db;
1515

16-
public class TestType
16+
class TestType
1717
{
1818
public bool BooleanValue { get; set; }
1919
public bool? BooleanNullableValue { get; set; }
@@ -37,6 +37,14 @@ public class TestType
3737
public DateTimeOffset? DateTimeOffsetNullableValue { get; set; }
3838
public Guid GuidValue { get; set; }
3939
public Guid? GuidNullableValue { get; set; }
40+
public ByteEnum ByteEnumValue { get; set; }
41+
public ByteEnum? ByteEnumNullableValue { get; set; }
42+
public Int16Enum Int16EnumValue { get; set; }
43+
public Int16Enum? Int16EnumNullableValue { get; set; }
44+
public Int32Enum Int32EnumValue { get; set; }
45+
public Int32Enum? Int32EnumNullableValue { get; set; }
46+
public Int64Enum Int64EnumValue { get; set; }
47+
public Int64Enum? Int64EnumNullableValue { get; set; }
4048
public char CharValue { get; set; }
4149
public char? CharNullableValue { get; set; }
4250
public char CharUnicodeValue { get; set; }
@@ -53,6 +61,38 @@ public struct TestEntityStruct
5361
public string Greeting { get; set; }
5462
}
5563

64+
enum ByteEnum : byte
65+
{
66+
None,
67+
A,
68+
B,
69+
C
70+
}
71+
72+
enum Int16Enum : short
73+
{
74+
None,
75+
A,
76+
B,
77+
C
78+
}
79+
80+
enum Int32Enum
81+
{
82+
None,
83+
A,
84+
B,
85+
C
86+
}
87+
88+
enum Int64Enum : long
89+
{
90+
None,
91+
A,
92+
B,
93+
C
94+
}
95+
5696
public ComplexTypeTests(DbContextFixture contextFixture)
5797
{
5898
_db = contextFixture.Db;
@@ -236,7 +276,15 @@ public async Task MustMatchSequenceOfTestTypeUsesConfiguration()
236276
CharValue = 'a',
237277
CharUnicodeValue = '☢',
238278
StringValue = "Lorem ipsum dolor sit amet",
239-
StringUnicodeValue = "😀👋"
279+
StringUnicodeValue = "😀👋",
280+
ByteEnumValue = ByteEnum.A,
281+
ByteEnumNullableValue = ByteEnum.B,
282+
Int16EnumValue = Int16Enum.A,
283+
Int16EnumNullableValue = Int16Enum.B,
284+
Int32EnumValue = Int32Enum.A,
285+
Int32EnumNullableValue =Int32Enum.B,
286+
Int64EnumValue = Int64Enum.A,
287+
Int64EnumNullableValue = Int64Enum.B
240288
},
241289
new TestType
242290
{
@@ -258,13 +306,21 @@ public async Task MustMatchSequenceOfTestTypeUsesConfiguration()
258306
CharNullableValue = '1',
259307
CharUnicodeValue = '☃',
260308
CharUnicodeNullableValue = '☢',
261-
StringValue = ""
309+
StringValue = "",
310+
ByteEnumValue = ByteEnum.None,
311+
Int16EnumValue = Int16Enum.A,
312+
Int32EnumValue = Int32Enum.B,
313+
Int64EnumValue = Int64Enum.C
262314
},
263315
new TestType
264316
{
265317
DecimalValue = 0.00M,
266318
CharValue = ' ',
267-
CharUnicodeValue = ' '
319+
CharUnicodeValue = ' ',
320+
ByteEnumNullableValue = ByteEnum.None,
321+
Int16EnumNullableValue = Int16Enum.A,
322+
Int32EnumNullableValue =Int32Enum.B,
323+
Int64EnumNullableValue = Int64Enum.C
268324
}
269325
};
270326

@@ -600,6 +656,28 @@ orderby td.Id
600656
Assert.Equal(expected, actual);
601657
}
602658

659+
[Fact]
660+
public async Task JoinWithEnumInt32()
661+
{
662+
var values = new[]
663+
{
664+
new { Id = 1, Value = TestEnum.None },
665+
new { Id = 3, Value = TestEnum.Value3 }
666+
};
667+
668+
var expected = new[] { 1, 3 };
669+
670+
var query =
671+
from td in _db.TestData
672+
join v in _db.AsQueryableValues(values) on new { td.Id, Value = td.EnumValue } equals new { v.Id, v.Value }
673+
orderby td.Id
674+
select td.Id;
675+
676+
var actual = await query.ToListAsync();
677+
678+
Assert.Equal(expected, actual);
679+
}
680+
603681
[Fact]
604682
public async Task JoinWithChar()
605683
{
@@ -812,12 +890,12 @@ orderby td.Id
812890
select td;
813891

814892
var actual = await query.ToListAsync();
815-
893+
816894
Assert.Equal(2, actual.Count);
817895

818896
Assert.Equal(1, actual[0].Id);
819897
Assert.Equal(2, actual[0].ChildEntity.Count);
820-
898+
821899
Assert.Equal(3, actual[1].Id);
822900
Assert.Equal(1, actual[1].ChildEntity.Count);
823901
}

0 commit comments

Comments
 (0)