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

Port Key As Segment Tests #3172

Open
wants to merge 3 commits 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 @@ -4225,6 +4225,7 @@ public CustomerInfoSingle(global::Microsoft.OData.Client.DataServiceQuerySingle<
/// CustomerInfoId
/// </KeyProperties>
[global::Microsoft.OData.Client.Key("CustomerInfoId")]
[global::Microsoft.OData.Client.HasStream()]
[global::Microsoft.OData.Client.OriginalNameAttribute("CustomerInfo")]
public partial class CustomerInfo : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged
{
Expand Down Expand Up @@ -5690,6 +5691,7 @@ public CarSingle(global::Microsoft.OData.Client.DataServiceQuerySingle<Car> quer
/// VIN
/// </KeyProperties>
[global::Microsoft.OData.Client.Key("VIN")]
[global::Microsoft.OData.Client.HasStream()]
[global::Microsoft.OData.Client.OriginalNameAttribute("Car")]
public partial class Car : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<Property Name="PhotoId" Type="Edm.Int32" Nullable="false" />
<Property Name="Photo" Type="Edm.Binary" />
</EntityType>
<EntityType Name="CustomerInfo">
<EntityType Name="CustomerInfo" HasStream="true">
<Key>
<PropertyRef Name="CustomerInfoId" />
</Key>
Expand Down Expand Up @@ -287,7 +287,7 @@
<Property Name="ComplexPhone" Type="Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Phone" />
<Property Name="ComplexContactDetails" Type="Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.ContactDetails" />
</EntityType>
<EntityType Name="Car">
<EntityType Name="Car" HasStream="true">
<Key>
<PropertyRef Name="VIN" />
</Key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//------------------------------------------------------------------------------

using Microsoft.OData.ModelBuilder;
using Microsoft.Spatial;
using EfKey = System.ComponentModel.DataAnnotations.KeyAttribute;

Expand Down Expand Up @@ -182,6 +183,7 @@ public class ProductPhoto
public byte[]? Photo { get; set; }
}

[MediaType]
public class CustomerInfo
{
public int CustomerInfoId { get; set; }
Expand Down Expand Up @@ -250,6 +252,7 @@ public class MappedEntityType
public ContactDetails? ComplexContactDetails { get; set; }
}

[MediaType]
public class Car
{
[EfKey]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//---------------------------------------------------------------------
// <copyright file="DollarSegmentTestsController.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.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.KeyAsSegmentTests.Server;

public class DollarSegmentTestsController : ODataController
{
private static CommonEndToEndDataSource _dataSource;

[EnableQuery]
[HttpGet("odata/People/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Employee")]
public IActionResult GetPeopleOfTypeEmployee()
{
var people = _dataSource.People?.OfType<Employee>();
return Ok(people);
}

[EnableQuery]
[HttpGet("odata/People/{key}/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Employee/$/Salary")]
public IActionResult GetEmployeeSalary([FromRoute] int key)
{
var employee = _dataSource.People?.OfType<Employee>().SingleOrDefault(a => a.PersonId == key);
if (employee == null)
{
return NotFound();
}
return Ok(employee.Salary);
}

[EnableQuery]
[HttpGet("odata/Products/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.DiscontinuedProduct/{key}/RelatedProducts/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.DiscontinuedProduct/{relatedKey}/Photos")]
public IActionResult GetProductRelatedPhotos([FromRoute] int key, [FromRoute] int relatedKey)
{
var product = _dataSource.Products?.SingleOrDefault(a => a.ProductId == key);
if (product == null)
{
return NotFound();
}

var relatedProduct = product.RelatedProducts?.SingleOrDefault(a => a.ProductId == relatedKey);
if (relatedProduct == null)
{
return NotFound();
}

return Ok(relatedProduct.Photos);
}

[EnableQuery]
[HttpGet("odata/Products/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.DiscontinuedProduct")]
public IActionResult GetDiscontinuedProducts()
{
var discontinuedProducts = _dataSource.Products?.OfType<DiscontinuedProduct>();

return Ok(discontinuedProducts);
}

[EnableQuery]
[HttpGet("odata/Products/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.DiscontinuedProduct/$")]
public IActionResult GetAnotherDiscontinuedProducts()
{
var discontinuedProducts = _dataSource.Products?.OfType<DiscontinuedProduct>();

return Ok(discontinuedProducts);
}

[EnableQuery]
[HttpGet("odata/Products/$/$/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.DiscontinuedProduct")]
public IActionResult GetDiscontinuedProductsMultipleDollarSegments()
{
var discontinuedProducts = _dataSource.Products?.OfType<DiscontinuedProduct>();

return Ok(discontinuedProducts);
}

[EnableQuery]
[HttpGet("odata/Login")]
public IActionResult GetLogin()
{
var login = _dataSource.Logins;
return Ok(login);
}

[HttpPost("odata/People/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Employee/$/Default.IncreaseSalaries")]
public IActionResult IncreaseSalaries([FromODataBody] int n)
{
_dataSource.People?.OfType<Employee>().ToList().ForEach(e => e.Salary += n);
return Ok();
}

[HttpPost("odata/People/$/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Employee/$/$/Default.IncreaseSalaries")]
public IActionResult IncreaseSalariesMultipleDollarSegments([FromODataBody] int n)
{
_dataSource.People?.OfType<Employee>().ToList().ForEach(e => e.Salary += n);
return Ok();
}

[HttpPost("odata/People/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Employee/$/Default.IncreaseSalaries/$")]
public IActionResult IncreaseSalariesDollarSegmentAtUriEnd([FromODataBody] int n)
{
_dataSource.People?.OfType<Employee>().ToList().ForEach(e => e.Salary += n);
return Ok();
}

[HttpPost("odata/People/$/Microsoft.OData.Client.E2E.Tests.Common.Server.EndToEnd.Employee/{key}/$/Default.Sack")]
public IActionResult Sack([FromODataUri] int key)
{
var employee = _dataSource.People?.OfType<Employee>().SingleOrDefault(a => a.PersonId == key);
if (employee == null)
{
return NotFound();
}

_dataSource.People?.Remove(employee);
return NoContent();
}

[HttpPost("odata/Login")]
public IActionResult PostLogin([FromBody] Login login)
{
_dataSource.Logins?.Add(login);
return Created(login);
}

[HttpPost("odata/dollarsegmenttests/Default.ResetDefaultDataSource")]
public IActionResult ResetDefaultDataSource()
{
_dataSource = CommonEndToEndDataSource.CreateInstance();

return Ok();
}
}
Loading