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

extra test to verify FirstOrDefaultAsync() behavior. Closes GH-3374 #3376

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/LinqTests/Operators/first_operator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Marten;
using Marten.Testing.Documents;
using Marten.Testing.Harness;
using Microsoft.Extensions.Logging;
using Shouldly;
using Xunit.Abstractions;

Expand Down Expand Up @@ -158,6 +160,36 @@ public async Task first_or_default_correct_hit_with_more_than_one_match_async()
target.Flag.ShouldBeTrue();
}

[Fact]
public async Task first_or_default_correct_hit_with_more_than_one_match_async_in_combo_with_order_by()
{
theSession.Store(new Target { Number = 1, AnotherNumber = 10});
theSession.Store(new Target { Number = 2, Flag = true, AnotherNumber = 30, String = "Correct" });
theSession.Store(new Target { Number = 2, AnotherNumber = 20, String = "Wrong"});
theSession.Store(new Target { Number = 4 });
await theSession.SaveChangesAsync();

theSession.Logger = new TestOutputMartenLogger(_output);

var target = await theSession.Query<Target>().Where(x => x.Number == 2).OrderByDescending(x => x.AnotherNumber).FirstOrDefaultAsync();
target.String.ShouldBe("Correct");
}

[Fact]
public async Task first_or_default_correct_hit_with_more_than_one_match_async_in_combo_with_order_by_2()
{
theSession.Store(new Target { Number = 1, AnotherNumber = 10});
theSession.Store(new Target { Number = 2, Flag = true, AnotherNumber = 30, String = "Correct" });
theSession.Store(new Target { Number = 2, AnotherNumber = 20, String = "Wrong"});
theSession.Store(new Target { Number = 4 });
await theSession.SaveChangesAsync();

theSession.Logger = new TestOutputMartenLogger(_output);

var target = await theSession.Query<Target>().OrderByDescending(x => x.AnotherNumber).FirstOrDefaultAsync(x => x.Number == 2, CancellationToken.None);
target.String.ShouldBe("Correct");
}

[Fact]
public async Task first_miss_async()
{
Expand Down
Loading