Skip to content

.NET Core 2.0 -> 2.1 #593

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 1 commit into from
Oct 23, 2019
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
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _
dotnet_naming_style.prefix_underscore.required_prefix = _
[*.cs]

# CS0659: Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
dotnet_diagnostic.CS0659.severity = silent
Copy link
Member

Choose a reason for hiding this comment

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

This is to suppress the error in RelationshipAttribute.cs, right? Are we sure it's fine to just ignore it rather than solving the issue? I don't know: I always ignored it until now, never looked into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take it out, so it stays as a warning next release

2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<NetCoreAppVersion>netcoreapp2.0</NetCoreAppVersion>
<NetCoreAppVersion>netcoreapp2.1</NetCoreAppVersion>
<NetStandardVersion>netstandard2.0</NetStandardVersion>

<AspNetCoreVersion>2.*</AspNetCoreVersion>
Expand Down
361 changes: 180 additions & 181 deletions JsonApiDotnetCore.sln

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/Examples/GettingStarted/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -10,17 +10,17 @@

namespace GettingStarted
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://localhost:5001")
.Build();


public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://localhost:5001");
}
}
11 changes: 6 additions & 5 deletions src/Examples/JsonApiDotNetCoreExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ namespace JsonApiDotNetCoreExample
{
public class Program
{
public static void Main(string[] args) => BuildWebHost(args).Run();

public static IWebHost BuildWebHost(string[] args) =>
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.UseStartup<Startup>();
}
}
27 changes: 14 additions & 13 deletions src/Examples/JsonApiDotNetCoreExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,23 @@ public Startup(IHostingEnvironment env)
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Warning);
services
.AddSingleton<ILoggerFactory>(loggerFactory)
.AddLogging(builder =>
{
builder.AddConsole();
builder.AddConfiguration(Config.GetSection("Logging"));
})
.AddDbContext<AppDbContext>(options => options.UseNpgsql(GetDbConnectionString()), ServiceLifetime.Transient)
.AddJsonApi(
options =>
{
options.Namespace = "api/v1";
options.DefaultPageSize = 5;
options.IncludeTotalRecordCount = true;
options.EnableResourceHooks = true;
options.LoaDatabaseValues = true;
},
discovery => discovery.AddCurrentAssembly());

.AddJsonApi(options =>
{
options.Namespace = "api/v1";
options.DefaultPageSize = 5;
options.IncludeTotalRecordCount = true;
options.EnableResourceHooks = true;
options.LoaDatabaseValues = true;
},
discovery => discovery.AddCurrentAssembly());
return services.BuildServiceProvider();
}

Expand All @@ -53,7 +55,6 @@ public virtual void Configure(
AppDbContext context)
{
context.Database.EnsureCreated();
loggerFactory.AddConsole(Config.GetSection("Logging"));
app.UseJsonApi();
}

Expand Down
10 changes: 4 additions & 6 deletions src/Examples/NoEntityFrameworkExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace NoEntityFrameworkExample
Expand All @@ -7,12 +7,10 @@ public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHost BuildWebHost(string[] args) =>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.UseStartup<Startup>();
}
}
25 changes: 11 additions & 14 deletions src/Examples/NoEntityFrameworkExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,28 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add framework services.
var mvcBuilder = services.AddMvcCore();

services.AddJsonApi(
options => options.Namespace = "api/v1",
resources: resources => resources.AddResource<TodoItem>("custom-todo-items"),
mvcBuilder: mvcBuilder
);

services.AddLogging(builder =>
{
builder.AddConfiguration(Configuration.GetSection("Logging"));
builder.AddConsole();
}).AddJsonApi(
options => options.Namespace = "api/v1",
resources: resources => resources.AddResource<TodoItem>("custom-todo-items"),
mvcBuilder: mvcBuilder
);
services.AddScoped<IResourceService<TodoItem>, TodoItemService>();

var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseNpgsql(Configuration.GetValue<string>("Data:DefaultConnection"));
services.AddSingleton<IConfiguration>(Configuration);
services.AddSingleton<DbContextOptions<AppDbContext>>(optionsBuilder.Options);
services.AddSingleton(optionsBuilder.Options);
services.AddScoped<AppDbContext>();

return services.BuildServiceProvider();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AppDbContext context)
public void Configure(IApplicationBuilder app, AppDbContext context)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));

context.Database.EnsureCreated();

app.UseJsonApi();
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/Examples/ReportsExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace ReportsExample
Expand All @@ -7,12 +7,10 @@ public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHost BuildWebHost(string[] args) =>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.UseStartup<Startup>();
}
}
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Internal/ResourceGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private IEnumerable<IResourceField> Getter<T>(Expression<Func<T, dynamic>> selec
targeted.Add(available.Single(f => f.ExposedInternalMemberName == memberExpression.Member.Name));
return targeted;
}
catch (Exception ex)
catch (InvalidOperationException)
{
ThrowNotExposedError(memberExpression.Member.Name, type);
}
Expand All @@ -115,7 +115,7 @@ private IEnumerable<IResourceField> Getter<T>(Expression<Func<T, dynamic>> selec
}
return targeted;
}
catch (Exception ex)
catch (InvalidOperationException)
{
ThrowNotExposedError(memberName, type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using JsonApiDotNetCore.Internal.Contracts;
Expand Down
2 changes: 1 addition & 1 deletion test/DiscoveryTests/DiscoveryTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
<PackageReference Include="Moq" Version="$(MoqVersion)" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec
[Collection("WebHostCollection")]
public class CreatingDataTests : EndToEndTest
{
private Faker<TodoItem> _todoItemFaker;
private Faker<Person> _personFaker;
private readonly Faker<TodoItem> _todoItemFaker;
private readonly Faker<Person> _personFaker;

public CreatingDataTests(TestFixture<TestStartup> fixture) : base(fixture)
{
Expand Down Expand Up @@ -155,9 +155,11 @@ public async Task CreateWithRelationship_HasManyAndInclude_IsCreatedAndIncludes(
var serializer = GetSerializer<TodoItemCollection>(e => new { }, e => new { e.TodoItems, e.Owner });

var owner = new Person();
var todoItem = new TodoItem();
todoItem.Owner = owner;
todoItem.Description = "Description";
var todoItem = new TodoItem
{
Owner = owner,
Description = "Description"
};
dbContext.People.Add(owner);
dbContext.TodoItems.Add(todoItem);
dbContext.SaveChanges();
Expand Down Expand Up @@ -340,7 +342,7 @@ public async Task CreateRelationship_ToManyWithImplicitRemove_IsCreated()
var oldPersonDb = dbContext.People.AsNoTracking().Where(p => p.Id == currentPerson.Id).Include(e => e.TodoItems).Single();
AssertEqualStatusCode(HttpStatusCode.Created, response);
Assert.Equal(2, newPersonDb.TodoItems.Count);
Assert.Equal(1, oldPersonDb.TodoItems.Count);
Assert.Single(oldPersonDb.TodoItems);
Assert.NotNull(newPersonDb.TodoItems.SingleOrDefault(ti => ti.Id == firstTd.Id));
Assert.NotNull(newPersonDb.TodoItems.SingleOrDefault(ti => ti.Id == secondTd.Id));
Assert.NotNull(oldPersonDb.TodoItems.SingleOrDefault(ti => ti.Id == thirdTd.Id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public ClientGeneratedIdsStartup(IHostingEnvironment env)
public override IServiceProvider ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Warning);
var mvcBuilder = services.AddMvcCore();
services
.AddSingleton<ILoggerFactory>(loggerFactory)
.AddLogging(builder =>
{
builder.AddConsole();
})
.AddDbContext<AppDbContext>(options => options.UseNpgsql(GetDbConnectionString()), ServiceLifetime.Transient)
.AddJsonApi(options => {
options.Namespace = "api/v1";
Expand Down
8 changes: 4 additions & 4 deletions test/UnitTests/Builders/LinkBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ public void BuildRelationshipLinks_GlobalResourceAndAttrConfiguration_ExpectedLi
[InlineData(Link.All, Link.All, _topSelf, true)]
[InlineData(Link.All, Link.Self, _topSelf, false)]
[InlineData(Link.All, Link.Paging, null, true)]
[InlineData(Link.All, Link.None, null, null)]
[InlineData(Link.All, Link.None, null, false)]
[InlineData(Link.Self, Link.NotConfigured, _topSelf, false)]
[InlineData(Link.Self, Link.All, _topSelf, true)]
[InlineData(Link.Self, Link.Self, _topSelf, false)]
[InlineData(Link.Self, Link.Paging, null, true)]
[InlineData(Link.Self, Link.None, null, null)]
[InlineData(Link.Self, Link.None, null, false)]
[InlineData(Link.Paging, Link.NotConfigured, null, true)]
[InlineData(Link.Paging, Link.All, _topSelf, true)]
[InlineData(Link.Paging, Link.Self, _topSelf, false)]
[InlineData(Link.Paging, Link.Paging, null, true)]
[InlineData(Link.Paging, Link.None, null, null)]
[InlineData(Link.Paging, Link.None, null, false)]
[InlineData(Link.None, Link.NotConfigured, null, false)]
[InlineData(Link.None, Link.All, _topSelf, true)]
[InlineData(Link.None, Link.Self, _topSelf, false)]
[InlineData(Link.None, Link.Paging, null, true)]
[InlineData(Link.None, Link.None, null, null)]
[InlineData(Link.None, Link.None, null, false)]
public void BuildTopLevelLinks_GlobalAndResourceConfiguration_ExpectedLinks(Link global,
Link resource,
object expectedSelfLink,
Expand Down
Loading