-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5966 Add support of string.TrimStart and TrimEnd methods to SerializerFinder #1953
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
6 commits
Select commit
Hold shift + click to select a range
3e3a14e
cover trimstart and trimend in serializer finder switch
kyra-rk 6261fc0
cover new trimstart/end in the serializer finder unittests
kyra-rk 21fde24
address PR
kyra-rk 484ed0c
move tests from jira ticket file to it's own file in the integration …
kyra-rk 080a44b
rename to StringTrimTests and add preprocessor directive for newer tr…
kyra-rk e7aad21
wrap the not supported test itself in if / endif
kyra-rk 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
155 changes: 155 additions & 0 deletions
155
tests/MongoDB.Driver.Tests/Linq/Integration/StringTrimTests.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,155 @@ | ||
| /* 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.Collections.Generic; | ||
| using System.Linq; | ||
| using MongoDB.Driver.TestHelpers; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace MongoDB.Driver.Tests.Linq.Integration; | ||
|
|
||
| public class StringTrimTests : LinqIntegrationTest<StringTrimTests.ClassFixture> | ||
| { | ||
| public StringTrimTests(ClassFixture fixture) | ||
| : base(fixture) | ||
| { | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_Trim_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.Trim()); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $trim : { input : "$Str" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal("abcd", "abcd", "abcd", "abcd"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_Trim_with_chars_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.Trim(new[] { ' ', 'a' })); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $trim : { input : "$Str", chars : " a" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal("bcd", "bcd", "bcd", "bcd"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_Trim_with_empty_chars_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.Trim(new char[0])); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $trim : { input : "$Str" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal("abcd", "abcd", "abcd", "abcd"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_TrimStart_with_chars_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.TrimStart(new[] { ' ', 'a' })); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $ltrim : { input : "$Str", chars : " a" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal("bcd ", "bcd ", "bcd", "bcd"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_TrimStart_with_empty_chars_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.TrimStart(new char[0])); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $ltrim : { input : "$Str" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal("abcd ", "abcd ", "abcd", "abcd"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_TrimEnd_with_chars_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.TrimEnd(new[] { ' ', 'd' })); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $rtrim : { input : "$Str", chars : " d" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal(" abc", "abc", " abc", "abc"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Select_with_TrimEnd_with_empty_chars_should_work() | ||
| { | ||
| var collection = Fixture.Collection; | ||
|
|
||
| var queryable = collection.AsQueryable() | ||
| .Select(x => x.Str.TrimEnd(new char[0])); | ||
|
|
||
| var stages = Translate(collection, queryable); | ||
| AssertStages(stages, """{ $project : { _v : { $rtrim : { input : "$Str" } }, _id : 0 } }"""); | ||
|
|
||
| var results = queryable.ToList(); | ||
| results.Should().Equal(" abcd", "abcd", " abcd", "abcd"); | ||
| } | ||
|
|
||
| // Add coverage for parameterless and single char overloads of Trim, TrimStart, and TrimEnd, see https://jira.mongodb.org/browse/CSHARP-5979 | ||
| // e.g. Trim(' '), TrimStart(), TrimStart(' '), TrimEnd(), TrimEnd(' ') | ||
|
|
||
| public class C | ||
| { | ||
| public int Id { get; set; } | ||
| public string Str { get; set; } | ||
| } | ||
|
|
||
| public sealed class ClassFixture : MongoCollectionFixture<C> | ||
| { | ||
| protected override IEnumerable<C> InitialData => | ||
| [ | ||
| new C { Id = 1, Str = " abcd "}, | ||
| new C { Id = 2, Str = "abcd "}, | ||
| new C { Id = 3, Str = " abcd"}, | ||
| new C { Id = 4, Str = "abcd"}, | ||
| ]; | ||
| } | ||
| } |
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
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.
Let's also add parameter-less methods as non-supported, probably together with the link to Jira ticket where we will implement them. Example of negative tests could be find here.
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.
How does the team usually link the Jira ticket? In Server it would have been something like
// TODO CSHARP-5979 Make these tests supported, but the closest example I found was: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.
Also, iirc they had a PR-level check for any remaining TODO SERVER-XXXX tickets matching the ticket name. Not sure if the team has something like this already, or if might be worth trying
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.
Usually I put comment something like: