File tree Expand file tree Collapse file tree 3 files changed +53
-5
lines changed Expand file tree Collapse file tree 3 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -2173,12 +2173,13 @@ internal AggregateResult RunAggregateCommand(AggregateArgs args)
2173
2173
// private methods
2174
2174
private void AssignId ( InsertRequest request )
2175
2175
{
2176
- var serializer = request . Serializer ?? BsonSerializer . LookupSerializer ( request . NominalType ) ;
2177
- var idProvider = serializer as IBsonIdProvider ;
2178
- if ( idProvider != null )
2176
+ var document = request . Document ;
2177
+ if ( document != null )
2179
2178
{
2180
- var document = request . Document ;
2181
- if ( document != null )
2179
+ var actualType = document . GetType ( ) ;
2180
+ var serializer = request . Serializer ?? BsonSerializer . LookupSerializer ( actualType ) ;
2181
+ var idProvider = serializer as IBsonIdProvider ;
2182
+ if ( idProvider != null )
2182
2183
{
2183
2184
object id ;
2184
2185
Type idNominalType ;
Original file line number Diff line number Diff line change
1
+ /* Copyright 2010-2014 MongoDB Inc.
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ using System ;
17
+ using System . Linq ;
18
+ using MongoDB . Bson ;
19
+ using MongoDB . Driver ;
20
+ using NUnit . Framework ;
21
+
22
+ namespace MongoDB . DriverUnitTests . Jira
23
+ {
24
+ [ TestFixture ]
25
+ public class CSharp958Tests
26
+ {
27
+ private interface IPerson { }
28
+
29
+ private class Person : IPerson
30
+ {
31
+ public ObjectId Id { get ; set ; }
32
+ public string Name { get ; set ; }
33
+ }
34
+
35
+ [ Test ]
36
+ public void TestAssignIdWorksWithInterface ( )
37
+ {
38
+ var collection = Configuration . GetTestCollection < IPerson > ( ) ;
39
+ collection . Drop ( ) ;
40
+
41
+ IPerson person = new Person { Name = "Jack" } ;
42
+ var result = collection . Insert ( person ) ;
43
+ Assert . AreNotEqual ( ObjectId . Empty , ( ( Person ) person ) . Id ) ;
44
+ }
45
+ }
46
+ }
Original file line number Diff line number Diff line change 139
139
<Compile Include =" Jira\CSharp801Tests.cs" />
140
140
<Compile Include =" Jira\CSharp840Tests.cs" />
141
141
<Compile Include =" Jira\CSharp893Tests.cs" />
142
+ <Compile Include =" Jira\CSharp958Tests.cs" />
142
143
<Compile Include =" Linq\BsonDocumentBackedClassSerializerTests.cs" />
143
144
<Compile Include =" Linq\BsonDocumentTests.cs" />
144
145
<Compile Include =" FailPoint.cs" />
You can’t perform that action at this time.
0 commit comments