66
77namespace LiteDB . Tests . Issues
88{
9-
9+
1010 public class Issue1865_Tests
1111 {
1212 public class Project : BaseEntity
1313 {
14-
14+ public List < BaseEntity > Points { get ; set ; } = new List < BaseEntity > ( ) ;
1515 }
1616
1717 public class Point : BaseEntity
@@ -31,43 +31,58 @@ public class BaseEntity
3131 [ Fact ]
3232 public void Incluced_document_types_should_be_reald ( )
3333 {
34- BsonMapper . Global . Entity < Point > ( ) . DbRef ( p => p . Project ) ;
35- BsonMapper . Global . Entity < Point > ( ) . DbRef ( p => p . Parent ) ;
36- BsonMapper . Global . ResolveCollectionName = ( s ) => "activity" ;
34+ BsonMapper . Global . Entity < Point > ( ) . DbRef ( p => p . Project , "activity" ) ;
35+ BsonMapper . Global . Entity < Point > ( ) . DbRef ( p => p . Parent , "activity" ) ;
36+ BsonMapper . Global . Entity < Project > ( ) . DbRef ( p => p . Points , "activity" ) ;
37+
38+ //BsonMapper.Global.ResolveCollectionName = (s) => "activity";
3739
3840 using var _database = new LiteDatabase ( ":memory:" ) ;
41+ var projectsCol = _database . GetCollection < Project > ( "activity" ) ;
42+ var pointsCol = _database . GetCollection < Point > ( "activity" ) ;
3943
4044 var project = new Project ( ) { Name = "Project" } ;
4145 var point1 = new Point { Parent = project , Project = project , Name = "Point 1" , Start = DateTime . Now , End = DateTime . Now . AddDays ( 2 ) } ;
4246 var point2 = new Point { Parent = point1 , Project = project , Name = "Point 2" , Start = DateTime . Now , End = DateTime . Now . AddDays ( 2 ) } ;
47+
48+ project . Points . Add ( point1 ) ;
49+ project . Points . Add ( point2 ) ;
4350
44-
45- _database . GetCollection < Point > ( "activity" ) . Insert ( point1 ) ;
46- _database . GetCollection < Point > ( "activity" ) . Insert ( point2 ) ;
47- _database . GetCollection < Project > ( "activity" ) . Insert ( project ) ;
51+ pointsCol . Insert ( point1 ) ;
52+ pointsCol . Insert ( point2 ) ;
53+ projectsCol . Insert ( project ) ;
4854
4955
50- var p1 = _database . GetCollection < Point > ( )
56+ var p1 = pointsCol
5157 . FindById ( point1 . Id ) ;
5258 Assert . Equal ( typeof ( Project ) , p1 . Parent . GetType ( ) ) ;
5359 Assert . Equal ( typeof ( Project ) , p1 . Project . GetType ( ) ) ;
5460
55- var p2 = _database . GetCollection < Point > ( )
61+ var p2 = pointsCol
5662 . FindById ( point2 . Id ) ;
5763 Assert . Equal ( typeof ( Point ) , p2 . Parent . GetType ( ) ) ;
5864 Assert . Equal ( typeof ( Project ) , p2 . Project . GetType ( ) ) ;
5965
60- p1 = _database . GetCollection < Point > ( )
61- . Include ( p=> p . Parent ) . Include ( p=> p . Project )
66+ var prj = projectsCol
67+ . FindById ( project . Id ) ;
68+ Assert . Equal ( typeof ( Point ) , prj . Points [ 0 ] . GetType ( ) ) ;
69+
70+ p1 = pointsCol
71+ . Include ( p => p . Parent ) . Include ( p => p . Project )
6272 . FindById ( point1 . Id ) ;
6373 Assert . Equal ( typeof ( Project ) , p1 . Parent . GetType ( ) ) ;
6474 Assert . Equal ( typeof ( Project ) , p1 . Project . GetType ( ) ) ;
6575
66- p2 = _database . GetCollection < Point > ( )
76+ p2 = pointsCol
6777 . Include ( p => p . Parent ) . Include ( p => p . Project )
6878 . FindById ( point2 . Id ) ;
6979 Assert . Equal ( typeof ( Point ) , p2 . Parent . GetType ( ) ) ;
7080 Assert . Equal ( typeof ( Project ) , p2 . Project . GetType ( ) ) ;
81+
82+ prj = projectsCol
83+ . Include ( p => p . Points )
84+ . FindById ( project . Id ) ;
85+ Assert . Equal ( typeof ( Point ) , prj . Points [ 0 ] . GetType ( ) ) ;
7186 }
7287 }
7388}
0 commit comments