Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/Tests/Framework.Tests/Web/CorsConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ namespace Framework.Tests.Web;

public sealed class CorsConfigurationTests
{
// appsettings files are read by the ASP.NET configuration loader, which accepts comments and
// trailing commas, so parse them the same way.
private static readonly JsonDocumentOptions AppSettingsJson = new()
{
CommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};

[Theory]
[InlineData("appsettings.json")]
[InlineData("appsettings.Production.json")]
Expand All @@ -13,7 +21,7 @@ public void AllowedMethods_Should_IncludePatch_When_RestrictedCorsIsConfigured(s
string path = Path.Combine(AppContext.BaseDirectory, "HostConfiguration", fileName);

// Act
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path));
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path), AppSettingsJson);
JsonElement corsOptions = document.RootElement.GetProperty("CorsOptions");
string[] allowedMethods = corsOptions
.GetProperty("AllowedMethods")
Expand Down Expand Up @@ -47,7 +55,7 @@ public void AllowedHeaders_Should_IncludeClientHeader_When_RestrictedCorsIsConfi
string path = Path.Combine(AppContext.BaseDirectory, "HostConfiguration", fileName);

// Act
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path));
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path), AppSettingsJson);
string[] allowedHeaders = document.RootElement
.GetProperty("CorsOptions")
.GetProperty("AllowedHeaders")
Expand Down
Loading