File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
tests/MongoDB.Bson.Tests/Serialization Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -39,10 +39,42 @@ public void Deserialize_should_throw_invalidOperationException_when_creator_retu
39
39
exception . Should ( ) . BeOfType < BsonSerializationException > ( ) ;
40
40
}
41
41
42
+ [ Fact ]
43
+ public void Deserialize_should_throw_when_no_creators_found ( )
44
+ {
45
+ var bsonClassMap = new BsonClassMap < ModelWithCtor > ( ) ;
46
+ bsonClassMap . AutoMap ( ) ;
47
+ bsonClassMap . Freeze ( ) ;
48
+
49
+ var subject = new BsonClassMapSerializer < ModelWithCtor > ( bsonClassMap ) ;
50
+
51
+ using var reader = new JsonReader ( "{ \" _id\" : \" just_an_id\" }" ) ;
52
+ var context = BsonDeserializationContext . CreateRoot ( reader ) ;
53
+
54
+ var exception = Record . Exception ( ( ) => subject . Deserialize ( context ) ) ;
55
+ exception . Should ( ) . BeOfType < BsonSerializationException > ( )
56
+ . Subject . Message . Should ( ) . Be ( $ "No matching creator found for class { typeof ( ModelWithCtor ) . FullName } ") ;
57
+ }
58
+
42
59
// nested classes
43
60
private class MyModel
44
61
{
45
62
public string Id { get ; set ; }
46
63
}
64
+
65
+ private class ModelWithCtor
66
+ {
67
+ private readonly string _myId ;
68
+ private readonly int _i ;
69
+
70
+ public ModelWithCtor ( string id , int i )
71
+ {
72
+ _myId = id ;
73
+ _i = i ;
74
+ }
75
+
76
+ public string Id => _myId ;
77
+ public int I => _i ;
78
+ }
47
79
}
48
80
}
You can’t perform that action at this time.
0 commit comments