Skip to content

Various small corrections #1131

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
Dec 21, 2021
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
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ Closes #{ISSUE_NUMBER}
- [ ] Complies with our [contributing guidelines](./.github/CONTRIBUTING.md)
- [ ] Adapted tests
- [ ] Documentation updated
- [ ] Created issue to update [Templates](https://github.com/json-api-dotnet/Templates/issues/new): {ISSUE_NUMBER}
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Configuration/TypeLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal sealed class TypeLocator
private static (Type implementationType, Type serviceInterface)? GetContainerRegistrationFromType(Type nextType, Type unboundInterface,
Type[] interfaceTypeArguments)
{
if (!nextType.IsNested)
if (!nextType.IsNested && !nextType.IsAbstract && !nextType.IsInterface)
{
foreach (Type nextConstructedInterface in nextType.GetInterfaces().Where(type => type.IsGenericType))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using TestBuildingBlocks;

namespace JsonApiDotNetCoreTests.IntegrationTests.HostingInIIS;
Expand All @@ -20,10 +18,10 @@ protected override void SetJsonApiOptions(JsonApiOptions options)
options.IncludeTotalResourceCount = true;
}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment environment, ILoggerFactory loggerFactory)
public override void Configure(IApplicationBuilder app)
{
app.UsePathBase("/iis-application-virtual-directory");

base.Configure(app, environment, loggerFactory);
base.Configure(app);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,4 @@ public void Fails_at_startup_when_multiple_controllers_exist_for_same_resource_t
// Assert
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage("Multiple controllers found for resource type 'knownResources'.");
}

public override void Dispose()
{
// Prevents crash when test cleanup tries to access lazily constructed Factory.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public async Task Get_skips_middleware_and_formatters()
// Arrange
using var request = new HttpRequestMessage(HttpMethod.Get, "/NonJsonApi");

HttpClient client = _testContext.Factory.CreateClient();
using HttpClient client = _testContext.Factory.CreateClient();

// Act
HttpResponseMessage httpResponse = await client.SendAsync(request);
using HttpResponseMessage httpResponse = await client.SendAsync(request);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
Expand All @@ -52,10 +52,10 @@ public async Task Post_skips_middleware_and_formatters()
}
};

HttpClient client = _testContext.Factory.CreateClient();
using HttpClient client = _testContext.Factory.CreateClient();

// Act
HttpResponseMessage httpResponse = await client.SendAsync(request);
using HttpResponseMessage httpResponse = await client.SendAsync(request);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
Expand All @@ -72,10 +72,10 @@ public async Task Post_skips_error_handler()
// Arrange
using var request = new HttpRequestMessage(HttpMethod.Post, "/NonJsonApi");

HttpClient client = _testContext.Factory.CreateClient();
using HttpClient client = _testContext.Factory.CreateClient();

// Act
HttpResponseMessage httpResponse = await client.SendAsync(request);
using HttpResponseMessage httpResponse = await client.SendAsync(request);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.BadRequest);
Expand All @@ -101,10 +101,10 @@ public async Task Put_skips_middleware_and_formatters()
}
};

HttpClient client = _testContext.Factory.CreateClient();
using HttpClient client = _testContext.Factory.CreateClient();

// Act
HttpResponseMessage httpResponse = await client.SendAsync(request);
using HttpResponseMessage httpResponse = await client.SendAsync(request);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
Expand All @@ -121,10 +121,10 @@ public async Task Patch_skips_middleware_and_formatters()
// Arrange
using var request = new HttpRequestMessage(HttpMethod.Patch, "/NonJsonApi?name=Janice");

HttpClient client = _testContext.Factory.CreateClient();
using HttpClient client = _testContext.Factory.CreateClient();

// Act
HttpResponseMessage httpResponse = await client.SendAsync(request);
using HttpResponseMessage httpResponse = await client.SendAsync(request);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
Expand All @@ -141,10 +141,10 @@ public async Task Delete_skips_middleware_and_formatters()
// Arrange
using var request = new HttpRequestMessage(HttpMethod.Delete, "/NonJsonApi");

HttpClient client = _testContext.Factory.CreateClient();
using HttpClient client = _testContext.Factory.CreateClient();

// Act
HttpResponseMessage httpResponse = await client.SendAsync(request);
using HttpResponseMessage httpResponse = await client.SendAsync(request);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,4 @@ public void Fails_at_startup_when_using_controller_for_resource_type_that_is_not
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage($"Controller '{typeof(UnknownResourcesController)}' " +
$"depends on resource type '{typeof(UnknownResource)}', which does not exist in the resource graph.");
}

public override void Dispose()
{
// Prevents crash when test cleanup tries to access lazily constructed Factory.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public sealed class Blog : Identifiable<int>
[Attr(Capabilities = AttrCapabilities.All & ~(AttrCapabilities.AllowCreate | AttrCapabilities.AllowChange))]
public bool ShowAdvertisements => PlatformName.EndsWith("(using free account)", StringComparison.Ordinal);

public bool IsPublished { get; set; }

[HasMany]
public IList<BlogPost> Posts { get; set; } = new List<BlogPost>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public FilterDataTypeTests(IntegrationTestContext<TestableStartup<FilterDbContex
var options = (JsonApiOptions)testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
options.EnableLegacyFilterNotation = false;

if (!options.SerializerOptions.Converters.Any(converter => converter is JsonStringEnumMemberConverter))
if (!options.SerializerOptions.Converters.Any(converter => converter is JsonStringEnumConverter))
{
options.SerializerOptions.Converters.Add(new JsonStringEnumMemberConverter());
options.SerializerOptions.Converters.Add(new JsonTimeSpanConverter());
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum LabelColor
{
Red,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ public async Task Retrieves_all_properties_when_fieldset_contains_readonly_attri
store.Clear();

Blog blog = _fakers.Blog.Generate();
blog.IsPublished = true;

await _testContext.RunOnDatabaseAsync(async dbContext =>
{
Expand All @@ -771,7 +772,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Data.SingleValue.Relationships.Should().BeNull();

var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
blogCaptured.ShowAdvertisements.Should().Be(blogCaptured.ShowAdvertisements);
blogCaptured.ShowAdvertisements.Should().Be(blog.ShowAdvertisements);
blogCaptured.IsPublished.Should().Be(blog.IsPublished);
blogCaptured.Title.Should().Be(blog.Title);
}

Expand Down Expand Up @@ -817,7 +819,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
postCaptured.Id.Should().Be(post.Id);
postCaptured.Caption.Should().Be(post.Caption);
postCaptured.Url.Should().Be(postCaptured.Url);
postCaptured.Url.Should().Be(post.Url);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
// Act
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

responseDocument.Should().BeEmpty();
Expand Down Expand Up @@ -222,6 +223,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
// Act
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

responseDocument.Should().BeEmpty();
Expand Down Expand Up @@ -760,6 +762,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

// Assert
responseDocument.Should().BeEmpty();

await _testContext.RunOnDatabaseAsync(async dbContext =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
// Act
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

responseDocument.Should().BeEmpty();
Expand Down Expand Up @@ -283,6 +284,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePatchAsync<Document>(route, requestBody);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);

responseDocument.Data.SingleValue.ShouldNotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace JsonApiDotNetCoreTests.IntegrationTests.ReadWrite;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum WorkItemPriority
{
Low,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public async Task Filter_from_resource_definition_is_applied_on_secondary_endpoi
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<Planet>();
dbContext.Stars.AddRange(star);
dbContext.Stars.Add(star);
await dbContext.SaveChangesAsync();
});

Expand Down Expand Up @@ -387,7 +387,7 @@ public async Task Filter_from_resource_definition_is_applied_on_relationship_end
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<Planet>();
dbContext.Stars.AddRange(star);
dbContext.Stars.Add(star);
await dbContext.SaveChangesAsync();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace JsonApiDotNetCoreTests.IntegrationTests.ResourceDefinitions.Reading;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum StarKind
{
Other,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Globalization;
using System.Net;
using System.Text.Json.Serialization;
using FluentAssertions;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Resources;
Expand Down Expand Up @@ -34,11 +33,6 @@ public SerializationTests(IntegrationTestContext<TestableStartup<SerializationDb
options.AllowClientGeneratedIds = true;
options.IncludeJsonApiVersion = false;
options.IncludeTotalResourceCount = true;

if (!options.SerializerOptions.Converters.Any(converter => converter is JsonTimeSpanConverter))
{
options.SerializerOptions.Converters.Add(new JsonTimeSpanConverter());
}
}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
<PackageReference Include="Macross.Json.Extensions" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="$(EFCoreVersion)" />
Expand Down
4 changes: 2 additions & 2 deletions test/TestBuildingBlocks/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public sealed class HttpResponseMessageAssertions : ReferenceTypeAssertions<Http
{
protected override string Identifier => "response";

public HttpResponseMessageAssertions(HttpResponseMessage instance)
: base(instance)
public HttpResponseMessageAssertions(HttpResponseMessage subject)
: base(subject)
{
}

Expand Down
9 changes: 6 additions & 3 deletions test/TestBuildingBlocks/IntegrationTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ private WebApplicationFactory<TStartup> CreateFactory()
return factoryWithConfiguredContentRoot;
}

public virtual void Dispose()
public void Dispose()
{
RunOnDatabaseAsync(async dbContext => await dbContext.Database.EnsureDeletedAsync()).Wait();
if (_lazyFactory.IsValueCreated)
{
RunOnDatabaseAsync(async dbContext => await dbContext.Database.EnsureDeletedAsync()).Wait();

Factory.Dispose();
_lazyFactory.Value.Dispose();
}
}

public void ConfigureLogging(Action<ILoggingBuilder> loggingConfiguration)
Expand Down
4 changes: 1 addition & 3 deletions test/TestBuildingBlocks/TestableStartup.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using JsonApiDotNetCore.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace TestBuildingBlocks;

Expand All @@ -24,7 +22,7 @@ protected virtual void SetJsonApiOptions(JsonApiOptions options)
options.SerializerOptions.WriteIndented = true;
}

public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment environment, ILoggerFactory loggerFactory)
public virtual void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseJsonApi();
Expand Down