|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Xunit; |
| 4 | +using System.Linq; |
| 5 | +using System.Security.Cryptography; |
| 6 | + |
| 7 | +namespace LiteDB.Tests.Issues |
| 8 | +{ |
| 9 | + |
| 10 | + public class Issue1865_Tests |
| 11 | + { |
| 12 | + public class Project : BaseEntity |
| 13 | + { |
| 14 | + |
| 15 | + } |
| 16 | + |
| 17 | + public class Point : BaseEntity |
| 18 | + { |
| 19 | + public BaseEntity Project { get; set; } |
| 20 | + public BaseEntity Parent { get; set; } |
| 21 | + public DateTime Start { get; internal set; } |
| 22 | + public DateTime End { get; internal set; } |
| 23 | + } |
| 24 | + |
| 25 | + public class BaseEntity |
| 26 | + { |
| 27 | + public ObjectId Id { get; set; } = ObjectId.NewObjectId(); |
| 28 | + public string Name { get; set; } |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void Incluced_document_types_should_be_reald() |
| 33 | + { |
| 34 | + BsonMapper.Global.Entity<Point>().DbRef(p => p.Project); |
| 35 | + BsonMapper.Global.Entity<Point>().DbRef(p => p.Parent); |
| 36 | + BsonMapper.Global.ResolveCollectionName = (s) => "activity"; |
| 37 | + |
| 38 | + using var _database = new LiteDatabase(":memory:"); |
| 39 | + |
| 40 | + var project = new Project() { Name = "Project" }; |
| 41 | + var point1 = new Point { Parent = project, Project = project, Name = "Point 1", Start = DateTime.Now, End = DateTime.Now.AddDays(2) }; |
| 42 | + var point2 = new Point { Parent = point1, Project = project, Name = "Point 2", Start = DateTime.Now, End = DateTime.Now.AddDays(2) }; |
| 43 | + |
| 44 | + |
| 45 | + _database.GetCollection<Point>("activity").Insert(point1); |
| 46 | + _database.GetCollection<Point>("activity").Insert(point2); |
| 47 | + _database.GetCollection<Project>("activity").Insert(project); |
| 48 | + |
| 49 | + |
| 50 | + var p1 = _database.GetCollection<Point>() |
| 51 | + .FindById(point1.Id); |
| 52 | + Assert.Equal(typeof(Project), p1.Parent.GetType()); |
| 53 | + Assert.Equal(typeof(Project), p1.Project.GetType()); |
| 54 | + |
| 55 | + var p2 = _database.GetCollection<Point>() |
| 56 | + .FindById(point2.Id); |
| 57 | + Assert.Equal(typeof(Point), p2.Parent.GetType()); |
| 58 | + Assert.Equal(typeof(Project), p2.Project.GetType()); |
| 59 | + |
| 60 | + p1 = _database.GetCollection<Point>() |
| 61 | + .Include(p=>p.Parent).Include(p=>p.Project) |
| 62 | + .FindById(point1.Id); |
| 63 | + Assert.Equal(typeof(Project), p1.Parent.GetType()); |
| 64 | + Assert.Equal(typeof(Project), p1.Project.GetType()); |
| 65 | + |
| 66 | + p2 = _database.GetCollection<Point>() |
| 67 | + .Include(p => p.Parent).Include(p => p.Project) |
| 68 | + .FindById(point2.Id); |
| 69 | + Assert.Equal(typeof(Point), p2.Parent.GetType()); |
| 70 | + Assert.Equal(typeof(Project), p2.Project.GetType()); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments