-
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to value type LINQ querying. Closes GH-3450
- Loading branch information
1 parent
c82ea9e
commit 4e33cec
Showing
4 changed files
with
198 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Marten; | ||
using Marten.Testing.Harness; | ||
using Vogen; | ||
using Shouldly; | ||
|
||
namespace ValueTypeTests.Bugs; | ||
|
||
public class querying_by_value_types : BugIntegrationContext | ||
{ | ||
[Fact] | ||
public async Task run_queries() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.RegisterValueType(typeof(EmailAddress)); | ||
opts.RegisterValueType(typeof(Age)); | ||
}); | ||
|
||
var customer = new Customer | ||
{ | ||
Email = EmailAddress.From("[email protected]"), | ||
Age = Age.From(25) | ||
}; | ||
|
||
theSession.Store(customer); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
var loadedCustomer = await theSession.LoadAsync<Customer>(customer.Id); | ||
|
||
loadedCustomer.Email.ShouldNotBeNull(); | ||
loadedCustomer.Email.Value.ShouldBe("[email protected]"); | ||
|
||
|
||
var queryByAge = await theSession.Query<Customer>() | ||
.FirstOrDefaultAsync(x => x.Age == 25); | ||
|
||
queryByAge.ShouldNotBeNull(); | ||
|
||
var queryByEmail = await theSession.Query<Customer>() | ||
.FirstOrDefaultAsync(x => x.Email == customer.Email); | ||
|
||
queryByEmail.ShouldNotBeNull(); | ||
} | ||
} | ||
|
||
[ValueObject<string>] | ||
public partial record EmailAddress; | ||
|
||
[ValueObject<int>] | ||
public partial record Age; | ||
|
||
public class Customer | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public required EmailAddress Email { get; init; } | ||
|
||
public required Age Age { get; init; } | ||
} |