-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP4040: Fix bug when using field with same element name as discriminator #1684
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
Open
papafe
wants to merge
9
commits into
mongodb:main
Choose a base branch
from
papafe:csharp4040
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
10f9e11
CSHARP4040: Fix bug when using field with same element name as discri…
papafe 770f24d
Added implementation
papafe a6612bb
Various fixes
papafe 4cf885f
Small corrections following PR comments.
papafe 2f46ff4
Small fixes
papafe 3e53e45
Removed check of conflict in discriminator convention.
papafe 68b5985
Corrected exception type
papafe 5e8b734
String corrected
papafe 97bfe4b
Slightly better wording
papafe 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
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
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
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,47 @@ | ||
/* 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 FluentAssertions; | ||
using MongoDB.Bson; | ||
using MongoDB.Bson.Serialization.Attributes; | ||
using Xunit; | ||
|
||
namespace MongoDB.Driver.Tests.Jira | ||
{ | ||
public class CSharp4040Tests | ||
{ | ||
private class BaseDocument | ||
{ | ||
[BsonId] public ObjectId Id { get; set; } = ObjectId.GenerateNewId(); | ||
|
||
[BsonElement("_t")] | ||
public string Field1 { get; set; } | ||
} | ||
|
||
private class DerivedDocument : BaseDocument {} | ||
|
||
[Fact] | ||
public void BsonClassMapSerializer_serialization_when_using_field_with_same_element_name_as_discriminator_should_throw() | ||
{ | ||
var obj = new DerivedDocument { Field1 = "field1" }; | ||
|
||
var recordedException = Record.Exception(() => obj.ToJson(typeof(BaseDocument))); | ||
recordedException.Should().NotBeNull(); | ||
recordedException.Should().BeOfType<BsonSerializationException>(); | ||
recordedException.Message.Should().Be("The discriminator element name cannot be _t because it is already being used" + | ||
" by the property Field1 of type MongoDB.Driver.Tests.Jira.CSharp4040Tests+DerivedDocument"); | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.