-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update AspNetCoreOData version to 9.1.1 * Port QueryOption Tests
- Loading branch information
1 parent
70eef8a
commit 843ac15
Showing
14 changed files
with
1,625 additions
and
11 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
...Tests/Common/Microsoft.OData.Client.E2E.TestCommon/Helpers/ODataValueAssertEqualHelper.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,123 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="ODataValueAssertEqualHelper.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.OData.Client.E2E.TestCommon.Helpers; | ||
|
||
public static class ODataValueAssertEqualHelper | ||
{ | ||
#region Util methods to AssertEqual ODataValues | ||
|
||
public static void AssertODataValueEqual(ODataValue expected, ODataValue actual) | ||
{ | ||
ODataPrimitiveValue expectedPrimitiveValue = expected as ODataPrimitiveValue; | ||
ODataPrimitiveValue actualPrimitiveValue = actual as ODataPrimitiveValue; | ||
if (expectedPrimitiveValue != null && actualPrimitiveValue != null) | ||
{ | ||
AssertODataPrimitiveValueEqual(expectedPrimitiveValue, actualPrimitiveValue); | ||
} | ||
else | ||
{ | ||
ODataEnumValue expectedEnumValue = expected as ODataEnumValue; | ||
ODataEnumValue actualEnumValue = actual as ODataEnumValue; | ||
if (expectedEnumValue != null && actualEnumValue != null) | ||
{ | ||
AssertODataEnumValueEqual(expectedEnumValue, actualEnumValue); | ||
} | ||
else | ||
{ | ||
ODataCollectionValue expectedCollectionValue = (ODataCollectionValue)expected; | ||
ODataCollectionValue actualCollectionValue = (ODataCollectionValue)actual; | ||
AssertODataCollectionValueEqual(expectedCollectionValue, actualCollectionValue); | ||
} | ||
} | ||
} | ||
|
||
private static void AssertODataCollectionValueEqual(ODataCollectionValue expectedCollectionValue, ODataCollectionValue actualCollectionValue) | ||
{ | ||
Assert.NotNull(expectedCollectionValue); | ||
Assert.NotNull(actualCollectionValue); | ||
Assert.Equal(expectedCollectionValue.TypeName, actualCollectionValue.TypeName); | ||
var expectedItemsArray = expectedCollectionValue.Items.OfType<object>().ToArray(); | ||
var actualItemsArray = actualCollectionValue.Items.OfType<object>().ToArray(); | ||
|
||
Assert.Equal(expectedItemsArray.Length, actualItemsArray.Length); | ||
for (int i = 0; i < expectedItemsArray.Length; i++) | ||
{ | ||
var expectedOdataValue = expectedItemsArray[i] as ODataValue; | ||
var actualOdataValue = actualItemsArray[i] as ODataValue; | ||
if (expectedOdataValue != null && actualOdataValue != null) | ||
{ | ||
AssertODataValueEqual(expectedOdataValue, actualOdataValue); | ||
} | ||
else | ||
{ | ||
Assert.Equal(expectedItemsArray[i], actualItemsArray[i]); | ||
} | ||
} | ||
} | ||
|
||
public static void AssertODataPropertiesEqual(IEnumerable<ODataProperty> expectedProperties, IEnumerable<ODataProperty> actualProperties) | ||
{ | ||
if (expectedProperties == null && actualProperties == null) | ||
{ | ||
return; | ||
} | ||
|
||
Assert.NotNull(expectedProperties); | ||
Assert.NotNull(actualProperties); | ||
var expectedPropertyArray = expectedProperties.ToArray(); | ||
var actualPropertyArray = actualProperties.ToArray(); | ||
Assert.Equal(expectedPropertyArray.Length, actualPropertyArray.Length); | ||
for (int i = 0; i < expectedPropertyArray.Length; i++) | ||
{ | ||
AssertODataPropertyEqual(expectedPropertyArray[i], actualPropertyArray[i]); | ||
} | ||
} | ||
|
||
public static void AssertODataPropertyEqual(ODataProperty expectedOdataProperty, ODataProperty actualOdataProperty) | ||
{ | ||
Assert.NotNull(expectedOdataProperty); | ||
Assert.NotNull(actualOdataProperty); | ||
Assert.Equal(expectedOdataProperty.Name, actualOdataProperty.Name); | ||
AssertODataValueEqual(ToODataValue(expectedOdataProperty.Value), ToODataValue(actualOdataProperty.Value)); | ||
} | ||
|
||
private static ODataValue ToODataValue(object value) | ||
{ | ||
if (value == null) | ||
{ | ||
return new ODataNullValue(); | ||
} | ||
|
||
var odataValue = value as ODataValue; | ||
if (odataValue != null) | ||
{ | ||
return odataValue; | ||
} | ||
|
||
return new ODataPrimitiveValue(value); | ||
} | ||
|
||
private static void AssertODataPrimitiveValueEqual(ODataPrimitiveValue expectedPrimitiveValue, ODataPrimitiveValue actualPrimitiveValue) | ||
{ | ||
Assert.NotNull(expectedPrimitiveValue); | ||
Assert.NotNull(actualPrimitiveValue); | ||
Assert.Equal(expectedPrimitiveValue.Value, actualPrimitiveValue.Value); | ||
} | ||
|
||
private static void AssertODataEnumValueEqual(ODataEnumValue expectedEnumValue, ODataEnumValue actualEnumValue) | ||
{ | ||
Assert.NotNull(expectedEnumValue); | ||
Assert.NotNull(actualEnumValue); | ||
Assert.Equal(expectedEnumValue.Value, actualEnumValue.Value); | ||
Assert.Equal(expectedEnumValue.TypeName, actualEnumValue.TypeName); | ||
} | ||
|
||
#endregion Util methods to AssertEqual ODataValues | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...EndToEndTests/Common/Microsoft.OData.Client.E2E.TestCommon/Logs/LogAssertTraceListener.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,31 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="LogAssertTraceListener.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.Diagnostics; | ||
|
||
namespace Microsoft.OData.Client.E2E.TestCommon.Logs; | ||
|
||
public class LogAssertTraceListener : TraceListener | ||
{ | ||
public LogAssertTraceListener() | ||
{ | ||
// Clear existing listeners and add this listener | ||
Trace.Listeners.Clear(); | ||
Trace.Listeners.Add(this); | ||
} | ||
|
||
public override void Write(string? message) { } | ||
|
||
public override void WriteLine(string? message) { } | ||
|
||
public override void Fail(string? message, string? detailMessage) | ||
{ | ||
// Log the assertion failure | ||
Console.WriteLine($"DEBUG ASSERTION FAILED: {message} {detailMessage}"); | ||
} | ||
} | ||
|
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
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
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
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
118 changes: 118 additions & 0 deletions
118
...nt/Microsoft.OData.Client.E2E.Tests/QueryOptionTests/Server/QueryOptionTestsController.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,118 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="QueryOptionTestsController.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Query; | ||
using Microsoft.AspNetCore.OData.Routing.Controllers; | ||
using Microsoft.OData.Client.E2E.Tests.Common.Server.Default; | ||
|
||
namespace Microsoft.OData.Client.E2E.Tests.QueryOptionTests.Server | ||
{ | ||
public class QueryOptionTestsController : ODataController | ||
{ | ||
private static DefaultDataSource _dataSource; | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/Products")] | ||
public IActionResult GetProducts() | ||
{ | ||
var products = _dataSource.Products; | ||
|
||
return Ok(products); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/Products({key})")] | ||
public IActionResult GetProduct([FromRoute] int key) | ||
{ | ||
var product = _dataSource.Products?.SingleOrDefault(a => a.ProductID == key); | ||
|
||
if (product == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(product); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/People")] | ||
public IActionResult GetPeople() | ||
{ | ||
var people = _dataSource.People; | ||
|
||
return Ok(people); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/People({key})")] | ||
public IActionResult GetPerson([FromRoute] int key) | ||
{ | ||
var person = _dataSource.People?.SingleOrDefault(a => a.PersonID == key); | ||
|
||
if (person == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(person); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/Customers")] | ||
public IActionResult GetCustomers() | ||
{ | ||
var customers = _dataSource.Customers; | ||
|
||
return Ok(customers); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/Customers({key})")] | ||
public IActionResult GetCustomer([FromRoute] int key) | ||
{ | ||
var customer = _dataSource.Customers?.SingleOrDefault(a => a.PersonID == key); | ||
|
||
if (customer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customer); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/Customers({key})/Numbers")] | ||
public IActionResult GetNumbersFromCustomer([FromRoute] int key) | ||
{ | ||
var customer = _dataSource.Customers?.SingleOrDefault(a => a.PersonID == key); | ||
|
||
if (customer == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(customer.Numbers); | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/ProductDetails")] | ||
public IActionResult GetProductDetails() | ||
{ | ||
var productDetails = _dataSource.ProductDetails; | ||
|
||
return Ok(productDetails); | ||
} | ||
|
||
[HttpPost("odata/queryoption/Default.ResetDefaultDataSource")] | ||
public IActionResult ResetDefaultDataSource() | ||
{ | ||
_dataSource = DefaultDataSource.CreateInstance(); | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
Oops, something went wrong.