Skip to content

Commit

Permalink
refactor: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pdevito3 committed Feb 20, 2024
1 parent 154ad45 commit 79dc08e
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<Recipe>(x => x.CollectionEmail.Value);//.HasQueryName("email");
config.Property<Recipe>(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<Recipe>(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<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
});
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config);
var people = await appliedQueryable.ToListAsync();
Expand Down

0 comments on commit 79dc08e

Please sign in to comment.