From f8a1e56275fcc70cd51fe272f5ebac0774753709 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 16:18:48 -0500 Subject: [PATCH 01/18] feat(ci): add unstable build --- appveyor.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 5c73d4e86c..a9f03c1a5a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,6 +6,7 @@ branches: only: - master - develop + - unstable nuget: disable_publish_on_pr: true build_script: @@ -23,6 +24,13 @@ deploy: skip_symbols: true on: branch: develop +- provider: NuGet + server: https://www.myget.org/F/jadnc/api/v2/package + api_key: + secure: 6CeYcZ4Ze+57gxfeuHzqP6ldbUkPtF6pfpVM1Gw/K2jExFrAz763gNAQ++tiacq3 + skip_symbols: true + on: + branch: unstable - provider: NuGet name: production api_key: From 82c8ad5d58234cde350074d1c29ce8c510a8f23d Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 16:19:58 -0500 Subject: [PATCH 02/18] fix(#107): EF bug tracking: https://github.com/aspnet/EntityFramework/issues/8462 --- src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs b/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs index a9ccac907b..14e2abc797 100644 --- a/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs +++ b/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs @@ -85,9 +85,12 @@ public virtual async Task GetAsync(TId id) public virtual async Task GetAndIncludeAsync(TId id, string relationshipName) { - return await Get() + var result = await Get() .Include(relationshipName) - .SingleOrDefaultAsync(e => e.Id.Equals(id)); + .Where(e => e.Id.Equals(id)) + .ToListAsync(); + + return result.SingleOrDefault(); } public virtual async Task CreateAsync(TEntity entity) From 6c8e9e2be03303dac3b595eeda192040e5ee88d0 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 16:28:30 -0500 Subject: [PATCH 03/18] chore(csproj): bump package version --- src/JsonApiDotNetCore/JsonApiDotNetCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index afbbd138a4..70f6e2683b 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -1,6 +1,6 @@  - 2.0.4 + 2.0.5 netstandard1.6 JsonApiDotNetCore JsonApiDotNetCore From c91b80b47dfe0bf0189f76a2784c500708130ce2 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 16:40:29 -0500 Subject: [PATCH 04/18] fix(repository): only apply select if there are fields in query also add logging --- src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs b/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs index 14e2abc797..2005478bbf 100644 --- a/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs +++ b/src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs @@ -49,7 +49,10 @@ public DefaultEntityRepository( public virtual IQueryable Get() { - return _dbSet.Select(_jsonApiContext.QuerySet?.Fields); + if(_jsonApiContext.QuerySet?.Fields != null && _jsonApiContext.QuerySet.Fields.Any()) + return _dbSet.Select(_jsonApiContext.QuerySet?.Fields); + + return _dbSet; } public virtual IQueryable Filter(IQueryable entities, FilterQuery filterQuery) @@ -85,11 +88,15 @@ public virtual async Task GetAsync(TId id) public virtual async Task GetAndIncludeAsync(TId id, string relationshipName) { + _logger.LogDebug($"[JADN] GetAndIncludeAsync({id}, {relationshipName})"); + var result = await Get() .Include(relationshipName) .Where(e => e.Id.Equals(id)) .ToListAsync(); - + + _logger.LogDebug($"[JADN] Found {result.Count} entity"); + return result.SingleOrDefault(); } From 6759b7022574b9b47115f9e1e45c908fb0893116 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 16:54:39 -0500 Subject: [PATCH 05/18] chore(csproj): remove runtime specificity --- src/JsonApiDotNetCore/JsonApiDotNetCore.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index 70f6e2683b..6ae3272ca4 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -4,7 +4,6 @@ netstandard1.6 JsonApiDotNetCore JsonApiDotNetCore - 1.1.1 $(PackageTargetFallback);dnxcore50;portable-net45+win8 From e549df1ae54ea8dfbbd4ab17d1a1a991507a5998 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 17:05:42 -0500 Subject: [PATCH 06/18] fix(controller): call correct service method --- src/JsonApiDotNetCore/Controllers/JsonApiController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Controllers/JsonApiController.cs b/src/JsonApiDotNetCore/Controllers/JsonApiController.cs index d6ab13ae3e..2ff94b3ef3 100644 --- a/src/JsonApiDotNetCore/Controllers/JsonApiController.cs +++ b/src/JsonApiDotNetCore/Controllers/JsonApiController.cs @@ -64,7 +64,7 @@ public virtual async Task GetAsync(TId id) [HttpGet("{id}/relationships/{relationshipName}")] public virtual async Task GetRelationshipsAsync(TId id, string relationshipName) { - var relationship = _resourceService.GetRelationshipAsync(id, relationshipName); + var relationship = _resourceService.GetRelationshipsAsync(id, relationshipName); if(relationship == null) return NotFound(); From e6cdcb07ea46c2b549f4f35922c3ce3e9e9e51fe Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 17:05:54 -0500 Subject: [PATCH 07/18] fix(appveyor): try to include psql fix(ci): psql not reconginized fix(ci): Cannot find any service with service name 'postgresql-x64-9.3 Fix(ci): typo fix(ci): appveyor hanging fix(ci): createdb: could not connect to database template1... fix(ci): fix createdb syntax fix(ci): continue trying to fix appveyor fix(ci): fix createdb syntax fix(ci): createdb with no pwd fix(ci) fix(ci) feat(ci): run tests on appveyor fix(ci): restore all projects --- Build.ps1 | 6 ++++- appveyor.yml | 24 +++++++++++++++++++- test/NoEntityFrameworkTests/appsettings.json | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index 4934457d3d..345493543e 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,7 +1,11 @@ $revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) -dotnet restore .\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj +dotnet restore + +dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj +dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj + dotnet build .\src\JsonApiDotNetCore -c Release echo "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG" diff --git a/appveyor.yml b/appveyor.yml index a9f03c1a5a..55c43a7f82 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,18 +1,40 @@ version: '{build}' os: Visual Studio 2017 + +environment: + POSTGRES_PORT: tcp://localhost:5432 + POSTGRES_ENV_POSTGRES_USER: postgres + POSTGRES_ENV_POSTGRES_PASSWORD: Password12! + POSTGRES_ENV_POSTGRES_DB: JsonApiDotNetCoreExample + PGUSER: postgres + PGPASSWORD: Password12! + Data:DefaultConnection: "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=Password12!" + pull_requests: do_not_increment_build_number: true + branches: only: - master - develop - unstable + nuget: disable_publish_on_pr: true + +init: + - SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH% + +services: + - postgresql + build_script: +- ps: createdb JsonApiDotNetCoreExample - ps: dotnet --version - ps: .\Build.ps1 + test: off + artifacts: - path: .\**\artifacts\**\*.nupkg name: NuGet @@ -37,4 +59,4 @@ deploy: secure: /fsEOgG4EdtNd6DPmko9h3NxQwx1IGDcFreGTKd2KA56U2KEkpX/L/pCGpCIEf2s on: branch: master - appveyor_repo_tag: true \ No newline at end of file + appveyor_repo_tag: true diff --git a/test/NoEntityFrameworkTests/appsettings.json b/test/NoEntityFrameworkTests/appsettings.json index 898a1ad601..40ed14033f 100644 --- a/test/NoEntityFrameworkTests/appsettings.json +++ b/test/NoEntityFrameworkTests/appsettings.json @@ -1,6 +1,6 @@ { "Data": { - "DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres" + "DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=" }, "Logging": { "IncludeScopes": false, From 556a5343b92cc9cf2c274b1f67856712ae93d121 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 18:48:02 -0500 Subject: [PATCH 08/18] docs(readme): add netcoreapp v2 notes --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bdf00dae6..7bfbc6e64e 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,14 @@ A framework for building [json:api](http://jsonapi.org/) compliant web servers. ## Installation And Usage -See the documentation [here](https://research-institute.github.io/json-api-dotnet-core) \ No newline at end of file +See the documentation [here](https://research-institute.github.io/json-api-dotnet-core) + + +## .Net Core v2 Notes + +Branch `feat/core-2` is where I am working on .Net Core 2 compatibility tests and package upgrades. +There are several blockers to be aware of: + +- Microsoft.AspNetCore.* packages target the runtime (netcoreapp) instead of netstandard. +This will be fixed in future versions. +- EF bug against netcoreapp2.0 runtime ([EntityFramework#8021](https://github.com/aspnet/EntityFramework/issues/8021)) From 38f15c3faf5519b00d7fad8fb35cf22f412644ce Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:11:36 -0500 Subject: [PATCH 09/18] feat(controllers): add errors response --- JsonApiDotnetCore.sln | 15 ++ .../Controllers/JsonApiControllerMixin.cs | 23 ++ test/UnitTests/.gitignore | 234 ++++++++++++++++++ .../UnitTests/JsonApiControllerMixin_Tests.cs | 58 +++++ test/UnitTests/UnitTests.csproj | 19 ++ 5 files changed, 349 insertions(+) create mode 100644 test/UnitTests/.gitignore create mode 100644 test/UnitTests/JsonApiControllerMixin_Tests.cs create mode 100644 test/UnitTests/UnitTests.csproj diff --git a/JsonApiDotnetCore.sln b/JsonApiDotnetCore.sln index 71cba7f264..e3c197bbc5 100644 --- a/JsonApiDotnetCore.sln +++ b/JsonApiDotnetCore.sln @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkExample", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkTests", "test\NoEntityFrameworkTests\NoEntityFrameworkTests.csproj", "{73DA578D-A63F-4956-83ED-6D7102E09140}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{6D4BD85A-A262-44C6-8572-FE3A30410BF3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -80,6 +82,18 @@ Global {73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x64.Build.0 = Release|Any CPU {73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x86.ActiveCfg = Release|Any CPU {73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x86.Build.0 = Release|Any CPU + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x64.ActiveCfg = Debug|x64 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x64.Build.0 = Debug|x64 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x86.ActiveCfg = Debug|x86 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x86.Build.0 = Debug|x86 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|Any CPU.Build.0 = Release|Any CPU + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x64.ActiveCfg = Release|x64 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x64.Build.0 = Release|x64 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x86.ActiveCfg = Release|x86 + {6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -90,5 +104,6 @@ Global {0B959765-40D2-43B5-87EE-FE2FEF9DBED5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F} {570165EC-62B5-4684-A139-8D2A30DD4475} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF} {73DA578D-A63F-4956-83ED-6D7102E09140} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F} + {6D4BD85A-A262-44C6-8572-FE3A30410BF3} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F} EndGlobalSection EndGlobal diff --git a/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs b/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs index 85e7425b75..dd9cf2f189 100644 --- a/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs +++ b/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs @@ -1,3 +1,5 @@ +using System.Linq; +using JsonApiDotNetCore.Internal; using Microsoft.AspNetCore.Mvc; namespace JsonApiDotNetCore.Controllers @@ -13,5 +15,26 @@ protected IActionResult Forbidden() { return new StatusCodeResult(403); } + + protected IActionResult Errors(ErrorCollection errors) + { + var result = new ObjectResult(errors); + result.StatusCode = GetErrorStatusCode(errors); + + return result; + } + + private int GetErrorStatusCode(ErrorCollection errors) + { + var statusCodes = errors.Errors + .Select(e => (int)e.StatusCode) + .Distinct() + .ToList(); + + if(statusCodes.Count == 1) + return statusCodes[0]; + + return int.Parse(statusCodes.Max().ToString()[0] + "00"); + } } } diff --git a/test/UnitTests/.gitignore b/test/UnitTests/.gitignore new file mode 100644 index 0000000000..0ca27f04e1 --- /dev/null +++ b/test/UnitTests/.gitignore @@ -0,0 +1,234 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ diff --git a/test/UnitTests/JsonApiControllerMixin_Tests.cs b/test/UnitTests/JsonApiControllerMixin_Tests.cs new file mode 100644 index 0000000000..f201b29fcf --- /dev/null +++ b/test/UnitTests/JsonApiControllerMixin_Tests.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using JsonApiDotNetCore.Controllers; +using JsonApiDotNetCore.Internal; +using Microsoft.AspNetCore.Mvc; +using Xunit; + +namespace UnitTests +{ + public class JsonApiControllerMixin_Tests : JsonApiControllerMixin + { + + [Fact] + public void Errors_Correctly_Infers_Status_Code() + { + // arrange + var errors422 = new ErrorCollection { + Errors = new List { + new Error("422", "bad specific"), + new Error("422", "bad other specific"), + } + }; + + var errors400 = new ErrorCollection { + Errors = new List { + new Error("200", "weird"), + new Error("400", "bad"), + new Error("422", "bad specific"), + } + }; + + var errors500 = new ErrorCollection { + Errors = new List { + new Error("200", "weird"), + new Error("400", "bad"), + new Error("422", "bad specific"), + new Error("500", "really bad"), + new Error("502", "really bad specific"), + } + }; + + + // act + var result422 = this.Errors(errors422); + var result400 = this.Errors(errors400); + var result500 = this.Errors(errors500); + + // assert + var response422 = Assert.IsType(result422); + var response400 = Assert.IsType(result400); + var response500 = Assert.IsType(result500); + + Assert.Equal(422, response422.StatusCode); + Assert.Equal(400, response400.StatusCode); + Assert.Equal(500, response500.StatusCode); + } + } +} diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj new file mode 100644 index 0000000000..ad3d3fcaf3 --- /dev/null +++ b/test/UnitTests/UnitTests.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.0 + + false + + + + + + + + + + + + + From 6dff067a7e1599a3f5f97a3fad3fe40a55b59ade Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:16:08 -0500 Subject: [PATCH 10/18] feat(controllers): add singular Error method --- .../Controllers/JsonApiControllerMixin.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs b/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs index dd9cf2f189..fafc70f161 100644 --- a/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs +++ b/src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using JsonApiDotNetCore.Internal; using Microsoft.AspNetCore.Mvc; @@ -16,6 +17,17 @@ protected IActionResult Forbidden() return new StatusCodeResult(403); } + protected IActionResult Error(Error error) + { + var errorCollection = new ErrorCollection { + Errors = new List { error } + }; + var result = new ObjectResult(errorCollection); + result.StatusCode = error.StatusCode; + + return result; + } + protected IActionResult Errors(ErrorCollection errors) { var result = new ObjectResult(errors); @@ -27,7 +39,7 @@ protected IActionResult Errors(ErrorCollection errors) private int GetErrorStatusCode(ErrorCollection errors) { var statusCodes = errors.Errors - .Select(e => (int)e.StatusCode) + .Select(e => e.StatusCode) .Distinct() .ToList(); From 7813e9945d547aed2d06a0dd9c5654bf4c98a635 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:16:19 -0500 Subject: [PATCH 11/18] docs(errors): document errors --- docs/Errors.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/Errors.md b/docs/Errors.md index 70102d157d..7b7a8928b0 100644 --- a/docs/Errors.md +++ b/docs/Errors.md @@ -28,8 +28,11 @@ public void MyMethod() { public override async Task PostAsync([FromBody] MyEntity entity) { if(_db.IsFull) - return new ObjectResult(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry.")); + return Error(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry.")); + if(model.Validations.IsValid == false) + return Errors(model.Validations.Select(v => v.GetErrors())); + // ... } ``` \ No newline at end of file From 48e40b5dc78f6b0688e38e94e623e2f64d1da35c Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:17:05 -0500 Subject: [PATCH 12/18] feat(ci): run the new unit tests project --- Build.ps1 | 1 + build.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/Build.ps1 b/Build.ps1 index 345493543e..9a5e17d170 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -3,6 +3,7 @@ $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) dotnet restore +dotnet test ./test/UnitTests/UnitTests.csproj dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj diff --git a/build.sh b/build.sh index d4d4fbe65a..44d46fd88a 100755 --- a/build.sh +++ b/build.sh @@ -8,5 +8,6 @@ dotnet restore ./src/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj dotnet restore ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj dotnet restore ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj +dotnet test ./test/UnitTests/UnitTests.csproj dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj \ No newline at end of file From c4b0a236e56bc37c2fdf5d83d48a90e3281c0674 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:21:04 -0500 Subject: [PATCH 13/18] fix(unit-tests): target1.1 --- test/UnitTests/UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj index ad3d3fcaf3..b0626bbb85 100644 --- a/test/UnitTests/UnitTests.csproj +++ b/test/UnitTests/UnitTests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp1.1 false From 851005fbc15f66b3a76b5cdccca2357c2918abde Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:34:23 -0500 Subject: [PATCH 14/18] chore(ci): bump travis dotnet version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dea6a483b7..e072bb9cd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ services: before_script: - psql -c 'create database JsonApiDotNetCoreExample;' -U postgres mono: none -dotnet: 1.0.1 +dotnet: 1.1.0 branches: only: - master From 0d5b5ee723693bfe559bac59f8290bd903b080d4 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:39:09 -0500 Subject: [PATCH 15/18] chore(ci): target correct dotnet core version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e072bb9cd6..234e836e7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ services: before_script: - psql -c 'create database JsonApiDotNetCoreExample;' -U postgres mono: none -dotnet: 1.1.0 +dotnet: 1.0.4 # https://www.microsoft.com/net/download/linux branches: only: - master From 569c302c06a63a5cb97fcb88f2d35b30cd107733 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:44:54 -0500 Subject: [PATCH 16/18] chore(ci): try restoring all at once --- build.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 44d46fd88a..441470e65d 100755 --- a/build.sh +++ b/build.sh @@ -3,10 +3,7 @@ #exit if any command fails set -e -dotnet restore ./src/JsonApiDotNetCore/JsonApiDotNetCore.csproj -dotnet restore ./src/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj -dotnet restore ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj -dotnet restore ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj +dotnet restore dotnet test ./test/UnitTests/UnitTests.csproj dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj From 37a8a2a902202848b5b8557ecf0053b06134ae51 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 21:53:29 -0500 Subject: [PATCH 17/18] feat(deserializer): add generic method --- src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs b/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs index 19ec28ee6a..fbbd4f69e2 100644 --- a/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs +++ b/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs @@ -31,6 +31,11 @@ public object Deserialize(string requestBody) return entity; } + public object Deserialize(string requestBody) + { + return (TEntity)Deserialize(requestBody); + } + public object DeserializeRelationship(string requestBody) { var data = JToken.Parse(requestBody)["data"]; From 69c4302f0c5e15904d18f136529357c4d2927ac8 Mon Sep 17 00:00:00 2001 From: jaredcnance Date: Sat, 13 May 2017 22:08:16 -0500 Subject: [PATCH 18/18] docs(readme): document postgres issue --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7bfbc6e64e..b5f3a9cd55 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,4 @@ There are several blockers to be aware of: - Microsoft.AspNetCore.* packages target the runtime (netcoreapp) instead of netstandard. This will be fixed in future versions. - EF bug against netcoreapp2.0 runtime ([EntityFramework#8021](https://github.com/aspnet/EntityFramework/issues/8021)) +- Can't run acceptance testing against postgres on preview runtime [pgsql.EntityFrameworkCore.PostgreSQL#171](https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/171#issuecomment-301287257)