Skip to content

Commit

Permalink
Merge 336b725 into c0eb108
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman authored Jul 16, 2023
2 parents c0eb108 + 336b725 commit 58b8f9f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore.SourceGenerators/SourceCodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void WriteNullableEnable()

private void WriteNamespaceImports(INamedTypeSymbol loggerFactoryInterface, INamedTypeSymbol resourceType, string? controllerNamespace)
{
_sourceBuilder.AppendLine($@"using {loggerFactoryInterface.ContainingNamespace};");
_sourceBuilder.AppendLine($"using {loggerFactoryInterface.ContainingNamespace};");

_sourceBuilder.AppendLine("using JsonApiDotNetCore.Configuration;");
_sourceBuilder.AppendLine("using JsonApiDotNetCore.Controllers;");
Expand All @@ -123,7 +123,7 @@ private void WriteOpenClassDeclaration(string controllerName, JsonApiEndpointsCo
string baseClassName = GetControllerBaseClassName(endpointsToGenerate);

WriteIndent();
_sourceBuilder.AppendLine($@"public sealed partial class {controllerName} : {baseClassName}<{resourceType.Name}, {idType}>");
_sourceBuilder.AppendLine($"public sealed partial class {controllerName} : {baseClassName}<{resourceType.Name}, {idType}>");

WriteOpenCurly();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,18 @@ protected async Task UpdateRelationshipAsync(RelationshipAttribute relationship,
private bool RequireLoadOfInverseRelationship(RelationshipAttribute relationship, [NotNullWhen(true)] object? trackedValueToAssign)
{
// See https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/502.
return trackedValueToAssign != null && relationship is HasOneAttribute { IsOneToOne: true };
if (trackedValueToAssign != null && relationship is HasOneAttribute { IsOneToOne: true })
{
IEntityType? leftEntityType = _dbContext.Model.FindEntityType(relationship.LeftType.ClrType);
INavigation? navigation = leftEntityType?.FindNavigation(relationship.Property.Name);

if (navigation != null && navigation.ForeignKey.DeclaringEntityType.ClrType == relationship.LeftType.ClrType)
{
return true;
}
}

return false;
}

protected virtual async Task SaveChangesAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreTests.IntegrationTests.AtomicOperations;
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.AtomicOperations")]
public sealed class MusicTrack : Identifiable<Guid>
{
[RegularExpression(@"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$")]
[RegularExpression("(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$")]
public override Guid Id { get; set; }

[Attr]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ public async Task Get_skips_middleware_and_formatters()
public async Task Post_skips_middleware_and_formatters()
{
// Arrange
using var request = new HttpRequestMessage(HttpMethod.Post, "/NonJsonApi")
using var request = new HttpRequestMessage(HttpMethod.Post, "/NonJsonApi");

request.Content = new StringContent("Jack")
{
Content = new StringContent("Jack")
Headers =
{
Headers =
{
ContentType = new MediaTypeHeaderValue("text/plain")
}
ContentType = new MediaTypeHeaderValue("text/plain")
}
};

Expand Down Expand Up @@ -90,14 +89,13 @@ public async Task Post_skips_error_handler()
public async Task Put_skips_middleware_and_formatters()
{
// Arrange
using var request = new HttpRequestMessage(HttpMethod.Put, "/NonJsonApi")
using var request = new HttpRequestMessage(HttpMethod.Put, "/NonJsonApi");

request.Content = new StringContent("\"Jane\"")
{
Content = new StringContent("\"Jane\"")
Headers =
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
ContentType = new MediaTypeHeaderValue("application/json")
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/SourceGeneratorTests/ControllerGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public sealed class Item : Identifiable<string?>
GeneratorDriverRunResult runResult = driver.GetRunResult();
runResult.Should().NotHaveDiagnostics();

runResult.Should().HaveProducedSourceCodeContaining(@"#nullable enable");
runResult.Should().HaveProducedSourceCodeContaining("#nullable enable");
}

[Fact]
Expand Down

0 comments on commit 58b8f9f

Please sign in to comment.