-
Notifications
You must be signed in to change notification settings - Fork 164
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
unittest derived interfaces #470
Open
manureini
wants to merge
1
commit into
OData:release-8.x
Choose a base branch
from
manureini:main
base: release-8.x
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
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
55 changes: 55 additions & 0 deletions
55
test/Microsoft.AspNetCore.OData.E2E.Tests/DerivedInterfaces/DerivedInterfacesControllers.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,55 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DerivedInterfacesControllers.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 Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Formatter; | ||
using Microsoft.AspNetCore.OData.Query; | ||
using Microsoft.AspNetCore.OData.Routing.Controllers; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DerivedInterfaces | ||
{ | ||
public class CustomersController : ODataController | ||
{ | ||
static List<Customer> Customers { get; set; } | ||
|
||
static CustomersController() | ||
{ | ||
Customers = new List<Customer> | ||
{ | ||
new Customer { | ||
Id = 1, | ||
Name = "Customer 1", | ||
Order = new VipOrder() | ||
{ | ||
Id = 10, | ||
Product = "Test Product 1", | ||
LoyaltyCardNo = "42" | ||
} | ||
}, | ||
new Customer { | ||
Id = 2, | ||
Name = "Customer 1", | ||
Order = new VipOrder() | ||
{ | ||
Id = 11, | ||
Product = "Test Product 2", | ||
LoyaltyCardNo = "43" | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)] | ||
[HttpGet("odata/Customers/Microsoft.AspNetCore.OData.E2E.Tests.DerivedInterfaces.Customers")] | ||
public IActionResult Get() | ||
{ | ||
return Ok(Customers); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
test/Microsoft.AspNetCore.OData.E2E.Tests/DerivedInterfaces/DerivedInterfacesDataModel.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,34 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DerivedInterfacesDataModel.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.DerivedInterfaces | ||
{ | ||
public class Customer : IIdentifiable | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
|
||
public IOrder Order { get; set; } | ||
} | ||
|
||
public class VipOrder : IOrder | ||
{ | ||
public int Id { get; set; } | ||
public string Product { get; set; } | ||
public string LoyaltyCardNo { get; set; } | ||
} | ||
|
||
public interface IOrder : IIdentifiable | ||
{ | ||
public string Product { get; set; } | ||
} | ||
|
||
public interface IIdentifiable | ||
{ | ||
public int Id { get; set; } | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
test/Microsoft.AspNetCore.OData.E2E.Tests/DerivedInterfaces/DerivedInterfacesTests.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,59 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="DerivedInterfacesTests.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.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.OData.TestCommon; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.ModelBuilder; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.OData.E2E.Tests.DerivedInterfaces | ||
{ | ||
public class DerivedTypeTests : WebApiTestBase<DerivedTypeTests> | ||
{ | ||
public DerivedTypeTests(WebApiTestFixture<DerivedTypeTests> fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
protected static void UpdateConfigureServices(IServiceCollection services) | ||
{ | ||
services.ConfigureControllers(typeof(CustomersController)); | ||
services.AddControllers().AddOData(opt => opt.AddRouteComponents("odata", GetEdmModel()).Count().Filter().OrderBy().Expand().SetMaxTop(null).Select()); | ||
} | ||
|
||
private static IEdmModel GetEdmModel() | ||
{ | ||
ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); | ||
builder.EntitySet<Customer>("Customers"); | ||
return builder.GetEdmModel(); | ||
} | ||
|
||
[Fact] | ||
public async Task QueryCustomersFiltered() | ||
{ | ||
// Arrange | ||
string requestUri = "/odata/Customers?$filter=Order/Id eq 11"; | ||
|
||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri); | ||
HttpClient client = CreateClient(); | ||
|
||
// Act | ||
HttpResponseMessage response = await client.SendAsync(request); | ||
string py = await response.Content.ReadAsStringAsync(); | ||
|
||
// Assert | ||
Assert.DoesNotContain("error", py); | ||
Assert.True(response.IsSuccessStatusCode); | ||
|
||
string expectedContent = "\"Id\":2,\"Name\":\"Customer 1\""; | ||
Assert.Contains(expectedContent, expectedContent); | ||
} | ||
} | ||
} |
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.
This implements
IDisposable
. Please wrap it in ausing
block