Skip to content

Commit 662ff59

Browse files
committed
build: add integration tests to cover enums
1 parent 783b387 commit 662ff59

1 file changed

Lines changed: 101 additions & 1 deletion

File tree

QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,4 +967,104 @@ public async Task can_filter_with_child_props_for_complex_property_with_alias()
967967
people.Count.Should().Be(1);
968968
people[0].Id.Should().Be(fakePersonOne.Id);
969969
}
970-
}
970+
971+
[Fact]
972+
public async Task can_filter_by_enum_name()
973+
{
974+
// Arrange
975+
var testingServiceScope = new TestingServiceScope();
976+
var faker = new Faker();
977+
var fakePersonOne = new FakeTestingPersonBuilder()
978+
.WithTitle(faker.Lorem.Sentence())
979+
.WithBirthMonth(BirthMonthEnum.January)
980+
.Build();
981+
var fakePersonTwo = new FakeTestingPersonBuilder().Build();
982+
await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo);
983+
984+
var input = $"""{nameof(TestingPerson.BirthMonth)} == "January" && {nameof(TestingPerson.Title)} == "{fakePersonOne.Title}" """;
985+
986+
// Act
987+
var queryablePeople = testingServiceScope.DbContext().People;
988+
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input);
989+
var people = await appliedQueryable.ToListAsync();
990+
991+
// Assert
992+
people.Count.Should().Be(1);
993+
people[0].Id.Should().Be(fakePersonOne.Id);
994+
}
995+
996+
[Fact]
997+
public async Task can_filter_by_in_enum_names()
998+
{
999+
// Arrange
1000+
var testingServiceScope = new TestingServiceScope();
1001+
var faker = new Faker();
1002+
var fakePersonOne = new FakeTestingPersonBuilder()
1003+
.WithTitle(faker.Lorem.Sentence())
1004+
.WithBirthMonth(BirthMonthEnum.January)
1005+
.Build();
1006+
var fakePersonTwo = new FakeTestingPersonBuilder().Build();
1007+
await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo);
1008+
1009+
var input = $"""{nameof(TestingPerson.BirthMonth)} ^^ ["January", "March"] && {nameof(TestingPerson.Title)} == "{fakePersonOne.Title}" """;
1010+
1011+
// Act
1012+
var queryablePeople = testingServiceScope.DbContext().People;
1013+
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input);
1014+
var people = await appliedQueryable.ToListAsync();
1015+
1016+
// Assert
1017+
people.Count.Should().Be(1);
1018+
people[0].Id.Should().Be(fakePersonOne.Id);
1019+
}
1020+
1021+
[Fact]
1022+
public async Task can_filter_by_enum_number()
1023+
{
1024+
// Arrange
1025+
var testingServiceScope = new TestingServiceScope();
1026+
var faker = new Faker();
1027+
var fakePersonOne = new FakeTestingPersonBuilder()
1028+
.WithTitle(faker.Lorem.Sentence())
1029+
.WithBirthMonth(BirthMonthEnum.June)
1030+
.Build();
1031+
var fakePersonTwo = new FakeTestingPersonBuilder().Build();
1032+
await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo);
1033+
1034+
var input = $"""{nameof(TestingPerson.BirthMonth)} == "6" && {nameof(TestingPerson.Title)} == "{fakePersonOne.Title}" """;
1035+
1036+
// Act
1037+
var queryablePeople = testingServiceScope.DbContext().People;
1038+
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input);
1039+
var people = await appliedQueryable.ToListAsync();
1040+
1041+
// Assert
1042+
people.Count.Should().Be(1);
1043+
people[0].Id.Should().Be(fakePersonOne.Id);
1044+
}
1045+
1046+
[Fact]
1047+
public async Task can_filter_by_in_enum_numbers()
1048+
{
1049+
// Arrange
1050+
var testingServiceScope = new TestingServiceScope();
1051+
var faker = new Faker();
1052+
var fakePersonOne = new FakeTestingPersonBuilder()
1053+
.WithTitle(faker.Lorem.Sentence())
1054+
.WithBirthMonth(BirthMonthEnum.January)
1055+
.Build();
1056+
var fakePersonTwo = new FakeTestingPersonBuilder().Build();
1057+
await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo);
1058+
1059+
var input = $"""{nameof(TestingPerson.BirthMonth)} ^^ ["1", "3"] && {nameof(TestingPerson.Title)} == "{fakePersonOne.Title}" """;
1060+
1061+
// Act
1062+
var queryablePeople = testingServiceScope.DbContext().People;
1063+
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input);
1064+
var people = await appliedQueryable.ToListAsync();
1065+
1066+
// Assert
1067+
people.Count.Should().Be(1);
1068+
people[0].Id.Should().Be(fakePersonOne.Id);
1069+
}
1070+
}

0 commit comments

Comments
 (0)