-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some tests that would fail when running under a non en-US culture
Before this commit, two tests would fail with this error (FaultExceptionTest.Serializable_TDetail and FaultExceptionTest.Serializable_Default): ``` Xunit.Sdk.EqualException Assert.Equal() Failure ↓ (pos 1259) Expected: ···:text><a:xmlLang>en-US</a:xmlLang></a:FaultException.FaultRea··· Actual: ···:text><a:xmlLang>fr-CH</a:xmlLang></a:FaultException.FaultRea··· ↑ (pos 1259) ``` Explicitly setting the expected culture with a `BeforeAfterTestAttribute` solves this issue.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...stem.Private.ServiceModel/tests/Common/Infrastructure/xunit/WcfCurrentCultureAttribute.cs
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,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Reflection; | ||
using Xunit.Sdk; | ||
|
||
namespace Infrastructure.Common | ||
{ | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | ||
public class WcfCurrentCultureAttribute : BeforeAfterTestAttribute | ||
{ | ||
private readonly CultureInfo _cultureInfo; | ||
private CultureInfo _savedCultureInfo; | ||
|
||
public WcfCurrentCultureAttribute(string name) | ||
{ | ||
_cultureInfo = new CultureInfo(name); | ||
} | ||
|
||
public override void Before(MethodInfo methodUnderTest) | ||
{ | ||
_savedCultureInfo = CultureInfo.CurrentCulture; | ||
CultureInfo.CurrentCulture = _cultureInfo; | ||
} | ||
|
||
public override void After(MethodInfo methodUnderTest) | ||
{ | ||
CultureInfo.CurrentCulture = _savedCultureInfo; | ||
} | ||
} | ||
} |
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