-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5952: SerializerFinder resolve wrong serializer for BsonDocument members #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a349282
CSHARP-5952: SerializerFinder resolve wrong serializer for BsonDocume…
sanych-sun caf52e2
Update src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/…
sanych-sun c1f2569
pr
sanych-sun a31ec7f
pr
sanych-sun 9408d7d
pr
sanych-sun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/BsonDocumentTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* Copyright 2010-present MongoDB Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| using System.Linq.Expressions; | ||
| using FluentAssertions; | ||
| using MongoDB.Bson; | ||
| using MongoDB.Bson.Serialization; | ||
| using MongoDB.Bson.Serialization.Serializers; | ||
| using MongoDB.Driver.Linq; | ||
| using MongoDB.Driver.Linq.Linq3Implementation.SerializerFinders; | ||
| using MongoDB.Driver.Linq.Linq3Implementation.Serializers; | ||
| using Xunit; | ||
|
|
||
| namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.SerializerFinders; | ||
|
|
||
| public class BsonDocumentTests | ||
| { | ||
| [Theory] | ||
| [MemberData(nameof(SupportedTestCases))] | ||
| public void SerializerFinder_should_resolve_serializer_for_BsonDocument_members(LambdaExpression expression, IBsonSerializer expected) | ||
| { | ||
| var serializerMap = TestHelpers.CreateSerializerMap(expression); | ||
|
|
||
| SerializerFinder.FindSerializers(expression.Body, null, serializerMap); | ||
|
|
||
| serializerMap.IsKnown(expression.Body, out _).Should().BeTrue(); | ||
| serializerMap.GetSerializer(expression.Body).Should().Be(expected); | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(NotSupportedTestCases))] | ||
| public void SerializerFinder_resolve_unknowable_serializer_for_unsupported_BsonDocument_members(LambdaExpression expression) | ||
| { | ||
| var serializerMap = TestHelpers.CreateSerializerMap(expression); | ||
|
|
||
| SerializerFinder.FindSerializers(expression.Body, null, serializerMap); | ||
|
|
||
| serializerMap.IsKnown(expression.Body, out var serializer).Should().BeTrue(); | ||
| serializer.Should().BeOfType(typeof(UnknowableSerializer<>).MakeGenericType(expression.Body.Type)); | ||
| var exception = Record.Exception(() => serializerMap.GetSerializer(expression.Body)); | ||
| exception.Should().BeOfType<ExpressionNotSupportedException>(); | ||
| } | ||
|
|
||
| public static readonly object[][] SupportedTestCases = | ||
| [ | ||
| [TestHelpers.MakeLambda((BsonDocument d) => d["name"]), BsonValueSerializer.Instance] | ||
| ]; | ||
|
|
||
| public static readonly object[][] NotSupportedTestCases = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also add test cases using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| [ | ||
| [TestHelpers.MakeLambda((BsonDocument d) => d.ElementCount)], | ||
| [TestHelpers.MakeLambda((BsonDocument d) => d.Elements)], | ||
| [TestHelpers.MakeLambda((BsonDocument d) => d.Values)], | ||
| [TestHelpers.MakeLambda((BsonDocument d) => d.Names)], | ||
|
|
||
| [TestHelpers.MakeLambda((RawBsonDocument d) => d.ElementCount)], | ||
| [TestHelpers.MakeLambda((RawBsonDocument d) => d.Elements)], | ||
| [TestHelpers.MakeLambda((RawBsonDocument d) => d.Values)], | ||
| [TestHelpers.MakeLambda((RawBsonDocument d) => d.Names)], | ||
| ]; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that this doesn't exercise the code path you changed since Indexer will go through VisitMethodCall instead of VisitMember. Still good to have this here though.