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

update odata tests to 8.0 #26201

Merged
merged 1 commit into from
Oct 13, 2021
Merged
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 @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.8" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel;

namespace Microsoft.EntityFrameworkCore.Query
Expand All @@ -32,7 +33,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.LevelOne.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -62,7 +63,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.LevelTwo.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -92,7 +93,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.LevelThree.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -122,7 +123,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.LevelFour.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.OData.Builder;
using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;

namespace Microsoft.EntityFrameworkCore.Query
{
Expand All @@ -24,14 +22,6 @@ public ComplexNavigationsODataQueryTestFixture()
= ODataQueryTestFixtureInitializer.Initialize<ComplexNavigationsODataContext>(StoreName, GetEdmModel());
}

public void UpdateConfigureServices<TContext>(IServiceCollection services, string storeName)
where TContext : DbContext
{
services.AddDbContext<TContext>(b =>
b.UseSqlServer(
SqlServerTestStore.CreateConnectionString(storeName)));
}

private static IEdmModel GetEdmModel()
{
var modelBuilder = new ODataConventionModelBuilder();
Expand Down
23 changes: 12 additions & 11 deletions test/EFCore.OData.FunctionalTests/Query/GearsOfWarControllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;

namespace Microsoft.EntityFrameworkCore.Query
Expand Down Expand Up @@ -39,7 +40,7 @@ public ITestActionResult Get([FromODataUri] string keyNickname, [FromODataUri] i
{
var result = _context.Gears.FirstOrDefault(e => e.Nickname == keyNickname && e.SquadId == keySquadId);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -69,7 +70,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.Squads.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -99,7 +100,7 @@ public ITestActionResult Get([FromODataUri] Guid key)
{
var result = _context.Tags.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -129,7 +130,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.Weapons.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -159,7 +160,7 @@ public ITestActionResult Get([FromODataUri] string key)
{
var result = _context.Cities.FirstOrDefault(e => e.Name == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -189,7 +190,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.Missions.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -219,7 +220,7 @@ public ITestActionResult Get([FromODataUri] int keySquadId, [FromODataUri] int k
{
var result = _context.SquadMissions.FirstOrDefault(e => e.SquadId == keySquadId && e.MissionId == keyMissionId);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -256,7 +257,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.Factions.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -293,7 +294,7 @@ public ITestActionResult Get([FromODataUri] string key)
{
var result = _context.LocustLeaders.FirstOrDefault(e => e.Name == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -323,7 +324,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.LocustHighCommands.FirstOrDefault(e => e.Id == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.OData.Builder;
using Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
using Microsoft.Extensions.Hosting;
using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;

namespace Microsoft.EntityFrameworkCore.Query
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task Basic_query_inheritance()
[ConditionalFact]
public async Task Basic_query_single_element_from_set_composite_key()
{
var requestUri = $"{BaseAddress}/odata/Gears(Nickname='Marcus', SquadId=1)";
var requestUri = $"{BaseAddress}/odata/Gears(Nickname='Marcus',SquadId=1)";
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
var response = await Client.SendAsync(request);

Expand All @@ -64,7 +64,7 @@ public async Task Basic_query_single_element_from_set_composite_key()
Assert.Equal("Marcus", result["Nickname"].ToString());
}

[ConditionalFact(Skip = "OData/WebApi#2437")]
[ConditionalFact]
public async Task Complex_query_with_any_on_collection_navigation()
{
var requestUri = string.Format(@"{0}/odata/Gears?$filter=Weapons/any(w: w/Id gt 4)", BaseAddress);
Expand Down
13 changes: 7 additions & 6 deletions test/EFCore.OData.FunctionalTests/Query/NorthwindControllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;

namespace Microsoft.EntityFrameworkCore.Query
Expand All @@ -32,7 +33,7 @@ public ITestActionResult Get([FromODataUri] string key)
{
var result = _context.Customers.FirstOrDefault(g => g.CustomerID == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -62,7 +63,7 @@ public ITestActionResult Get([FromODataUri] int key)
{
var result = _context.Orders.FirstOrDefault(e => e.OrderID == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -92,7 +93,7 @@ public ITestActionResult Get([FromODataUri] int keyOrderId, [FromODataUri] int k
{
var result = _context.OrderDetails.FirstOrDefault(e => e.OrderID == keyOrderId && e.ProductID == keyProductId);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -122,7 +123,7 @@ public ITestActionResult Get([FromODataUri] uint key)
{
var result = _context.Employees.FirstOrDefault(e => e.EmployeeID == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down Expand Up @@ -152,7 +153,7 @@ public ITestActionResult Get([FromODataUri] uint key)
{
var result = _context.Products.FirstOrDefault(e => e.ProductID == key);

return result == null ? NotFound() : (ITestActionResult)Ok(result);
return result == null ? NotFound() : Ok(result);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.OData.Builder;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Routing.Conventions;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.OData.Routing.Conventions;
using Microsoft.AspNetCore.OData.Routing.Template;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OData.Edm;
using Microsoft.OData.UriParser;
using Microsoft.OData.ModelBuilder;

namespace Microsoft.EntityFrameworkCore.Query
{
Expand All @@ -33,7 +27,7 @@ public NorthwindODataQueryTestFixture()
= ODataQueryTestFixtureInitializer.Initialize<NorthwindODataContext>(
StoreName,
GetEdmModel(),
new List<IODataRoutingConvention> { new OrderDetailsRoutingConvention() });
new List<IODataControllerActionConvention> { new OrderDetailsControllerActionConvention() });
}

private static IEdmModel GetEdmModel()
Expand Down Expand Up @@ -62,26 +56,47 @@ public override async Task DisposeAsync()
}
}

public class OrderDetailsRoutingConvention : IODataRoutingConvention
public class OrderDetailsControllerActionConvention : IODataControllerActionConvention
{
public IEnumerable<ControllerActionDescriptor> SelectAction(RouteContext routeContext)
public int Order => 0;

public bool AppliesToController(ODataControllerActionContext context)
=> context.Controller.ControllerName == "OrderDetails";

public bool AppliesToAction(ODataControllerActionContext context)
{
var odataPath = routeContext.HttpContext.ODataFeature().Path;
if (odataPath == null)
if (context.Action.ActionName == "Get")
{
return null;
}
var entitySet = context.Model.EntityContainer.FindEntitySet("Order Details");
var route = new EntitySetSegmentTemplate(entitySet);
var parameters = context.Action.ActionMethod.GetParameters();
if (parameters.Length == 0)
{
var path = new ODataPathTemplate(route);
context.Action.AddSelector("get", context.Prefix, context.Model, path, context.Options.RouteOptions);

if (odataPath.PathTemplate == "~/entityset"
&& routeContext.HttpContext.Request.Method.Equals("get", StringComparison.OrdinalIgnoreCase)
&& ((EntitySetSegment)odataPath.Segments[0]).EntitySet.Name == "Order Details")
{
return routeContext.HttpContext.RequestServices.GetRequiredService<IActionDescriptorCollectionProvider>()
.ActionDescriptors.Items.OfType<ControllerActionDescriptor>()
.Where(c => c.ControllerName == "OrderDetails" && c.ActionName == "Get");
return true;
}
else if (parameters.Length == 2
&& parameters[0].Name == "keyOrderId"
&& parameters[1].Name == "keyProductId")
{
var keys = new Dictionary<string, string>
{
{ "OrderID", "{keyOrderId}" },
{ "ProductID", "{keyProductId}" }
};

var keyTemplate = new KeySegmentTemplate(keys, entitySet.EntityType(), entitySet);

var path = new ODataPathTemplate(route, keyTemplate);
context.Action.AddSelector("get", context.Prefix, context.Model, path, context.Options.RouteOptions);

return true;
}
}

return null;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task Basic_query_select_single_customer()
Assert.Equal("ALFKI", result["CustomerID"].ToString());
}

[ConditionalFact(Skip = "OData/WebApi#2437")]
[ConditionalFact]
public async Task Query_for_alfki_expand_orders()
{
var requestUri = string.Format(@"{0}/odata/Customers?$filter=CustomerID eq 'ALFKI'&$expand=Orders", BaseAddress);
Expand Down Expand Up @@ -110,5 +110,18 @@ public async Task Basic_query_order_details()

Assert.Contains("$metadata#Order%20Details", result["@odata.context"].ToString());
}

[ConditionalFact]
public async Task Basic_query_order_details_single_element_composite_key()
{
var requestUri = $"{BaseAddress}/odata/Order Details(OrderID=10248,ProductID=11)";
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
var response = await Client.SendAsync(request);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var result = await response.Content.ReadAsObject<JObject>();

Assert.Contains("$metadata#Order%20Details", result["@odata.context"].ToString());
}
}
}
Loading