-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Linq-to-BsonExpression with BsonRef property when it inherits fro…
…m another class
- Loading branch information
1 parent
883a1dc
commit 653c8f7
Showing
2 changed files
with
70 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
using System.Linq; | ||
|
||
namespace LiteDB.Issue1651 | ||
{ | ||
public class Order : BaseEntity | ||
{ | ||
public Customer Customer { get; set; } | ||
} | ||
|
||
public class Customer : BaseEntity | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
public class BaseEntity | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
public class CustomerRelationshipsTests | ||
{ | ||
[Fact] | ||
public void Find_ByRelationId_Success() | ||
{ | ||
BsonMapper.Global.Entity<Order>().DbRef(order => order.Customer); | ||
|
||
using var _database = new LiteDatabase(":memory:"); | ||
var _orderCollection = _database.GetCollection<Order>("Order"); | ||
var _customerCollection = _database.GetCollection<Customer>("Customer"); | ||
|
||
var customer = new Customer() { Name = "John", }; | ||
|
||
Assert.True(_customerCollection.Upsert(customer)); | ||
Assert.True(_customerCollection.Upsert(new Customer() { Name = "Anonymous" })); | ||
|
||
Assert.NotEqual(Guid.Empty, customer.Id); | ||
|
||
var order = new Order() | ||
{ | ||
Customer = customer, | ||
}; | ||
var order2 = new Order() | ||
{ | ||
Customer = new Customer() { Id = customer.Id }, | ||
}; | ||
var orphanOrder = new Order(); | ||
|
||
Assert.True(_orderCollection.Upsert(orphanOrder)); | ||
Assert.True(_orderCollection.Upsert(order)); | ||
Assert.True(_orderCollection.Upsert(order2)); | ||
|
||
customer.Name = "Josh"; | ||
Assert.True(_customerCollection.Update(customer)); | ||
|
||
var actualOrders = _orderCollection | ||
.Include(orderEntity => orderEntity.Customer) | ||
.Find(orderEntity => orderEntity.Customer.Id == customer.Id) | ||
.ToList(); | ||
|
||
Assert.Equal(2, actualOrders.Count); | ||
Assert.Equal(new[] { customer.Name, customer.Name }, | ||
actualOrders.Select(actualOrder => actualOrder.Customer.Name)); | ||
Assert.Equal(2, (_customerCollection.FindAll().ToList()).Count); | ||
Assert.Equal(3, (_orderCollection.FindAll().ToList()).Count); | ||
} | ||
} | ||
} |
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
653c8f7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix for #1651