Skip to content

Commit c2cf072

Browse files
author
Bart Koelman
authored
Merge pull request #1131 from json-api-dotnet/small-fixes
Various small corrections
2 parents 510172b + b13c4ff commit c2cf072

File tree

20 files changed

+42
-53
lines changed

20 files changed

+42
-53
lines changed

.github/PULL_REQUEST_TEMPLATE.md

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ Closes #{ISSUE_NUMBER}
77
- [ ] Complies with our [contributing guidelines](./.github/CONTRIBUTING.md)
88
- [ ] Adapted tests
99
- [ ] Documentation updated
10-
- [ ] Created issue to update [Templates](https://github.com/json-api-dotnet/Templates/issues/new): {ISSUE_NUMBER}

src/JsonApiDotNetCore/Configuration/TypeLocator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal sealed class TypeLocator
8989
private static (Type implementationType, Type serviceInterface)? GetContainerRegistrationFromType(Type nextType, Type unboundInterface,
9090
Type[] interfaceTypeArguments)
9191
{
92-
if (!nextType.IsNested)
92+
if (!nextType.IsNested && !nextType.IsAbstract && !nextType.IsInterface)
9393
{
9494
foreach (Type nextConstructedInterface in nextType.GetInterfaces().Where(type => type.IsGenericType))
9595
{

test/JsonApiDotNetCoreTests/IntegrationTests/HostingInIIS/HostingStartup.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using JetBrains.Annotations;
22
using JsonApiDotNetCore.Configuration;
33
using Microsoft.AspNetCore.Builder;
4-
using Microsoft.AspNetCore.Hosting;
54
using Microsoft.EntityFrameworkCore;
6-
using Microsoft.Extensions.Logging;
75
using TestBuildingBlocks;
86

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

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

27-
base.Configure(app, environment, loggerFactory);
25+
base.Configure(app);
2826
}
2927
}

test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs

-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@ public void Fails_at_startup_when_multiple_controllers_exist_for_same_resource_t
2222
// Assert
2323
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage("Multiple controllers found for resource type 'knownResources'.");
2424
}
25-
26-
public override void Dispose()
27-
{
28-
// Prevents crash when test cleanup tries to access lazily constructed Factory.
29-
}
3025
}

test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/NonJsonApiControllerTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public async Task Get_skips_middleware_and_formatters()
2323
// Arrange
2424
using var request = new HttpRequestMessage(HttpMethod.Get, "/NonJsonApi");
2525

26-
HttpClient client = _testContext.Factory.CreateClient();
26+
using HttpClient client = _testContext.Factory.CreateClient();
2727

2828
// Act
29-
HttpResponseMessage httpResponse = await client.SendAsync(request);
29+
using HttpResponseMessage httpResponse = await client.SendAsync(request);
3030

3131
// Assert
3232
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
@@ -52,10 +52,10 @@ public async Task Post_skips_middleware_and_formatters()
5252
}
5353
};
5454

55-
HttpClient client = _testContext.Factory.CreateClient();
55+
using HttpClient client = _testContext.Factory.CreateClient();
5656

5757
// Act
58-
HttpResponseMessage httpResponse = await client.SendAsync(request);
58+
using HttpResponseMessage httpResponse = await client.SendAsync(request);
5959

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

75-
HttpClient client = _testContext.Factory.CreateClient();
75+
using HttpClient client = _testContext.Factory.CreateClient();
7676

7777
// Act
78-
HttpResponseMessage httpResponse = await client.SendAsync(request);
78+
using HttpResponseMessage httpResponse = await client.SendAsync(request);
7979

8080
// Assert
8181
httpResponse.Should().HaveStatusCode(HttpStatusCode.BadRequest);
@@ -101,10 +101,10 @@ public async Task Put_skips_middleware_and_formatters()
101101
}
102102
};
103103

104-
HttpClient client = _testContext.Factory.CreateClient();
104+
using HttpClient client = _testContext.Factory.CreateClient();
105105

106106
// Act
107-
HttpResponseMessage httpResponse = await client.SendAsync(request);
107+
using HttpResponseMessage httpResponse = await client.SendAsync(request);
108108

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

124-
HttpClient client = _testContext.Factory.CreateClient();
124+
using HttpClient client = _testContext.Factory.CreateClient();
125125

126126
// Act
127-
HttpResponseMessage httpResponse = await client.SendAsync(request);
127+
using HttpResponseMessage httpResponse = await client.SendAsync(request);
128128

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

144-
HttpClient client = _testContext.Factory.CreateClient();
144+
using HttpClient client = _testContext.Factory.CreateClient();
145145

146146
// Act
147-
HttpResponseMessage httpResponse = await client.SendAsync(request);
147+
using HttpResponseMessage httpResponse = await client.SendAsync(request);
148148

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

test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/UnknownResourceControllerTests.cs

-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@ public void Fails_at_startup_when_using_controller_for_resource_type_that_is_not
2222
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage($"Controller '{typeof(UnknownResourcesController)}' " +
2323
$"depends on resource type '{typeof(UnknownResource)}', which does not exist in the resource graph.");
2424
}
25-
26-
public override void Dispose()
27-
{
28-
// Prevents crash when test cleanup tries to access lazily constructed Factory.
29-
}
3025
}

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/Blog.cs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public sealed class Blog : Identifiable<int>
1717
[Attr(Capabilities = AttrCapabilities.All & ~(AttrCapabilities.AllowCreate | AttrCapabilities.AllowChange))]
1818
public bool ShowAdvertisements => PlatformName.EndsWith("(using free account)", StringComparison.Ordinal);
1919

20+
public bool IsPublished { get; set; }
21+
2022
[HasMany]
2123
public IList<BlogPost> Posts { get; set; } = new List<BlogPost>();
2224

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/Filtering/FilterDataTypeTests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ public FilterDataTypeTests(IntegrationTestContext<TestableStartup<FilterDbContex
2626
var options = (JsonApiOptions)testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
2727
options.EnableLegacyFilterNotation = false;
2828

29-
if (!options.SerializerOptions.Converters.Any(converter => converter is JsonStringEnumMemberConverter))
29+
if (!options.SerializerOptions.Converters.Any(converter => converter is JsonStringEnumConverter))
3030
{
31-
options.SerializerOptions.Converters.Add(new JsonStringEnumMemberConverter());
32-
options.SerializerOptions.Converters.Add(new JsonTimeSpanConverter());
31+
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
3332
}
3433
}
3534

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/LabelColor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings;
55

66
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
7-
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
7+
[JsonConverter(typeof(JsonStringEnumConverter))]
88
public enum LabelColor
99
{
1010
Red,

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ public async Task Retrieves_all_properties_when_fieldset_contains_readonly_attri
749749
store.Clear();
750750

751751
Blog blog = _fakers.Blog.Generate();
752+
blog.IsPublished = true;
752753

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

773774
var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
774-
blogCaptured.ShowAdvertisements.Should().Be(blogCaptured.ShowAdvertisements);
775+
blogCaptured.ShowAdvertisements.Should().Be(blog.ShowAdvertisements);
776+
blogCaptured.IsPublished.Should().Be(blog.IsPublished);
775777
blogCaptured.Title.Should().Be(blog.Title);
776778
}
777779

@@ -817,7 +819,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
817819
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
818820
postCaptured.Id.Should().Be(post.Id);
819821
postCaptured.Caption.Should().Be(post.Caption);
820-
postCaptured.Url.Should().Be(postCaptured.Url);
822+
postCaptured.Url.Should().Be(post.Url);
821823
}
822824

823825
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/UpdateToOneRelationshipTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
168168
// Act
169169
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(route, requestBody);
170170

171+
// Assert
171172
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
172173

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

226+
// Assert
225227
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
226228

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

765+
// Assert
763766
responseDocument.Should().BeEmpty();
764767

765768
await _testContext.RunOnDatabaseAsync(async dbContext =>

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateToOneRelationshipTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
114114
// Act
115115
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(route, requestBody);
116116

117+
// Assert
117118
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
118119

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

287+
// Assert
286288
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
287289

288290
responseDocument.Data.SingleValue.ShouldNotBeNull();

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/WorkItemPriority.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace JsonApiDotNetCoreTests.IntegrationTests.ReadWrite;
55

66
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
7-
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
7+
[JsonConverter(typeof(JsonStringEnumConverter))]
88
public enum WorkItemPriority
99
{
1010
Low,

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/ResourceDefinitionReadTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public async Task Filter_from_resource_definition_is_applied_on_secondary_endpoi
331331
await _testContext.RunOnDatabaseAsync(async dbContext =>
332332
{
333333
await dbContext.ClearTableAsync<Planet>();
334-
dbContext.Stars.AddRange(star);
334+
dbContext.Stars.Add(star);
335335
await dbContext.SaveChangesAsync();
336336
});
337337

@@ -387,7 +387,7 @@ public async Task Filter_from_resource_definition_is_applied_on_relationship_end
387387
await _testContext.RunOnDatabaseAsync(async dbContext =>
388388
{
389389
await dbContext.ClearTableAsync<Planet>();
390-
dbContext.Stars.AddRange(star);
390+
dbContext.Stars.Add(star);
391391
await dbContext.SaveChangesAsync();
392392
});
393393

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/StarKind.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace JsonApiDotNetCoreTests.IntegrationTests.ResourceDefinitions.Reading;
55

66
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
7-
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
7+
[JsonConverter(typeof(JsonStringEnumConverter))]
88
public enum StarKind
99
{
1010
Other,

test/JsonApiDotNetCoreTests/IntegrationTests/Serialization/SerializationTests.cs

-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Globalization;
22
using System.Net;
3-
using System.Text.Json.Serialization;
43
using FluentAssertions;
54
using JsonApiDotNetCore.Configuration;
65
using JsonApiDotNetCore.Resources;
@@ -34,11 +33,6 @@ public SerializationTests(IntegrationTestContext<TestableStartup<SerializationDb
3433
options.AllowClientGeneratedIds = true;
3534
options.IncludeJsonApiVersion = false;
3635
options.IncludeTotalResourceCount = true;
37-
38-
if (!options.SerializerOptions.Converters.Any(converter => converter is JsonTimeSpanConverter))
39-
{
40-
options.SerializerOptions.Converters.Add(new JsonTimeSpanConverter());
41-
}
4236
}
4337

4438
[Fact]

test/JsonApiDotNetCoreTests/JsonApiDotNetCoreTests.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
20-
<PackageReference Include="Macross.Json.Extensions" Version="2.0.0" />
2120
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetVersion)" />
2221
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(EFCoreVersion)" />
2322
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="$(EFCoreVersion)" />

test/TestBuildingBlocks/HttpResponseMessageExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public sealed class HttpResponseMessageAssertions : ReferenceTypeAssertions<Http
1717
{
1818
protected override string Identifier => "response";
1919

20-
public HttpResponseMessageAssertions(HttpResponseMessage instance)
21-
: base(instance)
20+
public HttpResponseMessageAssertions(HttpResponseMessage subject)
21+
: base(subject)
2222
{
2323
}
2424

test/TestBuildingBlocks/IntegrationTestContext.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ private WebApplicationFactory<TStartup> CreateFactory()
103103
return factoryWithConfiguredContentRoot;
104104
}
105105

106-
public virtual void Dispose()
106+
public void Dispose()
107107
{
108-
RunOnDatabaseAsync(async dbContext => await dbContext.Database.EnsureDeletedAsync()).Wait();
108+
if (_lazyFactory.IsValueCreated)
109+
{
110+
RunOnDatabaseAsync(async dbContext => await dbContext.Database.EnsureDeletedAsync()).Wait();
109111

110-
Factory.Dispose();
112+
_lazyFactory.Value.Dispose();
113+
}
111114
}
112115

113116
public void ConfigureLogging(Action<ILoggingBuilder> loggingConfiguration)

test/TestBuildingBlocks/TestableStartup.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using JsonApiDotNetCore.Configuration;
22
using Microsoft.AspNetCore.Builder;
3-
using Microsoft.AspNetCore.Hosting;
43
using Microsoft.EntityFrameworkCore;
54
using Microsoft.Extensions.DependencyInjection;
6-
using Microsoft.Extensions.Logging;
75

86
namespace TestBuildingBlocks;
97

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

27-
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment environment, ILoggerFactory loggerFactory)
25+
public virtual void Configure(IApplicationBuilder app)
2826
{
2927
app.UseRouting();
3028
app.UseJsonApi();

0 commit comments

Comments
 (0)