Skip to content

Projects cleanup #744

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 10 commits into from
May 15, 2020
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
18 changes: 2 additions & 16 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,7 @@ CheckLastExitCode
dotnet build -c Release
CheckLastExitCode

# Workaround: running 'dotnet test -c Release' fails for yet unknown reasons on AppVeyor, so we run tests one by one.

dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj -c Release --no-build
CheckLastExitCode

dotnet test ./test/DiscoveryTests/DiscoveryTests.csproj -c Release --no-build
CheckLastExitCode

dotnet test ./test/IntegrationTests/IntegrationTests.csproj -c Release --no-build
CheckLastExitCode

dotnet test ./test/UnitTests/UnitTests.csproj -c Release --no-build
CheckLastExitCode

dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj -c Release --no-build
dotnet test -c Release --no-build
CheckLastExitCode

Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
Expand All @@ -62,7 +48,7 @@ If($env:APPVEYOR_REPO_TAG -eq $true) {
}
}
Else {
Write-Output "VERSION-SUFFIX: alpha1-$revision"
Write-Output "VERSION-SUFFIX: alpha5-$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 --include-symbols
CheckLastExitCode
Expand Down
8 changes: 1 addition & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ version: '{build}'
os: Visual Studio 2019

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!"
ACCESS_TOKEN:
secure: g1T332Uarmdgtkftchpafa8tDP/7eM4O0BD6iu1wu+zR224IyH5R8pb4sTChr4Ia

Expand Down Expand Up @@ -63,10 +58,9 @@ init:
- SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%

services:
- postgresql
- postgresql96

build_script:
- ps: createdb JsonApiDotNetCoreExample
- ps: dotnet --version
- ps: .\Build.ps1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace GettingStarted
namespace GettingStarted.Controllers
{
public sealed class ArticlesController : JsonApiController<Article>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace GettingStarted
namespace GettingStarted.Controllers
{
public sealed class PeopleController : JsonApiController<Person>
{
Expand Down
18 changes: 12 additions & 6 deletions src/Examples/GettingStarted/Data/SampleDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
using GettingStarted.Models;
using GettingStarted.ResourceDefinitionExample;
using Microsoft.EntityFrameworkCore;

namespace GettingStarted
namespace GettingStarted.Data
{
public class SampleDbContext : DbContext
{
public SampleDbContext(DbContextOptions<SampleDbContext> options) : base(options) { }
public DbSet<Article> Articles { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Model> Models { get; set; }

public SampleDbContext(DbContextOptions<SampleDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Examples/GettingStarted/Models/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public sealed class Article : Identifiable
{
[Attr]
public string Title { get; set; }

[HasOne]
public Person Author { get; set; }
public int AuthorId { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Examples/GettingStarted/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace GettingStarted.Models
{
public sealed class Person : Identifiable
{
[Attr]
[Attr]
public string Name { get; set; }

[HasMany]
[HasMany]
public ICollection<Article> Articles { get; set; }
}
}
14 changes: 8 additions & 6 deletions src/Examples/GettingStarted/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace GettingStarted
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
CreateHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://localhost:5001");
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
38 changes: 28 additions & 10 deletions src/Examples/GettingStarted/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
{
"profiles": {
"GettingStarted": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14141",
"sslPort": 44344
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchUrl": "api/people",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Kestrel": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "api/people",
"applicationUrl": "https://localhost:44344;http://localhost:14141",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Examples/GettingStarted/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
`dotnet run` to run the project

You can verify the project is running by checking this endpoint:
`localhost:5001/api/sample-model`
`localhost:14141/api/people`

For further documentation and implementation of a JsonApiDotnetCore Application see the documentation or GitHub page:

Repository: https://github.com/json-api-dotnet/JsonApiDotNetCore

Documentation: https://json-api-dotnet.github.io/
Documentation: https://json-api-dotnet.github.io/
44 changes: 33 additions & 11 deletions src/Examples/GettingStarted/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
using GettingStarted.Data;
using GettingStarted.Models;
using JsonApiDotNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using JsonApiDotNetCore;
using Microsoft.Extensions.DependencyInjection;

namespace GettingStarted
{
public sealed class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<SampleDbContext>(options =>
{
options.UseSqlite("Data Source=sample.db");
});
services.AddDbContext<SampleDbContext>(
options => options.UseSqlite("Data Source=sample.db"));

var mvcBuilder = services.AddMvcCore();
services.AddJsonApi(
options => options.Namespace = "api",
discover => discover.AddCurrentAssembly(), mvcBuilder: mvcBuilder);
services.AddJsonApi<SampleDbContext>(
options => options.Namespace = "api");
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, SampleDbContext context)
{
// indices need to be reset
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
CreateSampleData(context);

app.UseJsonApi();
}

private static void CreateSampleData(SampleDbContext context)
{
context.Articles.AddRange(new Article
{
Title = "What's new in JsonApiDotNetCore",
Author = new Person
{
Name = "John Doe"
}
}, new Article
{
Title = ".NET Core Best Practices",
Author = new Person
{
Name = "Microsoft"
}
});

context.SaveChanges();
}
}
}
10 changes: 10 additions & 0 deletions src/Examples/GettingStarted/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Models;
using Microsoft.Extensions.Logging;

namespace GettingStarted.ResourceDefinitionExample
namespace JsonApiDotNetCoreExample.Controllers
{
public sealed class ModelsController : JsonApiController<Model>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
using System.Linq;
using System.Net;
using JsonApiDotNetCore.Exceptions;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Hooks;
using JsonApiDotNetCoreExample.Models;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Models.JsonApiDocuments;
using JsonApiDotNetCoreExample.Models;

namespace JsonApiDotNetCoreExample.Resources
namespace JsonApiDotNetCoreExample.Definitions
{
public class ArticleResource : ResourceDefinition<Article>
public class ArticleDefinition : ResourceDefinition<Article>
{
public ArticleResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
public ArticleDefinition(IResourceGraph resourceGraph) : base(resourceGraph) { }

public override IEnumerable<Article> OnReturn(HashSet<Article> entities, ResourcePipeline pipeline)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using JsonApiDotNetCore.Models.JsonApiDocuments;
using JsonApiDotNetCoreExample.Models;

namespace JsonApiDotNetCoreExample.Resources
namespace JsonApiDotNetCoreExample.Definitions
{
public abstract class LockableResource<T> : ResourceDefinition<T> where T : class, IIsLockable, IIdentifiable
public abstract class LockableDefinition<T> : ResourceDefinition<T> where T : class, IIsLockable, IIdentifiable
{
protected LockableResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
protected LockableDefinition(IResourceGraph resourceGraph) : base(resourceGraph) { }

protected void DisallowLocked(IEnumerable<T> entities)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCoreExample.Models;

namespace GettingStarted.ResourceDefinitionExample
namespace JsonApiDotNetCoreExample.Definitions
{
public class ModelDefinition : ResourceDefinition<Model>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
using System.Linq;
using System.Net;
using JsonApiDotNetCore.Exceptions;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Hooks;
using JsonApiDotNetCoreExample.Models;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Models.JsonApiDocuments;
using JsonApiDotNetCoreExample.Models;

namespace JsonApiDotNetCoreExample.Resources
namespace JsonApiDotNetCoreExample.Definitions
{
public class PassportResource : ResourceDefinition<Passport>
public class PassportDefinition : ResourceDefinition<Passport>
{
public PassportResource(IResourceGraph resourceGraph) : base(resourceGraph)
public PassportDefinition(IResourceGraph resourceGraph) : base(resourceGraph)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Collections.Generic;
using System.Linq;
using JsonApiDotNetCore.Hooks;
using JsonApiDotNetCoreExample.Models;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCoreExample.Models;

namespace JsonApiDotNetCoreExample.Resources
namespace JsonApiDotNetCoreExample.Definitions
{
public class PersonResource : LockableResource<Person>, IHasMeta
public class PersonDefinition : LockableDefinition<Person>, IHasMeta
{
public PersonResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
public PersonDefinition(IResourceGraph resourceGraph) : base(resourceGraph) { }

public override IEnumerable<string> BeforeUpdateRelationship(HashSet<string> ids, IRelationshipsDictionary<Person> entitiesByRelationship, ResourcePipeline pipeline)
{
Expand Down
Loading