forked from dotnet/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of default values in RDG (dotnet#51193)
* Fix handling of default values in RDG * Address feedback * Cover more test scenarios * Add tests for culture + decimal * Add UseCulture test attribute * Fix formatting
- Loading branch information
1 parent
746ec24
commit 6e1cebd
Showing
3 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System; | ||
using System.Globalization; | ||
using System.Reflection; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.AspNetCore.Testing; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public sealed class UseCultureAttribute : BeforeAfterTestAttribute | ||
{ | ||
private CultureInfo _originalCulture; | ||
private CultureInfo _originalUiCulture; | ||
public UseCultureAttribute(string culture) | ||
: this(culture, culture) | ||
{ | ||
} | ||
|
||
public UseCultureAttribute(string culture, string uiCulture) | ||
{ | ||
Culture = new CultureInfo(culture); | ||
UiCulture = new CultureInfo(uiCulture); | ||
} | ||
|
||
public CultureInfo Culture { get; } | ||
public CultureInfo UiCulture { get; } | ||
|
||
public override void Before(MethodInfo methodUnderTest) | ||
{ | ||
_originalCulture = CultureInfo.CurrentCulture; | ||
_originalUiCulture = CultureInfo.CurrentUICulture; | ||
CultureInfo.CurrentCulture = Culture; | ||
CultureInfo.CurrentUICulture = UiCulture; | ||
} | ||
|
||
public override void After(MethodInfo methodUnderTest) | ||
{ | ||
CultureInfo.CurrentCulture = _originalCulture; | ||
CultureInfo.CurrentUICulture = _originalUiCulture; | ||
} | ||
} |