-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5391: Add spec test for $$type operator with "number" #1739
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
Conversation
tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedValueMatcher.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedValueMatcher.cs
Outdated
Show resolved
Hide resolved
|
||
if (expectedTypes.IsString) | ||
{ | ||
expectedTypeNames = new List<string> { expectedTypes.AsString }; | ||
var expectedType = expectedTypes.AsString; |
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.
Instead of asserting differently in more than one place keep the existing assert at the end of this method and change how expectedTypeNames
is computed:
if (expectedTypes.IsString)
{
var expectedType = expectedTypes.AsString;
expectedTypeNames = expectedType == "number" ? __numericTypes : [expectedType];
}
else if (expectedTypes.IsBsonArray)
{
expectedTypeNames = expectedTypes.AsBsonArray
.Select(t => t.AsString)
.SelectMany(t => t == "number" ? __numericTypes : [t])
.ToList();
}
else
{
throw new FormatException($"Unexpected $$type value BsonType: '{expectedTypes.BsonType}'.");
}
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.
I leave it to you to verify that all tests still pass with this proposed refactoring.
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, does "number"
actually ever appear as ONE element of an array?
In the json file you are adding it always appears by itself.
So the changes to the else if
part might not actually be needed...
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.
I decided to also modify the BsonArray case as the "number" value could be used anywhere. Currently there are no instances in our spec tests where it is used as an element of an array but in the future we could have a spec test that uses the "number" value in an array. However, it is untested functionality currently and updating the array use case in the future will be easy so I'll defer it.
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.
LGTM
No description provided.