From b75161fb5f723eda689b6573ab89736ac8292ce7 Mon Sep 17 00:00:00 2001 From: Samuel Wanjohi Date: Mon, 18 Nov 2024 19:24:06 +0300 Subject: [PATCH] Add more test cases and refactor Assert --- .../ClientTests/Tests/ClientQueryTests.cs | 46 +++++++++---------- .../FilterAndOrderByFunctionalTests.cs | 45 +++++++++++++++++- 2 files changed, 66 insertions(+), 25 deletions(-) diff --git a/test/EndToEndTests/Tests/Client/Microsoft.OData.Client.E2E.Tests/ClientTests/Tests/ClientQueryTests.cs b/test/EndToEndTests/Tests/Client/Microsoft.OData.Client.E2E.Tests/ClientTests/Tests/ClientQueryTests.cs index 3e4752386e..33baa9652c 100644 --- a/test/EndToEndTests/Tests/Client/Microsoft.OData.Client.E2E.Tests/ClientTests/Tests/ClientQueryTests.cs +++ b/test/EndToEndTests/Tests/Client/Microsoft.OData.Client.E2E.Tests/ClientTests/Tests/ClientQueryTests.cs @@ -64,34 +64,34 @@ public async Task DollarFilter_UsingContains_ExecutesSuccessfully(string query, } [Theory] - [InlineData("People?$filter=Name in ('')", 0)] - [InlineData("People?$filter=Name in ['']", 0)] - [InlineData("People?$filter=Name in ( '' )", 0)] - [InlineData("People?$filter=Name in [ '' ]", 0)] - [InlineData("People?$filter=Name in (\"\")", 0)] - [InlineData("People?$filter=Name in [\"\"]", 0)] - [InlineData("People?$filter=Name in ( \"\" )", 0)] - [InlineData("People?$filter=Name in [ \"\" ]", 0)] - [InlineData("People?$filter=Name in ( ' ' )", 0)] - [InlineData("People?$filter=Name in [ ' ' ]", 0)] - [InlineData("People?$filter=Name in ( \" \" )", 0)] - [InlineData("People?$filter=Name in [ \" \"]", 0)] - [InlineData("People?$filter=Name in ( '', ' ' )", 0)] - [InlineData("People?$filter=Name in [ '', ' ' ]", 0)] - [InlineData("People?$filter=Name in ( \"\", \" \" )", 0)] - [InlineData("People?$filter=Name in [ \"\", \" \" ]", 0)] - [InlineData("People?$filter=Name in ( '', \" \" )", 0)] - [InlineData("People?$filter=Name in [ '', \" \" ]", 0)] - [InlineData("People?$filter=Name in ( \"\", ' ' )", 0)] - [InlineData("People?$filter=Name in [ \"\", ' ' ]", 0)] - [InlineData("People?$filter=Name in [ 'null', 'null' ]", 0)] - public async Task DollarFilter_WithCollectionWithEmptyString_ExecutesSuccessfully(string query, int expectedCount) + [InlineData("People?$filter=Name in ('')")] + [InlineData("People?$filter=Name in ['']")] + [InlineData("People?$filter=Name in ( '' )")] + [InlineData("People?$filter=Name in [ '' ]")] + [InlineData("People?$filter=Name in (\"\")")] + [InlineData("People?$filter=Name in [\"\"]")] + [InlineData("People?$filter=Name in ( \"\" )")] + [InlineData("People?$filter=Name in [ \"\" ]")] + [InlineData("People?$filter=Name in ( ' ' )")] + [InlineData("People?$filter=Name in [ ' ' ]")] + [InlineData("People?$filter=Name in ( \" \" )")] + [InlineData("People?$filter=Name in [ \" \"]")] + [InlineData("People?$filter=Name in ( '', ' ' )")] + [InlineData("People?$filter=Name in [ '', ' ' ]")] + [InlineData("People?$filter=Name in ( \"\", \" \" )")] + [InlineData("People?$filter=Name in [ \"\", \" \" ]")] + [InlineData("People?$filter=Name in ( '', \" \" )")] + [InlineData("People?$filter=Name in [ '', \" \" ]")] + [InlineData("People?$filter=Name in ( \"\", ' ' )")] + [InlineData("People?$filter=Name in [ \"\", ' ' ]")] + [InlineData("People?$filter=Name in [ 'null', 'null' ]")] + public async Task DollarFilter_WithCollectionWithEmptyString_ExecutesSuccessfully(string query) { // Act var response = await _context.ExecuteAsync(new Uri(_baseUri.OriginalString + query)); // Assert - Assert.Equal(expectedCount, response.ToArray().Length); + Assert.Empty(response.ToArray()); } [Fact] diff --git a/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs b/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs index 3fce887f69..d271ba866b 100644 --- a/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs +++ b/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs @@ -2413,45 +2413,86 @@ public void FilterWithInOperationWithParensStringCollection_EscapedSingleQuote() [Theory] [InlineData("('a''bc')", "('a''bc')", 1)] + [InlineData("['a''bc']", "['a''bc']", 1)] [InlineData("('''def')", "('''def')", 1)] + [InlineData("['''def']", "['''def']", 1)] [InlineData("('xyz''')", "('xyz''')", 1)] + [InlineData("['xyz''']", "['xyz''']", 1)] [InlineData("('''pqr''')", "('''pqr''')", 1)] + [InlineData("['''pqr''']", "['''pqr''']", 1)] [InlineData("('a''bc','''def')", "('a''bc','''def')", 2)] + [InlineData("['a''bc','''def']", "['a''bc','''def']", 2)] [InlineData("('a''bc','xyz''')", "('a''bc','xyz''')", 2)] + [InlineData("['a''bc','xyz''']", "['a''bc','xyz''']", 2)] [InlineData("('a''bc','''pqr''')", "('a''bc','''pqr''')", 2)] + [InlineData("['a''bc','''pqr''']", "['a''bc','''pqr''']", 2)] [InlineData("('''def','a''bc')", "('''def','a''bc')", 2)] + [InlineData("['''def','a''bc']", "['''def','a''bc']", 2)] [InlineData("('''def','xyz''')", "('''def','xyz''')", 2)] + [InlineData("['''def','xyz''']", "['''def','xyz''']", 2)] [InlineData("('''def','''pqr''')", "('''def','''pqr''')", 2)] + [InlineData("['''def','''pqr''']", "['''def','''pqr''']", 2)] [InlineData("('xyz''','a''bc')", "('xyz''','a''bc')", 2)] + [InlineData("['xyz''','a''bc']", "['xyz''','a''bc']", 2)] [InlineData("('xyz''','''def')", "('xyz''','''def')", 2)] + [InlineData("['xyz''','''def']", "['xyz''','''def']", 2)] [InlineData("('xyz''','''pqr''')", "('xyz''','''pqr''')", 2)] + [InlineData("['xyz''','''pqr''']", "['xyz''','''pqr''']", 2)] [InlineData("('''pqr''','a''bc')", "('''pqr''','a''bc')", 2)] + [InlineData("['''pqr''','a''bc']", "['''pqr''','a''bc']", 2)] [InlineData("('''pqr''','''def')", "('''pqr''','''def')", 2)] + [InlineData("['''pqr''','''def']", "['''pqr''','''def']", 2)] [InlineData("('''pqr''','xyz''')", "('''pqr''','xyz''')", 2)] + [InlineData("['''pqr''','xyz''']", "['''pqr''','xyz''']", 2)] [InlineData("('a''bc','''def','xyz''')", "('a''bc','''def','xyz''')", 3)] + [InlineData("['a''bc','''def','xyz''']", "['a''bc','''def','xyz''']", 3)] [InlineData("('a''bc','''def','''pqr''')", "('a''bc','''def','''pqr''')", 3)] + [InlineData("['a''bc','''def','''pqr''']", "['a''bc','''def','''pqr''']", 3)] [InlineData("('a''bc','xyz''','''def')", "('a''bc','xyz''','''def')", 3)] + [InlineData("['a''bc','xyz''','''def']", "['a''bc','xyz''','''def']", 3)] [InlineData("('a''bc','xyz''','''pqr''')", "('a''bc','xyz''','''pqr''')", 3)] + [InlineData("['a''bc','xyz''','''pqr''']", "['a''bc','xyz''','''pqr''']", 3)] [InlineData("('a''bc','''pqr''','''def')", "('a''bc','''pqr''','''def')", 3)] + [InlineData("['a''bc','''pqr''','''def']", "['a''bc','''pqr''','''def']", 3)] [InlineData("('a''bc','''pqr''','xyz''')", "('a''bc','''pqr''','xyz''')", 3)] + [InlineData("['a''bc','''pqr''','xyz''']", "['a''bc','''pqr''','xyz''']", 3)] [InlineData("('''def','a''bc','xyz''')", "('''def','a''bc','xyz''')", 3)] + [InlineData("['''def','a''bc','xyz''']", "['''def','a''bc','xyz''']", 3)] [InlineData("('''def','a''bc','''pqr''')", "('''def','a''bc','''pqr''')", 3)] + [InlineData("['''def','a''bc','''pqr''']", "['''def','a''bc','''pqr''']", 3)] [InlineData("('''def','xyz''','a''bc')", "('''def','xyz''','a''bc')", 3)] + [InlineData("['''def','xyz''','a''bc']", "['''def','xyz''','a''bc']", 3)] [InlineData("('''def','xyz''','''pqr''')", "('''def','xyz''','''pqr''')", 3)] + [InlineData("['''def','xyz''','''pqr''']", "['''def','xyz''','''pqr''']", 3)] [InlineData("('''def','''pqr''','a''bc')", "('''def','''pqr''','a''bc')", 3)] + [InlineData("['''def','''pqr''','a''bc']", "['''def','''pqr''','a''bc']", 3)] [InlineData("('''def','''pqr''','xyz''')", "('''def','''pqr''','xyz''')", 3)] + [InlineData("['''def','''pqr''','xyz''']", "['''def','''pqr''','xyz''']", 3)] [InlineData("('xyz''','a''bc','''def')", "('xyz''','a''bc','''def')", 3)] + [InlineData("['xyz''','a''bc','''def']", "['xyz''','a''bc','''def']", 3)] [InlineData("('xyz''','a''bc','''pqr''')", "('xyz''','a''bc','''pqr''')", 3)] + [InlineData("['xyz''','a''bc','''pqr''']", "['xyz''','a''bc','''pqr''']", 3)] [InlineData("('xyz''','''def','''pqr''')", "('xyz''','''def','''pqr''')", 3)] + [InlineData("['xyz''','''def','''pqr''']", "['xyz''','''def','''pqr''']", 3)] [InlineData("('xyz''','''def','a''bc')", "('xyz''','''def','a''bc')", 3)] + [InlineData("['xyz''','''def','a''bc']", "['xyz''','''def','a''bc']", 3)] [InlineData("('xyz''','''pqr''','a''bc')", "('xyz''','''pqr''','a''bc')", 3)] + [InlineData("['xyz''','''pqr''','a''bc']", "['xyz''','''pqr''','a''bc']", 3)] [InlineData("('xyz''','''pqr''','''def')", "('xyz''','''pqr''','''def')", 3)] + [InlineData("['xyz''','''pqr''','''def']", "['xyz''','''pqr''','''def']", 3)] [InlineData("('''pqr''','a''bc','''def')", "('''pqr''','a''bc','''def')", 3)] + [InlineData("['''pqr''','a''bc','''def']", "['''pqr''','a''bc','''def']", 3)] [InlineData("('''pqr''','a''bc','xyz''')", "('''pqr''','a''bc','xyz''')", 3)] + [InlineData("['''pqr''','a''bc','xyz''']", "['''pqr''','a''bc','xyz''']", 3)] [InlineData("('''pqr''','''def','a''bc')", "('''pqr''','''def','a''bc')", 3)] + [InlineData("['''pqr''','''def','a''bc']", "['''pqr''','''def','a''bc']", 3)] [InlineData("('''pqr''','''def','xyz''')", "('''pqr''','''def','xyz''')", 3)] + [InlineData("['''pqr''','''def','xyz''']", "['''pqr''','''def','xyz''']", 3)] [InlineData("('''pqr''','xyz''','a''bc')", "('''pqr''','xyz''','a''bc')", 3)] + [InlineData("['''pqr''','xyz''','a''bc']", "['''pqr''','xyz''','a''bc']", 3)] [InlineData("('''pqr''','xyz''','''def')", "('''pqr''','xyz''','''def')", 3)] + [InlineData("['''pqr''','xyz''','''def']", "['''pqr''','xyz''','''def']", 3)] + public void FilterWithInExpressionContainingEscapedSingleQuotes(string inExpr, string parsedExpr, int count) { FilterClause filter = ParseFilter($"SSN in {inExpr}", HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType()); @@ -2749,7 +2790,7 @@ public void FilterWithInOperationWithWhitespace(string filterClause, string expe CollectionConstantNode collectionNode = Assert.IsType(inNode.Right); // A single whitespace or multiple whitespaces are valid literals - Assert.Equal(1, collectionNode.Collection.Count); + Assert.Single(collectionNode.Collection); ConstantNode constantNode = collectionNode.Collection.First(); Assert.Equal(expectedLiteralText, constantNode.LiteralText); @@ -2769,7 +2810,7 @@ public void FilterWithInOperationWithWhitespaceInSquareBrackets(string filterCla CollectionConstantNode collectionNode = Assert.IsType(inNode.Right); // A single whitespace or multiple whitespaces are valid literals - Assert.Equal(1, collectionNode.Collection.Count); + Assert.Single(collectionNode.Collection); ConstantNode constantNode = collectionNode.Collection.First(); Assert.Equal(expectedLiteralText, constantNode.LiteralText);