diff --git a/src/System.Private.ServiceModel/tests/Common/Infrastructure/xunit/WcfCurrentCultureAttribute.cs b/src/System.Private.ServiceModel/tests/Common/Infrastructure/xunit/WcfCurrentCultureAttribute.cs new file mode 100644 index 00000000000..6ba70c4b67f --- /dev/null +++ b/src/System.Private.ServiceModel/tests/Common/Infrastructure/xunit/WcfCurrentCultureAttribute.cs @@ -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; + } + } +} diff --git a/src/System.ServiceModel.Primitives/tests/ServiceModel/FaultExceptionTest.cs b/src/System.ServiceModel.Primitives/tests/ServiceModel/FaultExceptionTest.cs index 2beca2ba8ea..d07f0080de4 100644 --- a/src/System.ServiceModel.Primitives/tests/ServiceModel/FaultExceptionTest.cs +++ b/src/System.ServiceModel.Primitives/tests/ServiceModel/FaultExceptionTest.cs @@ -36,6 +36,7 @@ public static void Ctor_TDetail_FaultReason() } [WcfFact] + [WcfCurrentCulture("en-US")] public static void Serializable_TDetail() { // This isn't exactly what NetFx generates as the HResult is different due to CommunicationException deriving from SystemException on NetFx @@ -57,6 +58,7 @@ public static void Serializable_TDetail() } [WcfFact] + [WcfCurrentCulture("en-US")] public static void Serializable_Default() { string netfxBsl = @"System.ServiceModel.FaultExceptionThe creator of this fault did not specify a Reason.0-2146233088SenderThe creator of this fault did not specify a Reason.en-US";