From 79dc08e057e10c696e0341d5afd2824f7a3d1c83 Mon Sep 17 00:00:00 2001 From: Paul DeVito Date: Tue, 20 Feb 2024 16:25:07 -0500 Subject: [PATCH] refactor: more tests --- .../Tests/DatabaseFilteringTests.cs | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs b/QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs index aa0cf92..3affdfa 100644 --- a/QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs +++ b/QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs @@ -276,6 +276,34 @@ public async Task can_filter_by_datetime_with_milliseconds() people[0].Id.Should().Be(fakePersonOne.Id); } + [Fact] + public async Task can_filter_by_datetime_with_milliseconds_full_fractional() + { + // Arrange + var testingServiceScope = new TestingServiceScope(); + var dateUtcNow = DateTime.UtcNow; + var dateInMilliPast = dateUtcNow.AddMilliseconds(-100); + var fakePersonOne = new FakeTestingPersonBuilder() + .WithSpecificDateTime(dateUtcNow) + .Build(); + var fakePersonTwo = new FakeTestingPersonBuilder() + .WithSpecificDateTime(dateInMilliPast) + .Build(); + await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo); + + var input = $"""SpecificDateTime == "{fakePersonOne.SpecificDateTime:o}" """; + + // Act + var queryablePeople = testingServiceScope.DbContext().People; + + var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input); + var people = await appliedQueryable.ToListAsync(); + + // Assert + people.Count.Should().Be(1); + people[0].Id.Should().Be(fakePersonOne.Id); + } + [Fact] public async Task can_filter_by_dateonly() { @@ -843,7 +871,65 @@ public async Task can_filter_with_child_props_for_complex_property() var queryablePeople = testingServiceScope.DbContext().Recipes; var config = new QueryKitConfiguration(config => { - config.Property(x => x.CollectionEmail.Value);//.HasQueryName("email"); + config.Property(x => x.CollectionEmail.Value); + }); + var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config); + var people = await appliedQueryable.ToListAsync(); + + // Assert + people.Count.Should().Be(1); + people[0].Id.Should().Be(fakePersonOne.Id); + } + + [Fact] + public async Task can_filter_with_child_props_for_aliased_complex_property() + { + // Arrange + var testingServiceScope = new TestingServiceScope(); + var faker = new Faker(); + var fakePersonOne = new FakeRecipeBuilder() + .WithCollectionEmail(faker.Internet.Email()) + .Build(); + var fakePersonTwo = new FakeRecipeBuilder() + .Build(); + await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo); + + var input = $"""email == "{fakePersonOne.CollectionEmail.Value}" """; + + // Act + var queryablePeople = testingServiceScope.DbContext().Recipes; + var config = new QueryKitConfiguration(config => + { + config.Property(x => x.CollectionEmail.Value).HasQueryName("email"); + }); + var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config); + var people = await appliedQueryable.ToListAsync(); + + // Assert + people.Count.Should().Be(1); + people[0].Id.Should().Be(fakePersonOne.Id); + } + + [Fact] + public async Task can_filter_with_child_props_for_null_aliased_complex_property() + { + // Arrange + var testingServiceScope = new TestingServiceScope(); + var faker = new Faker(); + var fakePersonOne = new FakeRecipeBuilder() + .WithCollectionEmail(null) + .Build(); + var fakePersonTwo = new FakeRecipeBuilder() + .Build(); + await testingServiceScope.InsertAsync(fakePersonOne, fakePersonTwo); + + var input = $"""email == null"""; + + // Act + var queryablePeople = testingServiceScope.DbContext().Recipes; + var config = new QueryKitConfiguration(config => + { + config.Property(x => x.CollectionEmail.Value).HasQueryName("email"); }); var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config); var people = await appliedQueryable.ToListAsync();