Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pdevito3 opened this issue Aug 6, 2022 · 1 comment
Open

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

pdevito3 opened this issue Aug 6, 2022 · 1 comment

Comments

@pdevito3
Copy link

pdevito3 commented Aug 6, 2022

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.

@genuinefafa
Copy link

I wonder how to solve this issue; If I try to do a <=2002/05/28 if something is dated 2002-05-28Z00:01:00 it is not returned.
I was wonder if I can fine tune Processor 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants