-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b36f3d3
commit fa81478
Showing
12 changed files
with
595 additions
and
72 deletions.
There are no files selected for viewing
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
306 changes: 238 additions & 68 deletions
306
src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSetSerializer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
128 changes: 128 additions & 0 deletions
128
.../Microsoft.AspNetCore.OData.E2E.Tests/IAsyncEnumerableTests/IAsyncEnumerableController.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,128 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="IAsyncEnumerableController.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 System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Query; | ||
using Microsoft.AspNetCore.OData.Routing.Controllers; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.IAsyncEnumerableTests | ||
{ | ||
public class CustomersController : ODataController | ||
{ | ||
private readonly IAsyncEnumerableContext _context; | ||
|
||
public CustomersController(IAsyncEnumerableContext context) | ||
{ | ||
context.Database.EnsureCreated(); | ||
_context = context; | ||
|
||
if (!_context.Customers.Any()) | ||
{ | ||
Generate(); | ||
} | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("v1/Customers")] | ||
public IAsyncEnumerable<Customer> CustomersData() | ||
{ | ||
IAsyncEnumerable<Customer> customers = CreateCollectionAsync<Customer>(); | ||
|
||
return customers; | ||
} | ||
|
||
[EnableQuery] | ||
[HttpGet("odata/Customers")] | ||
public IAsyncEnumerable<Customer> Get() | ||
{ | ||
return _context.Customers.AsAsyncEnumerable(); | ||
} | ||
|
||
public async IAsyncEnumerable<Customer> CreateCollectionAsync<T>() | ||
{ | ||
await Task.Delay(5); | ||
// Yield the items one by one asynchronously | ||
yield return new Customer | ||
{ | ||
Id = 1, | ||
Name = "Customer1", | ||
Orders = new List<Order> { | ||
new Order { | ||
Name = "Order1", | ||
Price = 25 | ||
}, | ||
new Order { | ||
Name = "Order2", | ||
Price = 75 | ||
} | ||
}, | ||
Address = new Address | ||
{ | ||
Name = "City1", | ||
Street = "Street1" | ||
} | ||
}; | ||
|
||
await Task.Delay(5); | ||
|
||
yield return new Customer | ||
{ | ||
Id = 2, | ||
Name = "Customer2", | ||
Orders = new List<Order> { | ||
new Order { | ||
Name = "Order1", | ||
Price = 35 | ||
}, | ||
new Order { | ||
Name = "Order2", | ||
Price = 65 | ||
} | ||
}, | ||
Address = new Address | ||
{ | ||
Name = "City2", | ||
Street = "Street2" | ||
} | ||
}; | ||
} | ||
|
||
public void Generate() | ||
{ | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
var customer = new Customer | ||
{ | ||
Name = "Customer" + (i + 1) % 2, | ||
Orders = | ||
new List<Order> { | ||
new Order { | ||
Name = "Order" + 2*i, | ||
Price = i * 25 | ||
}, | ||
new Order { | ||
Name = "Order" + 2*i+1, | ||
Price = i * 75 | ||
} | ||
}, | ||
Address = new Address | ||
{ | ||
Name = "City" + i % 2, | ||
Street = "Street" + i % 2, | ||
} | ||
}; | ||
|
||
_context.Customers.Add(customer); | ||
} | ||
|
||
_context.SaveChanges(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
test/Microsoft.AspNetCore.OData.E2E.Tests/IAsyncEnumerableTests/IAsyncEnumerableDataModel.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,54 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="IAsyncEnumerableDataModel.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.EntityFrameworkCore; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.IAsyncEnumerableTests | ||
{ | ||
public class IAsyncEnumerableContext : DbContext | ||
{ | ||
public IAsyncEnumerableContext(DbContextOptions<IAsyncEnumerableContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Customer> Customers { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Customer>().OwnsOne(c => c.Address).WithOwner(); | ||
} | ||
} | ||
|
||
public class Customer | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public Address Address { get; set; } | ||
|
||
public IList<Order> Orders { get; set; } | ||
} | ||
|
||
public class Order | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public int Price { get; set; } | ||
} | ||
|
||
public class Address | ||
{ | ||
public string Name { get; set; } | ||
|
||
public string Street { get; set; } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
test/Microsoft.AspNetCore.OData.E2E.Tests/IAsyncEnumerableTests/IAsyncEnumerableEdmModel.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,24 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="IAsyncEnumerableEdmModel.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.IAsyncEnumerableTests | ||
{ | ||
public class IAsyncEnumerableEdmModel | ||
{ | ||
public static IEdmModel GetEdmModel() | ||
{ | ||
var builder = new ODataConventionModelBuilder(); | ||
builder.EntitySet<Customer>("Customers"); | ||
builder.EntitySet<Order>("Orders"); | ||
IEdmModel model = builder.GetEdmModel(); | ||
return model; | ||
} | ||
} | ||
} |
Oops, something went wrong.