Skip to content

Filtering on a DateOnly struct doesn't filter list #179

@pdevito3

Description

@pdevito3

Describe the bug
Filtering by DateOnly does not work

To Reproduce
Filtering by a DateTime works:

[Test]
    public async Task can_filter_author_list_using_date()
    {
        //Arrange
        var DateTimeNow = DateTime.Now;
        var fakeAuthorOne = FakeAuthor.Generate(new FakeAuthorForCreationDto()
            .RuleFor(a => a.Dob, f => f.Date.Past())            
            .Generate());
        var fakeAuthorTwo = FakeAuthor.Generate(new FakeAuthorForCreationDto()
            .RuleFor(a => a.Dob, _ => DateTimeNow)            
            .Generate());
        var author = new List<Author>();
        author.Add(fakeAuthorOne);
        author.Add(fakeAuthorTwo);
        var mockDbData = author.AsQueryable().BuildMock();
        var queryParameters = new AuthorParametersDto() { Filters = $"Dob>={DateTimeNow}" };

        _authorRepository
            .Setup(x => x.Query())
            .Returns(mockDbData);

        //Act
        var query = new GetAuthorList.AuthorListQuery(queryParameters);
        var handler = new GetAuthorList.Handler(_authorRepository.Object, _mapper, _sieveProcessor);
        var authors = await handler.Handle(query, CancellationToken.None);

        // Assert
        authors.Should().HaveCount(1);
        authors
            .FirstOrDefault()
            .Should().BeEquivalentTo(fakeAuthorTwo, options =>
                options.ExcludingMissingMembers()
                    .Excluding(x => x.PhysicalAddress));
    }

but using the same setup for a DateOnly does not filter a list

[Test]
    public async Task can_filter_author_list_using_dateonly()
    {
        //Arrange
        var dateOnlyNow = DateOnly.FromDateTime(DateTime.Now);
        var fakeAuthorOne = FakeAuthor.Generate(new FakeAuthorForCreationDto()
            .RuleFor(a => a.DayWorldEnds, f => f.Date.PastDateOnly())            
            .Generate());
        var fakeAuthorTwo = FakeAuthor.Generate(new FakeAuthorForCreationDto()
            .RuleFor(a => a.DayWorldEnds, _ => dateOnlyNow)            
            .Generate());
        var author = new List<Author>();
        author.Add(fakeAuthorOne);
        author.Add(fakeAuthorTwo);
        var mockDbData = author.AsQueryable().BuildMock();
        var queryParameters = new AuthorParametersDto() { Filters = $"DayWorldEnds>={DateOnlyNow}" };

        _authorRepository
            .Setup(x => x.Query())
            .Returns(mockDbData);

        //Act
        var query = new GetAuthorList.AuthorListQuery(queryParameters);
        var handler = new GetAuthorList.Handler(_authorRepository.Object, _mapper, _sieveProcessor);
        var authors = await handler.Handle(query, CancellationToken.None);

        // Assert
        authors.Should().HaveCount(1);
        authors
            .FirstOrDefault()
            .Should().BeEquivalentTo(fakeAuthorTwo, options =>
                options.ExcludingMissingMembers()
                    .Excluding(x => x.PhysicalAddress));
    }

Expected behavior
The list should be filtered by matching records on the DateOnly prop

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions