Skip to content

Commit

Permalink
Merge branch 'master' into openapi-required-and-nullable-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Oct 1, 2023
2 parents c3c4844 + 923fbd8 commit 66a2dc4
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Middleware/HeaderConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ namespace JsonApiDotNetCore.Middleware;
public static class HeaderConstants
{
public const string MediaType = "application/vnd.api+json";
public const string AtomicOperationsMediaType = MediaType + "; ext=\"https://jsonapi.org/ext/atomic\"";
public const string AtomicOperationsMediaType = $"{MediaType}; ext=\"https://jsonapi.org/ext/atomic\"";
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public async Task Cannot_create_resource_with_invalid_attribute_value()
ErrorObject error = responseDocument.Errors[0];
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
error.Title.Should().Be("Input validation failed.");
error.Detail.Should().Be("The field Name must match the regular expression '^[\\w\\s]+$'.");
error.Detail.Should().Be(@"The field Name must match the regular expression '^[\w\s]+$'.");
error.Source.ShouldNotBeNull();
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
}
Expand Down Expand Up @@ -534,7 +534,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
ErrorObject error = responseDocument.Errors[0];
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
error.Title.Should().Be("Input validation failed.");
error.Detail.Should().Be("The field Name must match the regular expression '^[\\w\\s]+$'.");
error.Detail.Should().Be(@"The field Name must match the regular expression '^[\w\s]+$'.");
error.Source.ShouldNotBeNull();
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
await dbContext.SaveChangesAsync();
});

string route = $"/public-api/swimming-pools/{pool.StringId}/water-slides" +
"?filter=greaterThan(length-in-meters,'1')&fields[water-slides]=length-in-meters";
string route =
$"/public-api/swimming-pools/{pool.StringId}/water-slides?filter=greaterThan(length-in-meters,'1')&fields[water-slides]=length-in-meters";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
await dbContext.SaveChangesAsync();
});

string route = $"/PublicApi/SwimmingPools/{pool.StringId}/WaterSlides" + "?filter=greaterThan(LengthInMeters,'1')&fields[WaterSlides]=LengthInMeters";
string route = $"/PublicApi/SwimmingPools/{pool.StringId}/WaterSlides?filter=greaterThan(LengthInMeters,'1')&fields[WaterSlides]=LengthInMeters";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>

responseDocument.Links.ShouldNotBeNull();
responseDocument.Links.Self.Should().Be($"{HostPrefix}{route}");
responseDocument.Links.First.Should().Be(basePath + "?page%5Bsize%5D=1");
responseDocument.Links.First.Should().Be($"{basePath}?page%5Bsize%5D=1");
responseDocument.Links.Last.Should().BeNull();
responseDocument.Links.Prev.Should().Be(responseDocument.Links.First);
responseDocument.Links.Next.Should().Be(basePath + "?page%5Bnumber%5D=3&page%5Bsize%5D=1");
responseDocument.Links.Next.Should().Be($"{basePath}?page%5Bnumber%5D=3&page%5Bsize%5D=1");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Caption.Should().Be(post.Caption);
postCaptured.Url.Should().BeNull();
}
Expand Down Expand Up @@ -106,7 +106,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Data.ManyValue[0].Attributes.ShouldContainKey("caption").With(value => value.Should().Be(post.Caption));
responseDocument.Data.ManyValue[0].Relationships.Should().BeNull();

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Caption.Should().Be(post.Caption);
postCaptured.Url.Should().BeNull();
}
Expand Down Expand Up @@ -149,7 +149,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Caption.Should().BeNull();
postCaptured.Url.Should().BeNull();
}
Expand Down Expand Up @@ -193,7 +193,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).Which;
blogCaptured.Id.Should().Be(blog.Id);
blogCaptured.Title.Should().BeNull();

Expand Down Expand Up @@ -240,7 +240,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Url.Should().Be(post.Url);
postCaptured.Caption.Should().BeNull();
}
Expand Down Expand Up @@ -299,7 +299,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Id.Should().Be(post.Id);
postCaptured.Caption.Should().Be(post.Caption);

Expand Down Expand Up @@ -361,7 +361,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var accountCaptured = (WebAccount)store.Resources.Should().ContainSingle(resource => resource is WebAccount).And.Subject.Single();
var accountCaptured = (WebAccount)store.Resources.Should().ContainSingle(resource => resource is WebAccount).Which;
accountCaptured.Id.Should().Be(account.Id);
accountCaptured.DisplayName.Should().Be(account.DisplayName);

Expand Down Expand Up @@ -423,7 +423,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).Which;
blogCaptured.Id.Should().Be(blog.Id);
blogCaptured.Owner.ShouldNotBeNull();
blogCaptured.Owner.DisplayName.Should().Be(blog.Owner.DisplayName);
Expand Down Expand Up @@ -476,7 +476,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Included[0].Attributes.ShouldContainKey("color").With(value => value.Should().Be(post.Labels.Single().Color));
responseDocument.Included[0].Relationships.Should().BeNull();

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Id.Should().Be(post.Id);
postCaptured.Caption.Should().Be(post.Caption);

Expand Down Expand Up @@ -532,7 +532,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Included[1].Attributes.ShouldContainKey("caption").With(value => value.Should().Be(blog.Owner.Posts[0].Caption));
responseDocument.Included[1].Relationships.Should().BeNull();

var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).Which;
blogCaptured.Id.Should().Be(blog.Id);
blogCaptured.Title.Should().Be(blog.Title);
blogCaptured.PlatformName.Should().BeNull();
Expand Down Expand Up @@ -620,7 +620,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).Which;
blogCaptured.Id.Should().Be(blog.Id);
blogCaptured.Title.Should().Be(blog.Title);
blogCaptured.PlatformName.Should().BeNull();
Expand Down Expand Up @@ -656,7 +656,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Data.ManyValue[0].Attributes.ShouldContainKey("caption").With(value => value.Should().Be(post.Caption));
responseDocument.Data.ManyValue[0].Relationships.Should().BeNull();

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Id.Should().Be(post.Id);
postCaptured.Caption.Should().Be(post.Caption);
postCaptured.Url.Should().BeNull();
Expand Down Expand Up @@ -691,7 +691,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Data.ManyValue[0].Attributes.Should().BeNull();
responseDocument.Data.ManyValue[0].Relationships.Should().BeNull();

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Id.Should().Be(post.Id);
postCaptured.Url.Should().BeNull();
}
Expand Down Expand Up @@ -824,7 +824,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Data.SingleValue.Attributes.ShouldContainKey("showAdvertisements").With(value => value.Should().Be(blog.ShowAdvertisements));
responseDocument.Data.SingleValue.Relationships.Should().BeNull();

var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).And.Subject.Single();
var blogCaptured = (Blog)store.Resources.Should().ContainSingle(resource => resource is Blog).Which;
blogCaptured.ShowAdvertisements.Should().Be(blog.ShowAdvertisements);
blogCaptured.IsPublished.Should().Be(blog.IsPublished);
blogCaptured.Title.Should().Be(blog.Title);
Expand Down Expand Up @@ -869,7 +869,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
value.Links.Related.ShouldNotBeNull();
});

var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).And.Subject.Single();
var postCaptured = (BlogPost)store.Resources.Should().ContainSingle(resource => resource is BlogPost).Which;
postCaptured.Id.Should().Be(post.Id);
postCaptured.Caption.Should().Be(post.Caption);
postCaptured.Url.Should().Be(post.Url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public async Task Cannot_create_resource_on_unknown_resource_type_in_url()
}
};

const string route = "/" + Unknown.ResourceType;
const string route = $"/{Unknown.ResourceType}";

// Act
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAsync<string>(route, requestBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
public async Task Cannot_get_primary_resources_for_unknown_type()
{
// Arrange
const string route = "/" + Unknown.ResourceType;
const string route = $"/{Unknown.ResourceType}";

// Act
(HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecuteGetAsync<string>(route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ParseFails(string patternText, string errorMessage)
Action action = () => FieldChainPattern.Parse(patternSource.Text);

// Assert
PatternFormatException exception = action.Should().Throw<PatternFormatException>().Which;
PatternFormatException exception = action.Should().ThrowExactly<PatternFormatException>().Which;
exception.Message.Should().Be(errorMessage);
exception.Position.Should().Be(patternSource.Position);
exception.Pattern.Should().Be(patternSource.Text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void VisitInclude(string expressionText, string expectedTypes)

// Assert
List<string> visitedTypeNames = rewriter.ExpressionsVisited.Select(queryExpression => queryExpression.GetType().Name).ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => type + "Expression").ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => $"{type}Expression").ToList();

visitedTypeNames.Should().ContainInOrder(expectedTypeNames);
visitedTypeNames.Should().HaveCount(expectedTypeNames.Count);
Expand All @@ -76,7 +76,7 @@ public void VisitSparseFieldSet(string expressionText, string expectedTypes)

// Assert
List<string> visitedTypeNames = rewriter.ExpressionsVisited.Select(queryExpression => queryExpression.GetType().Name).ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => type + "Expression").ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => $"{type}Expression").ToList();

visitedTypeNames.Should().ContainInOrder(expectedTypeNames);
visitedTypeNames.Should().HaveCount(expectedTypeNames.Count);
Expand Down Expand Up @@ -136,7 +136,7 @@ public void VisitFilter(string expressionText, string expectedTypes)

// Assert
List<string> visitedTypeNames = rewriter.ExpressionsVisited.Select(queryExpression => queryExpression.GetType().Name).ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => type + "Expression").ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => $"{type}Expression").ToList();

visitedTypeNames.Should().ContainInOrder(expectedTypeNames);
visitedTypeNames.Should().HaveCount(expectedTypeNames.Count);
Expand All @@ -160,7 +160,7 @@ public void VisitSort(string expressionText, string expectedTypes)

// Assert
List<string> visitedTypeNames = rewriter.ExpressionsVisited.Select(queryExpression => queryExpression.GetType().Name).ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => type + "Expression").ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => $"{type}Expression").ToList();

visitedTypeNames.Should().ContainInOrder(expectedTypeNames);
visitedTypeNames.Should().HaveCount(expectedTypeNames.Count);
Expand All @@ -183,7 +183,7 @@ public void VisitPagination(string expressionText, string expectedTypes)

// Assert
List<string> visitedTypeNames = rewriter.ExpressionsVisited.Select(queryExpression => queryExpression.GetType().Name).ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => type + "Expression").ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => $"{type}Expression").ToList();

visitedTypeNames.Should().ContainInOrder(expectedTypeNames);
visitedTypeNames.Should().HaveCount(expectedTypeNames.Count);
Expand All @@ -208,7 +208,7 @@ public void VisitParameterScope(string expressionText, string expectedTypes)

// Assert
List<string> visitedTypeNames = rewriter.ExpressionsVisited.Select(queryExpression => queryExpression.GetType().Name).ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => type + "Expression").ToList();
List<string> expectedTypeNames = expectedTypes.Split(',').Select(type => $"{type}Expression").ToList();

visitedTypeNames.Should().ContainInOrder(expectedTypeNames);
visitedTypeNames.Should().HaveCount(expectedTypeNames.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public void Cannot_convert_concatenation_operator()
// Act
Action action = () => resourceDefinition.GetSortExpressionFromLambda(new JsonApiResourceDefinition<FileEntry, long>.PropertySortOrder
{
(file => file.Name + ":" + file.Content, ListSortDirection.Ascending)
(file => $"{file.Name}:{file.Content}", ListSortDirection.Ascending)
});

// Assert
Expand Down

0 comments on commit 66a2dc4

Please sign in to comment.