-
Notifications
You must be signed in to change notification settings - Fork 352
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
Port QueryCount and CancellationToken tests #3167
Open
WanjohiSammy
wants to merge
3
commits into
main
Choose a base branch
from
port-querycount_and_delta-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
....OData.Client.E2E.Tests/CancellationTokenTests/Server/CancellationTokenTestsController.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,143 @@ | ||||||
//----------------------------------------------------------------------------- | ||||||
// <copyright file="CancellationTokenTestsController.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.Text.RegularExpressions; | ||||||
using Microsoft.AspNetCore.Mvc; | ||||||
using Microsoft.AspNetCore.OData.Formatter; | ||||||
using Microsoft.AspNetCore.OData.Query; | ||||||
using Microsoft.AspNetCore.OData.Routing.Controllers; | ||||||
using Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd; | ||||||
|
||||||
namespace Microsoft.OData.Client.E2E.Tests.DeltaTests.Server; | ||||||
|
||||||
public class CancellationTokenTestsController : ODataController | ||||||
{ | ||||||
private static CommonEndToEndDataSource _dataSource; | ||||||
|
||||||
[EnableQuery(PageSize = 5)] | ||||||
[HttpGet("odata/Customers")] | ||||||
public IActionResult GetCustomers(CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
return Ok(_dataSource.Customers); | ||||||
} | ||||||
|
||||||
[EnableQuery] | ||||||
[HttpGet("odata/Customers({key})")] | ||||||
public IActionResult GetCustomer([FromODataUri] int key, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
var customer = _dataSource.Customers?.FirstOrDefault(c => c.CustomerId == key); | ||||||
if (customer == null) | ||||||
{ | ||||||
return NotFound(); | ||||||
} | ||||||
|
||||||
return Ok(customer); | ||||||
} | ||||||
|
||||||
[HttpPost("odata/Customers")] | ||||||
public IActionResult AddCustomer([FromBody] Customer customer, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
_dataSource.Customers?.Add(customer); | ||||||
return Created(customer); | ||||||
} | ||||||
|
||||||
[HttpPost("odata/Customers({key})/Default.ChangeCustomerAuditInfo")] | ||||||
public IActionResult ChangeCustomerAuditInfo([FromODataUri] int key, [FromBody] AuditInfo auditInfo, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
var customer = _dataSource.Customers?.FirstOrDefault(c => c.CustomerId == key); | ||||||
if (customer == null) | ||||||
{ | ||||||
return NotFound(); | ||||||
} | ||||||
|
||||||
customer.Auditing = auditInfo; | ||||||
return Created(auditInfo); | ||||||
} | ||||||
|
||||||
[HttpPost("odata/Customers({key})/Orders/$ref")] | ||||||
public IActionResult AddOrderRefToCustomer([FromODataUri] int key, [FromBody] Uri orderUri, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
if (orderUri == null) | ||||||
{ | ||||||
return BadRequest(); | ||||||
} | ||||||
|
||||||
// Extract the order ID from the URI | ||||||
var lastSegment = orderUri.Segments.Last(); | ||||||
var orderId = int.Parse(Regex.Match(lastSegment, @"\d+").Value); | ||||||
|
||||||
// Find the order by ID | ||||||
var order = _dataSource.Orders?.SingleOrDefault(d => d.OrderId == orderId); | ||||||
if (order == null) | ||||||
{ | ||||||
return NotFound(); | ||||||
} | ||||||
|
||||||
// Add the order reference to the customer | ||||||
var customer = _dataSource.Customers?.SingleOrDefault(c => c.CustomerId == key); | ||||||
if (customer == null) | ||||||
{ | ||||||
return NotFound(); | ||||||
} | ||||||
|
||||||
customer.Orders ??= []; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The empty array initialization is incorrect.
Suggested change
Copilot is powered by AI, so mistakes are possible. Review output carefully before use. |
||||||
customer.Orders.Add(order); | ||||||
|
||||||
return Ok(customer); | ||||||
} | ||||||
|
||||||
[HttpPost("odata/Orders")] | ||||||
public IActionResult AddOrder([FromBody] Order order, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
_dataSource.Orders?.Add(order); | ||||||
return Created(order); | ||||||
} | ||||||
|
||||||
[HttpPost("odata/Cars")] | ||||||
public async Task<IActionResult> AddCar([FromBody] Car car, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
_dataSource.Cars?.Add(car); | ||||||
return Created(car); | ||||||
} | ||||||
|
||||||
[HttpPut("odata/Cars({key})/Photo")] | ||||||
public IActionResult UpdateCarPhoto([FromODataUri] int key, CancellationToken cancellationToken) | ||||||
{ | ||||||
cancellationToken.ThrowIfCancellationRequested(); | ||||||
|
||||||
var car = _dataSource.Cars?.FirstOrDefault(c => c.VIN == key); | ||||||
if (car == null) | ||||||
{ | ||||||
return NotFound(); | ||||||
} | ||||||
|
||||||
var photo = Request.Body; | ||||||
car.Photo = photo; | ||||||
return Ok(); | ||||||
} | ||||||
|
||||||
[HttpPost("odata/cancellationtokentests/Default.ResetDefaultDataSource")] | ||||||
public IActionResult ResetDefaultDataSource() | ||||||
{ | ||||||
_dataSource = CommonEndToEndDataSource.CreateInstance(); | ||||||
|
||||||
return Ok(); | ||||||
} | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The semicolon should be replaced with a curly brace to properly define the namespace.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.