Skip to content

Commit d124020

Browse files
committed
pr
1 parent 87be7c0 commit d124020

6 files changed

Lines changed: 27 additions & 73 deletions

File tree

src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstCreateObjectIdExpression.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@ internal sealed class AstCreateObjectIdExpression : AstExpression
2222
{
2323
public override AstNodeType NodeType => AstNodeType.CreateObjectIdExpression;
2424

25-
public override AstNode Accept(AstNodeVisitor visitor)
26-
{
27-
return visitor.VisitCreateObjectIdExpression(this);
28-
}
25+
public override AstNode Accept(AstNodeVisitor visitor) =>
26+
visitor.VisitCreateObjectIdExpression(this);
2927

30-
public override BsonValue Render()
31-
{
32-
return new BsonDocument
28+
public override BsonValue Render() =>
29+
new BsonDocument
3330
{
3431
{ "$createObjectId", new BsonDocument() }
3532
};
36-
}
3733
}

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/CreateObjectIdMethodToAggregationExpressionTranslator.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@
1818
using MongoDB.Driver.Linq.Linq3Implementation.Misc;
1919
using MongoDB.Driver.Linq.Linq3Implementation.Reflection;
2020

21-
namespace MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators
21+
namespace MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators;
22+
23+
internal static class CreateObjectIdMethodToAggregationExpressionTranslator
2224
{
23-
internal static class CreateObjectIdMethodToAggregationExpressionTranslator
25+
public static TranslatedExpression Translate(TranslationContext context, MethodCallExpression expression)
2426
{
25-
public static TranslatedExpression Translate(TranslationContext context, MethodCallExpression expression)
26-
{
27-
var method = expression.Method;
28-
29-
if (method.Is(MqlMethod.CreateObjectId))
30-
{
31-
var ast = AstExpression.CreateObjectId();
32-
var serializer = context.GetSerializer(expression);
33-
return new TranslatedExpression(expression, ast, serializer);
34-
}
27+
var method = expression.Method;
3528

36-
throw new ExpressionNotSupportedException(expression);
29+
if (method.Is(MqlMethod.CreateObjectId))
30+
{
31+
var ast = AstExpression.CreateObjectId();
32+
var serializer = context.GetSerializer(expression);
33+
return new TranslatedExpression(expression, ast, serializer);
3734
}
35+
36+
throw new ExpressionNotSupportedException(expression);
3837
}
3938
}

tests/MongoDB.Driver.Tests/Linq/Integration/MqlCreateObjectIdTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public MqlCreateObjectIdTests(ClassFixture fixture)
3232
}
3333

3434
[Fact]
35-
public void MqlCreateObjectId_in_where()
35+
public void MqlCreateObjectId_in_where_should_work()
3636
{
3737
var collection = Fixture.Collection;
3838
var queryable = collection.AsQueryable()
@@ -46,7 +46,7 @@ public void MqlCreateObjectId_in_where()
4646
}
4747

4848
[Fact]
49-
public void MqlCreateObjectId_in_select()
49+
public void MqlCreateObjectId_in_select_should_work()
5050
{
5151
var collection = Fixture.Collection;
5252
var queryable = collection.AsQueryable()
@@ -65,7 +65,7 @@ public void MqlCreateObjectId_in_select()
6565
}
6666

6767
[Fact]
68-
public async Task MqlCreateObjectId_in_filter_builder()
68+
public async Task MqlCreateObjectId_in_filter_builder_should_work()
6969
{
7070
var collection = Fixture.Collection;
7171

@@ -78,7 +78,7 @@ public async Task MqlCreateObjectId_in_filter_builder()
7878
}
7979

8080
[Fact]
81-
public async Task MqlCreateObjectId_in_projection_builder()
81+
public async Task MqlCreateObjectId_in_projection_builder_should_work()
8282
{
8383
var collection = Fixture.Collection;
8484

@@ -97,7 +97,7 @@ public async Task MqlCreateObjectId_in_projection_builder()
9797
}
9898

9999
[Fact]
100-
public async Task MqlCreateObjectId_in_aggregate()
100+
public async Task MqlCreateObjectId_in_aggregate_should_work()
101101
{
102102
var collection = Fixture.Collection;
103103

tests/MongoDB.Driver.Tests/Linq/Integration/MqlSubtypeTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public MqlSubtypeTests(ClassFixture fixture)
3838
[InlineData(BsonBinarySubType.Vector, 2)]
3939
[InlineData(BsonBinarySubType.UuidStandard, 3)]
4040
[InlineData(null, 4)]
41-
public void MqlSubtype_in_where(BsonBinarySubType? subtype, int expectedId)
41+
public void MqlSubtype_in_where_should_work(BsonBinarySubType? subtype, int expectedId)
4242
{
4343
var collection = Fixture.Collection;
4444
var queryable = collection.AsQueryable()
@@ -52,7 +52,7 @@ public void MqlSubtype_in_where(BsonBinarySubType? subtype, int expectedId)
5252
}
5353

5454
[Fact]
55-
public void MqlSubtype_in_select()
55+
public void MqlSubtype_in_select_should_work()
5656
{
5757
var collection = Fixture.Collection;
5858
var queryable = collection.AsQueryable()
@@ -66,7 +66,7 @@ public void MqlSubtype_in_select()
6666
}
6767

6868
[Fact]
69-
public async Task MqlSubtype_in_filter_builder()
69+
public async Task MqlSubtype_in_filter_builder_should_work()
7070
{
7171
var collection = Fixture.Collection;
7272

@@ -79,7 +79,7 @@ public async Task MqlSubtype_in_filter_builder()
7979
}
8080

8181
[Fact]
82-
public async Task MqlSubtype_in_projection_builder()
82+
public async Task MqlSubtype_in_projection_builder_should_work()
8383
{
8484
var collection = Fixture.Collection;
8585

@@ -93,7 +93,7 @@ public async Task MqlSubtype_in_projection_builder()
9393
}
9494

9595
[Fact]
96-
public async Task MqlSubtype_in_aggregate()
96+
public async Task MqlSubtype_in_aggregate_should_work()
9797
{
9898
var collection = Fixture.Collection;
9999

tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/MqlCreateObjectIdTests.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/MqlTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void SerializerFinder_should_resolve_mql_methods(LambdaExpression express
5151
[TestHelpers.MakeLambda((MyModel model) => Mql.SimilarityDotProduct(model.Vector1, model.Vector2, false)), typeof(DoubleSerializer)],
5252
[TestHelpers.MakeLambda((MyModel model) => Mql.SimilarityEuclidean(model.Vector1, model.Vector2, false)), typeof(DoubleSerializer)],
5353
[TestHelpers.MakeLambda((MyModel model) => Mql.Subtype(model.Data)), typeof(NullableSerializer<BsonBinarySubType>)],
54+
[TestHelpers.MakeLambda((MyModel model) => Mql.CreateObjectId()), typeof(ObjectIdSerializer)],
5455
];
5556

5657
private class MyModel

0 commit comments

Comments
 (0)