Skip to content
Merged
Changes from 2 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
23 changes: 23 additions & 0 deletions src/HotChocolate/Core/test/Types.Analyzers.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
Expand Down Expand Up @@ -111,6 +112,9 @@ public static Snapshot GetGeneratedSourceSnapshot(
MetadataReference.CreateFromFile(typeof(Authorization.AuthorizeAttribute).Assembly.Location)
];

// Compile errors are localized, so pin the culture since otherwise the snapshot comparison may fail
using var cultureScope = new UseSpecificCulture("en-US");

// Create a Roslyn compilation for the syntax tree.
var parseOptions = !enableInterceptors
? CSharpParseOptions.Default
Expand Down Expand Up @@ -314,4 +318,23 @@ private static void AddDiagnosticsToSnapshot(

[GeneratedRegex("MiddlewareFactories([a-z0-9]{32})")]
private static partial Regex MiddlewareFactoryHashRegex();

private sealed class UseSpecificCulture : IDisposable
{
private readonly CultureInfo _previousCurrentCulture;
private readonly CultureInfo _previousCurrentUiCulture;
public UseSpecificCulture(string cultureName)
{
_previousCurrentCulture = CultureInfo.CurrentCulture;
_previousCurrentUiCulture = CultureInfo.CurrentUICulture;
var culture = CultureInfo.GetCultureInfo(cultureName);
CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = culture;
}

public void Dispose()
{
CultureInfo.CurrentCulture = _previousCurrentCulture;
CultureInfo.CurrentUICulture = _previousCurrentUiCulture;
}
}
}