Skip to content

Use Mvc.Core instead of Mvc #300

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

Merged
merged 5 commits into from
Jun 14, 2018
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: csharp
dist: trusty
sudo: required
services:
services:
- postgresql
before_script:
- psql -c 'create database JsonApiDotNetCoreExample;' -U postgres
mono: none
dotnet: 2.1.105 # https://www.microsoft.com/net/download/linux
dotnet: 2.1.300 # https://www.microsoft.com/net/download/linux
branches:
only:
- master
Expand Down
27 changes: 13 additions & 14 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@
<NetCoreAppVersion>netcoreapp2.0</NetCoreAppVersion>
<NetStandardVersion>netstandard2.0</NetStandardVersion>

<AspNetCoreVersion>2.0.1</AspNetCoreVersion>
<AspNetCoreVersion>2.1.0</AspNetCoreVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit nervous about pushing this in a non-major release until #281 is done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could get #281 and bump the version or just release it. I suspect there will be no significant issues since 2.0 to 2.1 is more of a performance upgrade so just releasing might be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi - I've started this work over in #302 , should have it done tonight or tomorrow....the fix for the failing tests here will be the same as in that PR.


<MicrosoftLoggingVersion>2.0.0</MicrosoftLoggingVersion>
<MicrosoftConfigurationVersion>2.0.0</MicrosoftConfigurationVersion>
<MicrosoftOptionsVersion>2.0.0</MicrosoftOptionsVersion>
<MicrosoftLoggingVersion>2.1.0</MicrosoftLoggingVersion>
<MicrosoftConfigurationVersion>2.1.0</MicrosoftConfigurationVersion>
<MicrosoftOptionsVersion>2.1.0</MicrosoftOptionsVersion>

<EFCoreVersion>2.0.1</EFCoreVersion>
<EFCoreToolsVersion>2.0.1</EFCoreToolsVersion>
<EFCoreVersion>2.1.0</EFCoreVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is failing because of this. We do some reflection on EF APIs to check the actual SQL output of queries (ToSql). Looks like these properties no longer exist or were renamed.

private static readonly PropertyInfo NodeTypeProviderField = QueryCompilerTypeInfo.DeclaredProperties.Single(x => x.Name == "NodeTypeProvider");

var resultSql = StringExtensions.Normalize(query.ToSql());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#302 has a fix for this and includes the tests for the prior frameworks. I'll probably merge that in tonight and then you can rebase onto those changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to hold on #302 for now. I'm going to merge this in and get a release started.

<EFCoreToolsVersion>2.1.0</EFCoreToolsVersion>

<NpgsqlVersion>3.2.6</NpgsqlVersion>
<NpgsqlPostgreSQLVersion>2.0.0</NpgsqlPostgreSQLVersion>
<NpgsqlVersion>4.0.0</NpgsqlVersion>
<NpgsqlPostgreSQLVersion>2.1.0</NpgsqlPostgreSQLVersion>

<TuplesVersion>4.4.0</TuplesVersion>
<TuplesVersion>4.5.0</TuplesVersion>
</PropertyGroup>

<!-- Test Project Dependencies -->
<PropertyGroup>
<TestSdkVersion>15.3.0-preview-20170427-09</TestSdkVersion>
<TestHostVersion>1.1.2</TestHostVersion>
<XUnitVersion>2.3.0-beta3-build3705</XUnitVersion>
<BogusVersion>15.0.3</BogusVersion>
<MoqVersion>4.7.99</MoqVersion>
<TestSdkVersion>15.7.2</TestSdkVersion>
<XUnitVersion>2.3.1</XUnitVersion>
<BogusVersion>22.1.2</BogusVersion>
<MoqVersion>4.8.3</MoqVersion>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>Benchmarks</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.10" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" />
<PackageReference Include="moq" Version="$(MoqVersion)" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace JsonApiDotNetCoreExample.Controllers.Restricted
{
[Route("[controller]")]
[HttpReadOnly]
public class ReadOnlyController : Controller
public class ReadOnlyController : ControllerBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I've been wanting to do this for a while. I don't think anyone is generating views via their JADNC controllers, but if they are this would be a breaking change 🤔 ... I think this is the right direction. Just wondering about versioning.

{
[HttpGet]
public IActionResult Get() => Ok();
Expand All @@ -22,7 +22,7 @@ public class ReadOnlyController : Controller

[Route("[controller]")]
[NoHttpPost]
public class NoHttpPostController : Controller
public class NoHttpPostController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
Expand All @@ -39,7 +39,7 @@ public class NoHttpPostController : Controller

[Route("[controller]")]
[NoHttpPatch]
public class NoHttpPatchController : Controller
public class NoHttpPatchController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
Expand All @@ -56,7 +56,7 @@ public class NoHttpPatchController : Controller

[Route("[controller]")]
[NoHttpDelete]
public class NoHttpDeleteController : Controller
public class NoHttpDeleteController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace JsonApiDotNetCoreExample.Controllers
{
[Route("[controller]")]
public class TestValuesController : Controller
public class TestValuesController : ControllerBase
{
[HttpGet]
public IActionResult Get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ public CustomJsonApiController(
}

public class CustomJsonApiController<T, TId>
: Controller where T : class, IIdentifiable<TId>
: ControllerBase where T : class, IIdentifiable<TId>
{
private readonly ILogger _logger;
private readonly IResourceService<T, TId> _resourceService;
private readonly IJsonApiContext _jsonApiContext;

protected IActionResult UnprocessableEntity()
{
return new StatusCodeResult(422);
}

protected IActionResult Forbidden()
{
return new StatusCodeResult(403);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreToolsVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace JsonApiDotNetCoreExample.Migrations
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using JsonApiDotNetCoreExample.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand All @@ -7,6 +7,7 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using System;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace JsonApiDotNetCoreExample.Migrations
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(MicrosoftLoggingVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion)" />
<PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="Dapper" Version="1.50.5" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Examples/NoEntityFrameworkExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Startup(IHostingEnvironment env)
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add framework services.
var mvcBuilder = services.AddMvc();
var mvcBuilder = services.AddMvcCore();

services.AddJsonApi(options => {
options.Namespace = "api/v1";
Expand Down
1 change: 1 addition & 0 deletions src/Examples/OperationsExample/OperationsExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreToolsVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Examples/ReportsExample/ReportsExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(MicrosoftLoggingVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion)" />
<PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="Dapper" Version="1.50.5" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Examples/ReportsExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Startup(IHostingEnvironment env)

public virtual void ConfigureServices(IServiceCollection services)
{
var mvcBuilder = services.AddMvc();
var mvcBuilder = services.AddMvcCore();
services.AddJsonApi(opt =>
{
opt.BuildContextGraph(builder =>
Expand Down
22 changes: 9 additions & 13 deletions src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@

namespace JsonApiDotNetCore.Controllers
{
public abstract class JsonApiControllerMixin : Controller
public abstract class JsonApiControllerMixin : ControllerBase
{
protected IActionResult UnprocessableEntity()
{
return new StatusCodeResult(422);
}

protected IActionResult Forbidden()
{
return new StatusCodeResult(403);
Expand All @@ -23,18 +18,19 @@ protected IActionResult Error(Error error)
{
Errors = new List<Error> { error }
};
var result = new ObjectResult(errorCollection);
result.StatusCode = error.StatusCode;

return result;
return new ObjectResult(errorCollection)
{
StatusCode = error.StatusCode
};
}

protected IActionResult Errors(ErrorCollection errors)
{
var result = new ObjectResult(errors);
result.StatusCode = GetErrorStatusCode(errors);

return result;
return new ObjectResult(errors)
{
StatusCode = GetErrorStatusCode(errors)
};
}

private int GetErrorStatusCode(ErrorCollection errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.Controllers
/// <summary>
/// A controller to be used for bulk operations as defined in the json:api 1.1 specification
/// </summary>
public class JsonApiOperationsController : Controller
public class JsonApiOperationsController : ControllerBase
{
private readonly IOperationsProcessor _operationsProcessor;

Expand Down
10 changes: 5 additions & 5 deletions src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ public static class IServiceCollectionExtensions
public static IServiceCollection AddJsonApi<TContext>(this IServiceCollection services)
where TContext : DbContext
{
var mvcBuilder = services.AddMvc();
return AddJsonApi<TContext>(services, (opt) => { }, mvcBuilder);
var mvcBuilder = services.AddMvcCore();
return AddJsonApi<TContext>(services, opt => { }, mvcBuilder);
}

public static IServiceCollection AddJsonApi<TContext>(this IServiceCollection services, Action<JsonApiOptions> options)
where TContext : DbContext
{
var mvcBuilder = services.AddMvc();
var mvcBuilder = services.AddMvcCore();
return AddJsonApi<TContext>(services, options, mvcBuilder);
}

public static IServiceCollection AddJsonApi<TContext>(this IServiceCollection services,
Action<JsonApiOptions> options,
IMvcBuilder mvcBuilder) where TContext : DbContext
IMvcCoreBuilder mvcBuilder) where TContext : DbContext
{
var config = new JsonApiOptions();

Expand All @@ -57,7 +57,7 @@ public static IServiceCollection AddJsonApi<TContext>(this IServiceCollection se

public static IServiceCollection AddJsonApi(this IServiceCollection services,
Action<JsonApiOptions> options,
IMvcBuilder mvcBuilder)
IMvcCoreBuilder mvcBuilder)
{
var config = new JsonApiOptions();

Expand Down
9 changes: 5 additions & 4 deletions src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.2.5</VersionPrefix>
<VersionPrefix>2.3.0</VersionPrefix>
<TargetFrameworks>$(NetStandardVersion)</TargetFrameworks>
<AssemblyName>JsonApiDotNetCore</AssemblyName>
<PackageId>JsonApiDotNetCore</PackageId>
Expand All @@ -17,12 +17,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.1.0" />
<PackageReference Include="Ben.Demystifier" Version="0.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftLoggingVersion)" />
<PackageReference Include="System.Memory" Version="4.5.0-preview2-26406-04" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Memory" Version="4.5.0" />
<PackageReference Include="System.ValueTuple" Version="$(TuplesVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CustomErrorTests
public void Can_Return_Custom_Error_Types()
{
// arrange
var error = new CustomError("507", "title", "detail", "custom");
var error = new CustomError(507, "title", "detail", "custom");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

var errorCollection = new ErrorCollection();
errorCollection.Add(error);

Expand All @@ -36,7 +36,7 @@ public void Can_Return_Custom_Error_Types()
}

class CustomError : Error {
public CustomError(string status, string title, string detail, string myProp)
public CustomError(int status, string title, string detail, string myProp)
: base(status, title, detail)
{
MyCustomProperty = myProp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task Can_Filter_On_Not_Equal_Values()

// assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.False(deserializedTodoItems.Any(i => i.Ordinal == todoItem.Ordinal));
Assert.DoesNotContain(deserializedTodoItems, x => x.Ordinal == todoItem.Ordinal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

}

[Fact]
Expand Down Expand Up @@ -170,8 +170,8 @@ public async Task Can_Filter_On_In_Array_Values()
Assert.Equal(guids.Count(), deserializedTodoItems.Count());
foreach (var item in deserializedTodoItems)
{
Assert.True(guids.Contains(item.GuidProperty));
Assert.False(notInGuids.Contains(item.GuidProperty));
Assert.Contains(item.GuidProperty, guids);
Assert.DoesNotContain(item.GuidProperty, notInGuids);
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ public async Task Can_Filter_On_Related_In_Array_Values()
Assert.NotNull(included);
Assert.NotEmpty(included);
foreach (var item in included)
Assert.True(ownerFirstNames.Contains(item.Attributes["first-name"]));
Assert.Contains(item.Attributes["first-name"], ownerFirstNames);

}
}
Expand Down
Loading