From fca75220f67733f7d494568539a3ecc84ad7bc9e Mon Sep 17 00:00:00 2001 From: Jukka Snellman Date: Fri, 12 Aug 2022 15:30:59 +0300 Subject: [PATCH] add basic test --- .gitignore | 2 + .../StringLocalizerWithCulture.Tests.csproj | 46 +++++++ .../StringLocalizerWithCultureTests.cs | 35 +++++ .../TestData/MyClass.Designer.cs | 72 ++++++++++ .../TestData/MyClass.resx | 123 ++++++++++++++++++ StringLocalizerWithCulture.Tests/Usings.cs | 1 + StringLocalizerWithCulture.sln | 8 +- 7 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 StringLocalizerWithCulture.Tests/StringLocalizerWithCulture.Tests.csproj create mode 100644 StringLocalizerWithCulture.Tests/StringLocalizerWithCultureTests.cs create mode 100644 StringLocalizerWithCulture.Tests/TestData/MyClass.Designer.cs create mode 100644 StringLocalizerWithCulture.Tests/TestData/MyClass.resx create mode 100644 StringLocalizerWithCulture.Tests/Usings.cs diff --git a/.gitignore b/.gitignore index 2b52017..f506d1d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /.vs /StringLocalizerWithCulture/obj /StringLocalizerWithCulture/bin +/StringLocalizerWithCulture.Tests/bin +/StringLocalizerWithCulture.Tests/obj diff --git a/StringLocalizerWithCulture.Tests/StringLocalizerWithCulture.Tests.csproj b/StringLocalizerWithCulture.Tests/StringLocalizerWithCulture.Tests.csproj new file mode 100644 index 0000000..fa351d8 --- /dev/null +++ b/StringLocalizerWithCulture.Tests/StringLocalizerWithCulture.Tests.csproj @@ -0,0 +1,46 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + True + True + MyClass.resx + + + + + + ResXFileCodeGenerator + MyClass.Designer.cs + + + + diff --git a/StringLocalizerWithCulture.Tests/StringLocalizerWithCultureTests.cs b/StringLocalizerWithCulture.Tests/StringLocalizerWithCultureTests.cs new file mode 100644 index 0000000..27cf22c --- /dev/null +++ b/StringLocalizerWithCulture.Tests/StringLocalizerWithCultureTests.cs @@ -0,0 +1,35 @@ +using FluentAssertions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System.Globalization; + +namespace StringLocalizerWithCulture.Tests +{ + public class StringLocalizerWithCultureTests + { + + private readonly IStringLocalizerWithCultureFactory _factory; + + public StringLocalizerWithCultureTests() { + var services = new ServiceCollection() + .AddSingleton(new LoggerFactory()) + .AddLocalizationWithCulture() + .BuildServiceProvider(); + _factory = services.GetRequiredService(); + } + + [Fact] + public void GetString() + { + var localizer = _factory.Create(typeof(MyClass), CultureInfo.InvariantCulture); + var actual = localizer["Hello"]; + actual.Should().Be("Hello World"); + } + + } + + class MyClass + { + + } +} \ No newline at end of file diff --git a/StringLocalizerWithCulture.Tests/TestData/MyClass.Designer.cs b/StringLocalizerWithCulture.Tests/TestData/MyClass.Designer.cs new file mode 100644 index 0000000..a5e27cb --- /dev/null +++ b/StringLocalizerWithCulture.Tests/TestData/MyClass.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace StringLocalizerWithCulture.Tests.TestData { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class MyClass { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal MyClass() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("StringLocalizerWithCulture.Tests.TestData.MyClass", typeof(MyClass).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Hello World. + /// + internal static string Hello { + get { + return ResourceManager.GetString("Hello", resourceCulture); + } + } + } +} diff --git a/StringLocalizerWithCulture.Tests/TestData/MyClass.resx b/StringLocalizerWithCulture.Tests/TestData/MyClass.resx new file mode 100644 index 0000000..54525ad --- /dev/null +++ b/StringLocalizerWithCulture.Tests/TestData/MyClass.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World + + \ No newline at end of file diff --git a/StringLocalizerWithCulture.Tests/Usings.cs b/StringLocalizerWithCulture.Tests/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/StringLocalizerWithCulture.Tests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/StringLocalizerWithCulture.sln b/StringLocalizerWithCulture.sln index 5e99155..e9a2de6 100644 --- a/StringLocalizerWithCulture.sln +++ b/StringLocalizerWithCulture.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringLocalizerWithCulture", "StringLocalizerWithCulture\StringLocalizerWithCulture.csproj", "{8DA84E58-3228-4BE1-A7B4-23A57B1F5B18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StringLocalizerWithCulture", "StringLocalizerWithCulture\StringLocalizerWithCulture.csproj", "{8DA84E58-3228-4BE1-A7B4-23A57B1F5B18}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringLocalizerWithCulture.Tests", "StringLocalizerWithCulture.Tests\StringLocalizerWithCulture.Tests.csproj", "{C53FE560-2103-446C-A390-9D6E50F7C4F1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {8DA84E58-3228-4BE1-A7B4-23A57B1F5B18}.Debug|Any CPU.Build.0 = Debug|Any CPU {8DA84E58-3228-4BE1-A7B4-23A57B1F5B18}.Release|Any CPU.ActiveCfg = Release|Any CPU {8DA84E58-3228-4BE1-A7B4-23A57B1F5B18}.Release|Any CPU.Build.0 = Release|Any CPU + {C53FE560-2103-446C-A390-9D6E50F7C4F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C53FE560-2103-446C-A390-9D6E50F7C4F1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C53FE560-2103-446C-A390-9D6E50F7C4F1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C53FE560-2103-446C-A390-9D6E50F7C4F1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE