-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding infrastructure and rudimentary tests using OData. Ported Northwind, ComplexNavigations and GearsOfWar models. Only setup for sqlserver currently. Resolves #21402
- Loading branch information
Showing
30 changed files
with
2,013 additions
and
2 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
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
18 changes: 18 additions & 0 deletions
18
test/EFCore.OData.FunctionalTests/EFCore.OData.FunctionalTests.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks> | ||
<AssemblyName>Microsoft.EntityFrameworkCore.OData.FunctionalTests</AssemblyName> | ||
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace> | ||
<SkipTests Condition="'$(OS)' != 'Windows_NT' AND '$(Test__SqlServer__DefaultConnection)' == ''">True</SkipTests> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
19 changes: 19 additions & 0 deletions
19
test/EFCore.OData.FunctionalTests/Extensions/HttpContentExtensions.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,19 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Extensions | ||
{ | ||
public static class HttpContentExtensions | ||
{ | ||
public static async Task<T> ReadAsObject<T>(this HttpContent content) | ||
{ | ||
var json = await content.ReadAsStringAsync(); | ||
|
||
return JsonConvert.DeserializeObject<T>(json); | ||
} | ||
} | ||
} |
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,43 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Net.NetworkInformation; | ||
using System.Threading; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
public class PortArranger | ||
{ | ||
private static int _nextPort = 11000; | ||
|
||
public static int Reserve() | ||
{ | ||
var attempts = 0; | ||
while (attempts++ < 10) | ||
{ | ||
var port = Interlocked.Increment(ref _nextPort); | ||
if (port >= 65535) | ||
{ | ||
throw new OverflowException("Cannot get an available port, port value overflowed"); | ||
} | ||
|
||
if (IsFree(port)) | ||
{ | ||
return port; | ||
} | ||
} | ||
|
||
throw new TimeoutException(string.Format("Cannot get an available port in {0} attempts.", attempts)); | ||
} | ||
|
||
private static bool IsFree(int port) | ||
{ | ||
var properties = IPGlobalProperties.GetIPGlobalProperties(); | ||
var connections = properties.GetActiveTcpConnections(); | ||
|
||
return !connections.Any(c => c.LocalEndPoint.Port == port || c.RemoteEndPoint.Port == port); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
test/EFCore.OData.FunctionalTests/Properties/TestAssemblyConditions.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,7 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.EntityFrameworkCore.TestUtilities; | ||
|
||
// Skip the entire assembly if not on Windows and no external SQL Server is configured | ||
[assembly: SqlServerConfiguredCondition] |
27 changes: 27 additions & 0 deletions
27
test/EFCore.OData.FunctionalTests/Properties/launchSettings.json
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,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:64176", | ||
"sslPort": 44376 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"EFCore.OData.Tests": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
test/EFCore.OData.FunctionalTests/Query/ComplexNavigationsControllers.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,148 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNet.OData; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
public class LevelOneController : TestODataController, IDisposable | ||
{ | ||
private readonly ComplexNavigationsODataContext _context; | ||
|
||
public LevelOneController(ComplexNavigationsODataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public IEnumerable<Level1> Get() | ||
{ | ||
return _context.LevelOne; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public ITestActionResult Get([FromODataUri] int key) | ||
{ | ||
var result = _context.LevelOne.FirstOrDefault(e => e.Id == key); | ||
if (result == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(result); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
public class LevelTwoController : TestODataController, IDisposable | ||
{ | ||
private readonly ComplexNavigationsODataContext _context; | ||
|
||
public LevelTwoController(ComplexNavigationsODataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public IEnumerable<Level2> Get() | ||
{ | ||
return _context.LevelTwo; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public ITestActionResult Get([FromODataUri] int key) | ||
{ | ||
var result = _context.LevelTwo.FirstOrDefault(e => e.Id == key); | ||
if (result == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(result); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
public class LevelThreeController : TestODataController, IDisposable | ||
{ | ||
private readonly ComplexNavigationsODataContext _context; | ||
|
||
public LevelThreeController(ComplexNavigationsODataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public IEnumerable<Level3> Get() | ||
{ | ||
return _context.LevelThree; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public ITestActionResult Get([FromODataUri] int key) | ||
{ | ||
var result = _context.LevelThree.FirstOrDefault(e => e.Id == key); | ||
if (result == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(result); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
public class LevelFourController : TestODataController, IDisposable | ||
{ | ||
private readonly ComplexNavigationsODataContext _context; | ||
|
||
public LevelFourController(ComplexNavigationsODataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public IEnumerable<Level4> Get() | ||
{ | ||
return _context.LevelFour; | ||
} | ||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public ITestActionResult Get([FromODataUri] int key) | ||
{ | ||
var result = _context.LevelFour.FirstOrDefault(e => e.Id == key); | ||
if (result == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(result); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.