From 8292b8f7bbdfd3a9fa32d7cf19e9228be253e36f Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 17 Feb 2024 17:13:26 +1100 Subject: [PATCH] remove redundant uiCulture from UseCultureAttribute (#1391) --- .../UseCultureAttribute.cs | 122 ++++++++---------- 1 file changed, 51 insertions(+), 71 deletions(-) diff --git a/src/Humanizer.Tests.Shared/UseCultureAttribute.cs b/src/Humanizer.Tests.Shared/UseCultureAttribute.cs index c0da43370..cb5be8eff 100644 --- a/src/Humanizer.Tests.Shared/UseCultureAttribute.cs +++ b/src/Humanizer.Tests.Shared/UseCultureAttribute.cs @@ -1,82 +1,62 @@ using System.Reflection; using Xunit.Sdk; -namespace Humanizer.Tests +namespace Humanizer.Tests; + +/// +/// Apply this attribute to your test method to replace the +/// and +/// with another culture. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] +public class UseCultureAttribute : BeforeAfterTestAttribute { + readonly Lazy culture; + CultureInfo originalCulture; + CultureInfo originalUICulture; + /// - /// Apply this attribute to your test method to replace the - /// and - /// with another culture. + /// Replaces the culture and UI culture of the current thread with + /// /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] - public class UseCultureAttribute : BeforeAfterTestAttribute - { - readonly Lazy culture; - readonly Lazy uiCulture; - CultureInfo originalCulture; - CultureInfo originalUICulture; - - /// - /// Replaces the culture and UI culture of the current thread with - /// - /// - /// The name of the culture. - /// - /// - /// This constructor overload uses for both - /// and . - /// - /// - public UseCultureAttribute(string culture) - : this(culture, culture) - { } - - /// - /// Replaces the culture and UI culture of the current thread with - /// and - /// - /// The name of the culture. - /// The name of the UI culture. - public UseCultureAttribute(string culture, string uiCulture) - { - this.culture = new(() => new(culture)); - this.uiCulture = new(() => new(uiCulture)); - } + /// The name of the culture. + /// + /// + /// This constructor overload uses for both + /// and . + /// + /// + public UseCultureAttribute(string culture) => + this.culture = new(() => new(culture)); - /// - /// Gets the culture. - /// - public CultureInfo Culture => culture.Value; - - /// - /// Gets the UI culture. - /// - public CultureInfo UICulture => uiCulture.Value; + /// + /// Gets the culture. + /// + public CultureInfo Culture => culture.Value; - /// - /// Stores the current - /// and - /// and replaces them with the new cultures defined in the constructor. - /// - /// The method under test - public override void Before(MethodInfo methodUnderTest) - { - originalCulture = CultureInfo.CurrentCulture; - originalUICulture = CultureInfo.CurrentUICulture; + /// + /// Stores the current + /// and + /// and replaces them with the new cultures defined in the constructor. + /// + /// The method under test + public override void Before(MethodInfo methodUnderTest) + { + originalCulture = CultureInfo.CurrentCulture; + originalUICulture = CultureInfo.CurrentUICulture; - CultureInfo.CurrentCulture = Culture; - CultureInfo.CurrentUICulture = UICulture; - } + CultureInfo.CurrentCulture = Culture; + CultureInfo.CurrentUICulture = Culture; + } - /// - /// Restores the original and - /// to - /// - /// The method under test - public override void After(MethodInfo methodUnderTest) - { - CultureInfo.CurrentCulture = originalCulture; - CultureInfo.CurrentUICulture = originalUICulture; - } + /// + /// Restores the original and + /// to + /// + /// The method under test + public override void After(MethodInfo methodUnderTest) + { + CultureInfo.CurrentCulture = originalCulture; + CultureInfo.CurrentUICulture = originalUICulture; } -} +} \ No newline at end of file