SetCultureAttribute
Sets the current Culture on an assembly, test fixture or test method for
the duration of a test. The culture remains set until the test or fixture
completes and is then reset to its original value.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using System;
using System.Globalization;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class SetCultureAttribute : PropertyAttribute, IApplyToContext
{
private readonly string _culture;
public SetCultureAttribute(string culture)
: base("SetCulture", culture)
{
_culture = culture;
}
void IApplyToContext.ApplyToContext(TestExecutionContext context)
{
context.CurrentCulture = new CultureInfo(_culture, false);
}
}
}