diff --git a/csharp/Platform.Disposables.Tests/DisposableTests.cs b/csharp/Platform.Disposables.Tests/DisposableTests.cs index caa19fb..a4d6523 100644 --- a/csharp/Platform.Disposables.Tests/DisposableTests.cs +++ b/csharp/Platform.Disposables.Tests/DisposableTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Threading; @@ -42,7 +43,7 @@ private static ProcessStartInfo CreateProcessStartInfo(string logPath, bool wait return new ProcessStartInfo { FileName = "dotnet", - Arguments = $"run -p \"{projectPath}\" -f net7 \"{logPath}\" {waitForCancellation.ToString()}", + Arguments = $"run -p \"{projectPath}\" -f net8 \"{logPath}\" {waitForCancellation.ToString()}", UseShellExecute = false, CreateNoWindow = true }; @@ -79,5 +80,38 @@ private static string GetDisposalObjectTestProjectFilePath() } return path; } + + [Fact] + public static void MultipleDisposeExceptionMessageInternationalizationTest() + { + var testDisposable = new TestDisposable(); + testDisposable.Dispose(); + + // Test English (default) culture + var originalCulture = CultureInfo.CurrentUICulture; + try + { + CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); + var englishException = Assert.Throws(() => testDisposable.Dispose()); + Assert.Contains("Multiple dispose calls are not allowed", englishException.Message); + + // Test Russian culture + CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("ru-RU"); + var russianException = Assert.Throws(() => testDisposable.Dispose()); + Assert.Contains("Множественные вызовы Dispose не разрешены", russianException.Message); + } + finally + { + CultureInfo.CurrentUICulture = originalCulture; + } + } + + private class TestDisposable : DisposableBase + { + protected override void Dispose(bool manual, bool wasDisposed) + { + // Empty implementation for testing + } + } } } diff --git a/csharp/Platform.Disposables/DisposableBase.cs b/csharp/Platform.Disposables/DisposableBase.cs index c030a61..d5f5bd9 100644 --- a/csharp/Platform.Disposables/DisposableBase.cs +++ b/csharp/Platform.Disposables/DisposableBase.cs @@ -147,7 +147,7 @@ protected virtual void Dispose(bool manual) var wasDisposed = originalDisposedValue > 0; if (wasDisposed && !AllowMultipleDisposeCalls && manual) { - Ensure.Always.NotDisposed(this, ObjectName, "Multiple dispose calls are not allowed. Override AllowMultipleDisposeCalls property to modify behavior."); + Ensure.Always.NotDisposed(this, ObjectName, Resources.MultipleDisposeCallsNotAllowed); } if (AllowMultipleDisposeAttempts || !wasDisposed) { diff --git a/csharp/Platform.Disposables/Resources.Designer.cs b/csharp/Platform.Disposables/Resources.Designer.cs new file mode 100644 index 0000000..17d5478 --- /dev/null +++ b/csharp/Platform.Disposables/Resources.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 Platform.Disposables { + 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 Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 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("Platform.Disposables.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this 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 Multiple dispose calls are not allowed. Override AllowMultipleDisposeCalls property to modify behavior.. + /// + internal static string MultipleDisposeCallsNotAllowed { + get { + return ResourceManager.GetString("MultipleDisposeCallsNotAllowed", resourceCulture); + } + } + } +} \ No newline at end of file diff --git a/csharp/Platform.Disposables/Resources.resx b/csharp/Platform.Disposables/Resources.resx new file mode 100644 index 0000000..4ddc5f0 --- /dev/null +++ b/csharp/Platform.Disposables/Resources.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 + + + Multiple dispose calls are not allowed. Override AllowMultipleDisposeCalls property to modify behavior. + Exception message when multiple dispose calls are made on an object that doesn't allow them + + \ No newline at end of file diff --git a/csharp/Platform.Disposables/Resources.ru.resx b/csharp/Platform.Disposables/Resources.ru.resx new file mode 100644 index 0000000..78d47f6 --- /dev/null +++ b/csharp/Platform.Disposables/Resources.ru.resx @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Множественные вызовы Dispose не разрешены. Переопределите свойство AllowMultipleDisposeCalls для изменения поведения. + Сообщение исключения, когда выполняется несколько вызовов dispose для объекта, который их не разрешает + + \ No newline at end of file