-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for single quotes on in expression (#1078)
- Loading branch information
Showing
5 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
test/Microsoft.AspNetCore.OData.E2E.Tests/DollarFilter/DollarFilterController.cs
This file contains 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,23 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DollarFilterController.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Query; | ||
using Microsoft.AspNetCore.OData.Routing.Controllers; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DollarFilter | ||
{ | ||
public class PeopleController : ODataController | ||
{ | ||
[EnableQuery] | ||
public ActionResult<IEnumerable<Person>> Get() | ||
{ | ||
return Ok(DollarFilterDataSource.People); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/Microsoft.AspNetCore.OData.E2E.Tests/DollarFilter/DollarFilterDataModel.cs
This file contains 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,15 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DollarFilterDataModel.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DollarFilter | ||
{ | ||
public class Person | ||
{ | ||
public int Id { get; set; } | ||
public string SSN { get; set; } | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/Microsoft.AspNetCore.OData.E2E.Tests/DollarFilter/DollarFilterDataSource.cs
This file contains 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,29 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DollarFilterDataSource.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DollarFilter | ||
{ | ||
public class DollarFilterDataSource | ||
{ | ||
private static IList<Person> people; | ||
|
||
static DollarFilterDataSource() | ||
{ | ||
people = new List<Person> | ||
{ | ||
new Person { Id = 1, SSN = "a'bc" }, | ||
new Person { Id = 2, SSN = "'def" }, | ||
new Person { Id = 3, SSN = "xyz'" }, | ||
new Person { Id = 4, SSN = "'pqr'" } | ||
}; | ||
} | ||
|
||
public static IList<Person> People => people; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/Microsoft.AspNetCore.OData.E2E.Tests/DollarFilter/DollarFilterEdmModel.cs
This file contains 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,23 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DollarFilterEdmModel.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.ModelBuilder; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DollarFilter | ||
{ | ||
public class DollarFilterEdmModel | ||
{ | ||
public static IEdmModel GetEdmModel() | ||
{ | ||
var builder = new ODataConventionModelBuilder(); | ||
builder.EntitySet<Person>("People"); | ||
|
||
return builder.GetEdmModel(); | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
test/Microsoft.AspNetCore.OData.E2E.Tests/DollarFilter/DollarFilterTests.cs
This file contains 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,98 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DollarFilterTests.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.OData.TestCommon; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.OData.Edm; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DollarFilter | ||
{ | ||
public class DollarFilterTests : WebApiTestBase<DollarFilterTests> | ||
{ | ||
public DollarFilterTests(WebApiTestFixture<DollarFilterTests> fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
protected static void UpdateConfigureServices(IServiceCollection services) | ||
{ | ||
IEdmModel model = DollarFilterEdmModel.GetEdmModel(); | ||
|
||
services.ConfigureControllers(typeof(PeopleController)); | ||
|
||
services.AddControllers().AddOData(opt => | ||
opt.Filter().Select().AddRouteComponents("odata", model)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("('a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"}]")] | ||
[InlineData("('''def')", "[{\"Id\":2,\"SSN\":\"'def\"}]")] | ||
[InlineData("('xyz''')", "[{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('''pqr''')", "[{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('a''bc','''def')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"}]")] | ||
[InlineData("('a''bc','xyz''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('a''bc','''pqr''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''def','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"}]")] | ||
[InlineData("('''def','xyz''')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('''def','''pqr''')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('xyz''','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('xyz''','''def')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('xyz''','''pqr''')", "[{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','''def')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','xyz''')", "[{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('a''bc','''def','xyz''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('a''bc','''def','''pqr''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('a''bc','xyz''','''def')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('a''bc','xyz''','''pqr''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('a''bc','''pqr''','''def')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('a''bc','''pqr''','xyz''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''def','a''bc','xyz''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('''def','a''bc','''pqr''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''def','xyz''','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('''def','xyz''','''pqr''')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''def','''pqr''','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''def','''pqr''','xyz''')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('xyz''','a''bc','''def')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('xyz''','a''bc','''pqr''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('xyz''','''def','''pqr''')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('xyz''','''def','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"}]")] | ||
[InlineData("('xyz''','''pqr''','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('xyz''','''pqr''','''def')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','a''bc','''def')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','a''bc','xyz''')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','''def','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','''def','xyz''')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','xyz''','a''bc')", "[{\"Id\":1,\"SSN\":\"a'bc\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
[InlineData("('''pqr''','xyz''','''def')", "[{\"Id\":2,\"SSN\":\"'def\"},{\"Id\":3,\"SSN\":\"xyz'\"},{\"Id\":4,\"SSN\":\"'pqr'\"}]")] | ||
public async Task TestSingleQuotesOnInExpression(string inExpr, string partialResult) | ||
{ | ||
// Arrange | ||
var queryUrl = $"odata/People?$filter=SSN in {inExpr}"; | ||
var request = new HttpRequestMessage(HttpMethod.Get, queryUrl); | ||
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=minimal")); | ||
var client = CreateClient(); | ||
|
||
// Act | ||
var response = await client.SendAsync(request); | ||
|
||
// Assert | ||
Assert.NotNull(response); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.NotNull(response.Content); | ||
|
||
var result = await response.Content.ReadAsStringAsync(); | ||
|
||
Assert.EndsWith($"$metadata#People\",\"value\":{partialResult}}}", result); | ||
} | ||
} | ||
} |