Skip to content
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

Add string.Equals support. #365

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ internal static class CosmosExpressionValidatorConstants
"ToLower",
"ToUpper",
"TrimEnd",
"TrimStart"
"TrimStart",
"Equals"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,56 @@ await _testCosmos.GivenAnExistingItem(
testResults!.SingleOrDefault().Should().BeEquivalentTo(realResults!.SingleOrDefault());
}

[Fact]
public async Task GivenAQueryUsingStringEqualsMethodThenBothShouldWork()
{
await _testCosmos.GivenAnExistingItem(
new TestModel
{
Id = "RECORD1",
Name = "Bob Bobertson",
Value = false,
PartitionKey = "partition"
}
);

var (realResults, testResults) = await _testCosmos.WhenExecutingAQuery<TestModel>(
"partition",
q => q.Where(tm => tm.Name != null && tm.Name.Equals("Bob Bobertson"))
);

realResults.Should().NotBeNull();
testResults.Should().NotBeNull();

realResults!.SingleOrDefault().Should().NotBeNull();
testResults!.SingleOrDefault().Should().BeEquivalentTo(realResults!.SingleOrDefault());
}

[Fact]
public async Task GivenAQueryUsingStringEqualsMethodWithInvariantCultureIgnoreCaseThenBothShouldWork()
{
await _testCosmos.GivenAnExistingItem(
new TestModel
{
Id = "RECORD1",
Name = "Bob Bobertson",
Value = false,
PartitionKey = "partition"
}
);

var (realResults, testResults) = await _testCosmos.WhenExecutingAQuery<TestModel>(
"partition",
q => q.Where(tm => tm.Name != null && tm.Name.Equals("bob bobertson", StringComparison.InvariantCultureIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Cosmos now support any comparison passed to it? If it doesn't support some of the others in StringComparison it is probably worth adding a few negative tests and ensuring ContainerMock throws the same exception

);

realResults.Should().NotBeNull();
testResults.Should().NotBeNull();

realResults!.SingleOrDefault().Should().NotBeNull();
testResults!.SingleOrDefault().Should().BeEquivalentTo(realResults!.SingleOrDefault());
}

private bool GetTrue()
{
return true;
Expand Down