diff --git a/2.0.1.props b/2.0.1.props new file mode 100644 index 0000000000..1cf508ad78 --- /dev/null +++ b/2.0.1.props @@ -0,0 +1,30 @@ + + + netcoreapp2.0 + netstandard2.0 + + 2.0.1 + + 2.0.0 + 2.0.0 + 2.0.0 + + 2.0.1 + 2.0.1 + + 3.2.6 + 2.0.0 + + 4.4.0 + + + + + 15.3.0-preview-20170427-09 + 1.1.2 + 2.3.0-beta3-build3705 + 15.0.3 + 4.7.99 + + + diff --git a/2.1.0.props b/2.1.0.props new file mode 100644 index 0000000000..88973044e5 --- /dev/null +++ b/2.1.0.props @@ -0,0 +1,33 @@ + + + DEPS_2_1_0 + + + + netcoreapp2.0 + netstandard2.0 + + 2.1.0 + + 2.1.0 + 2.1.0 + 2.1.0 + + 2.1.0 + 2.1.0 + + 4.0.0 + 2.1.0 + + 4.5.0 + + + + + 15.7.2 + 2.3.1 + 22.1.2 + 4.8.3 + + + diff --git a/Build.ps1 b/Build.ps1 index bfbd989415..cf7a3960b8 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,63 +1,75 @@ # Gets the version suffix from the repo tag # example: v1.0.0-preview1-final => preview1-final -function Get-Version-Suffix-From-Tag -{ - $tag=$env:APPVEYOR_REPO_TAG_NAME - $split=$tag -split "-" - $suffix=$split[1..2] - $final=$suffix -join "-" - return $final +function Get-Version-Suffix-From-Tag { + $tag = $env:APPVEYOR_REPO_TAG_NAME + $split = $tag -split "-" + $suffix = $split[1..2] + $final = $suffix -join "-" + return $final } function CheckLastExitCode { - param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null) + param ([string]$Command, [int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript = $null) if ($SuccessCodes -notcontains $LastExitCode) { - $msg = "EXE RETURNED EXIT CODE $LastExitCode" - throw $msg + throw "$Command exited with $LastExitCode" } } -$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) - -dotnet restore - -dotnet test ./test/UnitTests/UnitTests.csproj -CheckLastExitCode +function Run($exp) { + Invoke-Expression $exp + CheckLastExitCode $exp +} -dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj -CheckLastExitCode +function BuildVersion($version) { + Write-Output "Testing project against ASP.Net Core $version" + $msBuildParams = "/p:TestProjectDependencyVersions=$version /p:NoWarn=NU1605 /v:minimal" -dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj -CheckLastExitCode + Run "dotnet restore $msBuildParams" + Run "dotnet msbuild $msBuildParams" + Run "dotnet test ./test/UnitTests/UnitTests.csproj --no-build $msBuildParams" + Run "dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj --no-build $msBuildParams" + Run "dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj --no-build $msBuildParams" + Run "dotnet test ./test/OperationsExampleTests/OperationsExampleTests.csproj --no-build $msBuildParams" +} -dotnet test ./test/OperationsExampleTests/OperationsExampleTests.csproj -CheckLastExitCode +function Test() { + $supportedVersions = @("2.0.1", "2.1.0") + foreach ($version in $supportedVersions) { + BuildVersion $version + } +} -dotnet build .\src\JsonApiDotNetCore -c Release -CheckLastExitCode +function Build() { + Run "dotnet restore .\src\JsonApiDotNetCore" + Run "dotnet build .\src\JsonApiDotNetCore -c Release" +} -Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG" +function Pack() { + Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG" -If($env:APPVEYOR_REPO_TAG -eq $true) { - $revision = Get-Version-Suffix-From-Tag - Write-Output "VERSION-SUFFIX: $revision" + $revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; + $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) + If ($env:APPVEYOR_REPO_TAG -eq $true) { + $revision = Get-Version-Suffix-From-Tag + Write-Output "VERSION-SUFFIX: $revision" - IF ([string]::IsNullOrWhitespace($revision)){ - Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts" - dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts - CheckLastExitCode + IF ([string]::IsNullOrWhitespace($revision)) { + Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts" + Run "dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts" + } + Else { + Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision" + Run "dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision" + } } - Else { - Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision" - dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision - CheckLastExitCode + Else { + Write-Output "VERSION-SUFFIX: alpha1-$revision" + Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" + Run "dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" } } -Else { - Write-Output "VERSION-SUFFIX: alpha1-$revision" - Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" - dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision - CheckLastExitCode -} + +Test +Build +Pack diff --git a/Directory.Build.props b/Directory.Build.props index 346835dd6c..af6e0988fc 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,31 +1,4 @@ - - - netcoreapp2.0 - netstandard2.0 - - 2.0.1 - - 2.0.0 - 2.0.0 - 2.0.0 - - 2.0.1 - 2.0.1 - - 3.2.6 - 2.0.0 - - 4.4.0 - - - - - 15.3.0-preview-20170427-09 - 1.1.2 - 2.3.0-beta3-build3705 - 15.0.3 - 4.7.99 - - + + diff --git a/JsonApiDotnetCore.sln b/JsonApiDotnetCore.sln index 4b7cf5ea47..f23f4219a8 100644 --- a/JsonApiDotnetCore.sln +++ b/JsonApiDotnetCore.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .gitignore = .gitignore .travis.yml = .travis.yml + 2.0.1.props = 2.0.1.props + 2.1.0.props = 2.1.0.props appveyor.yml = appveyor.yml Build.ps1 = Build.ps1 build.sh = build.sh diff --git a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj index e588c81b4e..2c35af61e1 100755 --- a/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj +++ b/src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj @@ -1,4 +1,7 @@ + + + $(NetCoreAppVersion) true diff --git a/src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.Designer.cs b/src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.Designer.cs deleted file mode 100644 index c86425b00c..0000000000 --- a/src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.Designer.cs +++ /dev/null @@ -1,161 +0,0 @@ -// -using JsonApiDotNetCoreExample.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Storage.Internal; -using System; - -namespace JsonApiDotNetCoreExample.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20180327120810_initial")] - partial class initial - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) - .HasAnnotation("ProductVersion", "2.0.1-rtm-125"); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Article", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("AuthorId"); - - b.Property("Name"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.ToTable("Articles"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Author", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Name"); - - b.HasKey("Id"); - - b.ToTable("Authors"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.CamelCasedModel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("CompoundAttr"); - - b.HasKey("Id"); - - b.ToTable("CamelCasedModels"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Person", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("FirstName"); - - b.Property("LastName"); - - b.HasKey("Id"); - - b.ToTable("People"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("AchievedDate"); - - b.Property("AssigneeId"); - - b.Property("CollectionId"); - - b.Property("CreatedDate") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("CURRENT_TIMESTAMP"); - - b.Property("Description"); - - b.Property("GuidProperty"); - - b.Property("Ordinal"); - - b.Property("OwnerId"); - - b.HasKey("Id"); - - b.HasIndex("AssigneeId"); - - b.HasIndex("CollectionId"); - - b.HasIndex("OwnerId"); - - b.ToTable("TodoItems"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItemCollection", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Name"); - - b.Property("OwnerId"); - - b.HasKey("Id"); - - b.HasIndex("OwnerId"); - - b.ToTable("TodoItemCollections"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Article", b => - { - b.HasOne("JsonApiDotNetCoreExample.Models.Author", "Author") - .WithMany("Articles") - .HasForeignKey("AuthorId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItem", b => - { - b.HasOne("JsonApiDotNetCoreExample.Models.Person", "Assignee") - .WithMany("AssignedTodoItems") - .HasForeignKey("AssigneeId"); - - b.HasOne("JsonApiDotNetCoreExample.Models.TodoItemCollection", "Collection") - .WithMany("TodoItems") - .HasForeignKey("CollectionId"); - - b.HasOne("JsonApiDotNetCoreExample.Models.Person", "Owner") - .WithMany("TodoItems") - .HasForeignKey("OwnerId"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItemCollection", b => - { - b.HasOne("JsonApiDotNetCoreExample.Models.Person", "Owner") - .WithMany("TodoItemCollections") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.cs b/src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.cs deleted file mode 100644 index ba19b62ef6..0000000000 --- a/src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.cs +++ /dev/null @@ -1,176 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using System; -using System.Collections.Generic; - -namespace JsonApiDotNetCoreExample.Migrations -{ - public partial class initial : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Authors", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), - Name = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Authors", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "CamelCasedModels", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), - CompoundAttr = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_CamelCasedModels", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "People", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), - FirstName = table.Column(nullable: true), - LastName = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_People", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Articles", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), - AuthorId = table.Column(nullable: false), - Name = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Articles", x => x.Id); - table.ForeignKey( - name: "FK_Articles_Authors_AuthorId", - column: x => x.AuthorId, - principalTable: "Authors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "TodoItemCollections", - columns: table => new - { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - OwnerId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_TodoItemCollections", x => x.Id); - table.ForeignKey( - name: "FK_TodoItemCollections_People_OwnerId", - column: x => x.OwnerId, - principalTable: "People", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "TodoItems", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), - AchievedDate = table.Column(nullable: true), - AssigneeId = table.Column(nullable: true), - CollectionId = table.Column(nullable: true), - CreatedDate = table.Column(nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"), - Description = table.Column(nullable: true), - GuidProperty = table.Column(nullable: false), - Ordinal = table.Column(nullable: false), - OwnerId = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_TodoItems", x => x.Id); - table.ForeignKey( - name: "FK_TodoItems_People_AssigneeId", - column: x => x.AssigneeId, - principalTable: "People", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_TodoItems_TodoItemCollections_CollectionId", - column: x => x.CollectionId, - principalTable: "TodoItemCollections", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_TodoItems_People_OwnerId", - column: x => x.OwnerId, - principalTable: "People", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateIndex( - name: "IX_Articles_AuthorId", - table: "Articles", - column: "AuthorId"); - - migrationBuilder.CreateIndex( - name: "IX_TodoItemCollections_OwnerId", - table: "TodoItemCollections", - column: "OwnerId"); - - migrationBuilder.CreateIndex( - name: "IX_TodoItems_AssigneeId", - table: "TodoItems", - column: "AssigneeId"); - - migrationBuilder.CreateIndex( - name: "IX_TodoItems_CollectionId", - table: "TodoItems", - column: "CollectionId"); - - migrationBuilder.CreateIndex( - name: "IX_TodoItems_OwnerId", - table: "TodoItems", - column: "OwnerId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Articles"); - - migrationBuilder.DropTable( - name: "CamelCasedModels"); - - migrationBuilder.DropTable( - name: "TodoItems"); - - migrationBuilder.DropTable( - name: "Authors"); - - migrationBuilder.DropTable( - name: "TodoItemCollections"); - - migrationBuilder.DropTable( - name: "People"); - } - } -} diff --git a/src/Examples/JsonApiDotNetCoreExample/Migrations/AppDbContextModelSnapshot.cs b/src/Examples/JsonApiDotNetCoreExample/Migrations/AppDbContextModelSnapshot.cs deleted file mode 100755 index c0794103fe..0000000000 --- a/src/Examples/JsonApiDotNetCoreExample/Migrations/AppDbContextModelSnapshot.cs +++ /dev/null @@ -1,160 +0,0 @@ -// -using JsonApiDotNetCoreExample.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Storage.Internal; -using System; - -namespace JsonApiDotNetCoreExample.Migrations -{ - [DbContext(typeof(AppDbContext))] - partial class AppDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) - .HasAnnotation("ProductVersion", "2.0.1-rtm-125"); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Article", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("AuthorId"); - - b.Property("Name"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.ToTable("Articles"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Author", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Name"); - - b.HasKey("Id"); - - b.ToTable("Authors"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.CamelCasedModel", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("CompoundAttr"); - - b.HasKey("Id"); - - b.ToTable("CamelCasedModels"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Person", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("FirstName"); - - b.Property("LastName"); - - b.HasKey("Id"); - - b.ToTable("People"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("AchievedDate"); - - b.Property("AssigneeId"); - - b.Property("CollectionId"); - - b.Property("CreatedDate") - .ValueGeneratedOnAdd() - .HasDefaultValueSql("CURRENT_TIMESTAMP"); - - b.Property("Description"); - - b.Property("GuidProperty"); - - b.Property("Ordinal"); - - b.Property("OwnerId"); - - b.HasKey("Id"); - - b.HasIndex("AssigneeId"); - - b.HasIndex("CollectionId"); - - b.HasIndex("OwnerId"); - - b.ToTable("TodoItems"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItemCollection", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Name"); - - b.Property("OwnerId"); - - b.HasKey("Id"); - - b.HasIndex("OwnerId"); - - b.ToTable("TodoItemCollections"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.Article", b => - { - b.HasOne("JsonApiDotNetCoreExample.Models.Author", "Author") - .WithMany("Articles") - .HasForeignKey("AuthorId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItem", b => - { - b.HasOne("JsonApiDotNetCoreExample.Models.Person", "Assignee") - .WithMany("AssignedTodoItems") - .HasForeignKey("AssigneeId"); - - b.HasOne("JsonApiDotNetCoreExample.Models.TodoItemCollection", "Collection") - .WithMany("TodoItems") - .HasForeignKey("CollectionId"); - - b.HasOne("JsonApiDotNetCoreExample.Models.Person", "Owner") - .WithMany("TodoItems") - .HasForeignKey("OwnerId"); - }); - - modelBuilder.Entity("JsonApiDotNetCoreExample.Models.TodoItemCollection", b => - { - b.HasOne("JsonApiDotNetCoreExample.Models.Person", "Owner") - .WithMany("TodoItemCollections") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj b/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj index eed5f1b09e..e6f615346f 100755 --- a/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj +++ b/src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj @@ -1,4 +1,7 @@  + + + $(NetCoreAppVersion) diff --git a/src/Examples/OperationsExample/OperationsExample.csproj b/src/Examples/OperationsExample/OperationsExample.csproj index 02eeabe976..15c0a0a0f9 100644 --- a/src/Examples/OperationsExample/OperationsExample.csproj +++ b/src/Examples/OperationsExample/OperationsExample.csproj @@ -1,4 +1,7 @@ + + + $(NetCoreAppVersion) true diff --git a/src/Examples/ReportsExample/ReportsExample.csproj b/src/Examples/ReportsExample/ReportsExample.csproj index bd4b402071..7fac808950 100644 --- a/src/Examples/ReportsExample/ReportsExample.csproj +++ b/src/Examples/ReportsExample/ReportsExample.csproj @@ -1,4 +1,7 @@ + + + $(NetCoreAppVersion) diff --git a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/IQueryableExtensions.cs b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/IQueryableExtensions.cs index c774478227..e1a3f4a57c 100644 --- a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/IQueryableExtensions.cs +++ b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/IQueryableExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Reflection; using Microsoft.EntityFrameworkCore.Internal; @@ -11,6 +12,22 @@ namespace JsonApiDotNetCoreExampleTests.Helpers.Extensions { public static class IQueryableExtensions + { + public static string ToSql(this IQueryable query) where TEntity : class + { +#if DEPS_2_1_0 + return QueryGenerator_2_1_0.ToSql(query); +#else + // this has to be the default value, + // constants will not be defined for the primary package build + // the constants only exist to simulate scenarios where consumers specify + // different version for framework dependencies + return QueryGenerator_2_0_0.ToSql(query); +#endif + } + } + + public static class QueryGenerator_2_0_0 { private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo(); @@ -25,7 +42,7 @@ public static class IQueryableExtensions private static readonly PropertyInfo DatabaseDependenciesField = typeof(Database).GetTypeInfo().DeclaredProperties.Single(x => x.Name == "Dependencies"); - public static string ToSql(this IQueryable query) where TEntity : class + public static string ToSql(IQueryable query) where TEntity : class { if (!(query is EntityQueryable) && !(query is InternalDbSet)) { @@ -46,4 +63,36 @@ public static string ToSql(this IQueryable query) where TEntit return sql; } } -} \ No newline at end of file + +#if DEPS_2_1_0 + public static class QueryGenerator_2_1_0 + { + private static readonly FieldInfo QueryCompilerField = typeof(EntityQueryProvider).GetTypeInfo().DeclaredFields.Single(x => x.Name == "_queryCompiler"); + + private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo(); + + private static readonly FieldInfo QueryModelGeneratorField = QueryCompilerTypeInfo.DeclaredFields.Single(x => x.Name == "_queryModelGenerator"); + + private static readonly FieldInfo DatabaseField = QueryCompilerTypeInfo.DeclaredFields.Single(x => x.Name == "_database"); + + private static readonly PropertyInfo DependenciesProperty = typeof(Database).GetTypeInfo().DeclaredProperties.Single(x => x.Name == "Dependencies"); + + public static string ToSql(IQueryable queryable) + where TEntity : class + { + if (!(queryable is EntityQueryable) && !(queryable is InternalDbSet)) + throw new ArgumentException(); + + var queryCompiler = (IQueryCompiler)QueryCompilerField.GetValue(queryable.Provider); + var queryModelGenerator = (IQueryModelGenerator)QueryModelGeneratorField.GetValue(queryCompiler); + var queryModel = queryModelGenerator.ParseQuery(queryable.Expression); + var database = DatabaseField.GetValue(queryCompiler); + var queryCompilationContextFactory = ((DatabaseDependencies)DependenciesProperty.GetValue(database)).QueryCompilationContextFactory; + var queryCompilationContext = queryCompilationContextFactory.Create(false); + var modelVisitor = (RelationalQueryModelVisitor)queryCompilationContext.CreateQueryModelVisitor(); + modelVisitor.CreateQueryExecutor(queryModel); + return modelVisitor.Queries.Join(Environment.NewLine + Environment.NewLine); + } + } +#endif +} diff --git a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs index 19c7491d2a..75cafef941 100644 --- a/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs +++ b/test/JsonApiDotNetCoreExampleTests/Helpers/Extensions/StringExtensions.cs @@ -9,7 +9,8 @@ public static string Normalize(this string input) { return Regex.Replace(input, @"\s+", string.Empty) .ToUpper() - .Replace('"', '\''); + .Replace("\"", string.Empty) + .Replace("'", string.Empty); } } -} \ No newline at end of file +} diff --git a/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj b/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj index 53f1d4bf77..7cc366bd0c 100755 --- a/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj +++ b/test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj @@ -1,4 +1,7 @@  + + + $(NetCoreAppVersion) false diff --git a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj index 19b8cc61d2..017eaf68f9 100644 --- a/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj +++ b/test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj @@ -1,4 +1,7 @@  + + + $(NetCoreAppVersion) true diff --git a/test/OperationsExampleTests/OperationsExampleTests.csproj b/test/OperationsExampleTests/OperationsExampleTests.csproj index 3b866d4207..d48ff8e639 100644 --- a/test/OperationsExampleTests/OperationsExampleTests.csproj +++ b/test/OperationsExampleTests/OperationsExampleTests.csproj @@ -1,4 +1,7 @@ + + + $(NetCoreAppVersion) false diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj index 39132d0b0a..be9edd30a3 100644 --- a/test/UnitTests/UnitTests.csproj +++ b/test/UnitTests/UnitTests.csproj @@ -1,4 +1,7 @@ + + + $(NetCoreAppVersion) false @@ -8,7 +11,7 @@ - +