diff --git a/cpp/Platform.Exceptions.Tests/ContractTests.cpp b/cpp/Platform.Exceptions.Tests/ContractTests.cpp new file mode 100644 index 0000000..991fd66 --- /dev/null +++ b/cpp/Platform.Exceptions.Tests/ContractTests.cpp @@ -0,0 +1,7 @@ +namespace Platform::Exceptions::Tests +{ + TEST(ContractTests, ArgumentNotNullContractTest) + { + EXPECT_THROW(Contract::Always::ArgumentNotNull(nullptr, "object"), std::invalid_argument); + }; +} diff --git a/cpp/Platform.Exceptions.Tests/EnsuranceTests.cpp b/cpp/Platform.Exceptions.Tests/EnsuranceTests.cpp deleted file mode 100644 index c9c9df0..0000000 --- a/cpp/Platform.Exceptions.Tests/EnsuranceTests.cpp +++ /dev/null @@ -1,7 +0,0 @@ -namespace Platform::Exceptions::Tests -{ - TEST(EnsuranceTests, ArgumentNotNullEnsuranceTest) - { - EXPECT_THROW(Ensure::Always::ArgumentNotNull(nullptr, "object"), std::invalid_argument); - }; -} diff --git a/cpp/Platform.Exceptions.Tests/Ignore/EnsureExtensions.cpp b/cpp/Platform.Exceptions.Tests/Ignore/ContractExtensions.cpp similarity index 100% rename from cpp/Platform.Exceptions.Tests/Ignore/EnsureExtensions.cpp rename to cpp/Platform.Exceptions.Tests/Ignore/ContractExtensions.cpp diff --git a/cpp/Platform.Exceptions.Tests/Ignore/IgnoredEnsuranceTests.cpp b/cpp/Platform.Exceptions.Tests/Ignore/IgnoredContractTests.cpp similarity index 71% rename from cpp/Platform.Exceptions.Tests/Ignore/IgnoredEnsuranceTests.cpp rename to cpp/Platform.Exceptions.Tests/Ignore/IgnoredContractTests.cpp index e09517a..fe898e1 100644 --- a/cpp/Platform.Exceptions.Tests/Ignore/IgnoredEnsuranceTests.cpp +++ b/cpp/Platform.Exceptions.Tests/Ignore/IgnoredContractTests.cpp @@ -1,6 +1,6 @@ namespace Platform::Exceptions::Tests::Ignore { - TEST(IgnoredEnsuranceTests, EnsuranceIgnoredTest) + TEST(IgnoredContractTests, ContractIgnoredTest) { EXPECT_NO_THROW(Always::ArgumentNotNull(nullptr, "object")); }; diff --git a/cpp/Platform.Exceptions/Ensure.h b/cpp/Platform.Exceptions/Contract.h similarity index 100% rename from cpp/Platform.Exceptions/Ensure.h rename to cpp/Platform.Exceptions/Contract.h diff --git a/cpp/Platform.Exceptions/EnsureExtensions.h b/cpp/Platform.Exceptions/ContractExtensions.h similarity index 96% rename from cpp/Platform.Exceptions/EnsureExtensions.h rename to cpp/Platform.Exceptions/ContractExtensions.h index 1cb8287..08bea34 100644 --- a/cpp/Platform.Exceptions/EnsureExtensions.h +++ b/cpp/Platform.Exceptions/ContractExtensions.h @@ -1,4 +1,4 @@ -namespace Platform::Exceptions::Ensure::Always +namespace Platform::Exceptions::Contract::Always { void ArgumentNotNull(auto argument, const std::string& argumentName, const std::string& message) requires std::is_pointer_v || std::is_null_pointer_v @@ -47,7 +47,7 @@ } } -namespace Platform::Exceptions::Ensure::OnDebug +namespace Platform::Exceptions::Contract::OnDebug { #ifdef NDEBUG #define NDEBUG_CONSTEVAL consteval diff --git a/cpp/Platform.Exceptions/ExtensionRoots/EnsureAlwaysExtensionRoot.h b/cpp/Platform.Exceptions/ExtensionRoots/ContractAlwaysExtensionRoot.h similarity index 100% rename from cpp/Platform.Exceptions/ExtensionRoots/EnsureAlwaysExtensionRoot.h rename to cpp/Platform.Exceptions/ExtensionRoots/ContractAlwaysExtensionRoot.h diff --git a/cpp/Platform.Exceptions/ExtensionRoots/EnsureOnDebugExtensionRoot.h b/cpp/Platform.Exceptions/ExtensionRoots/ContractOnDebugExtensionRoot.h similarity index 100% rename from cpp/Platform.Exceptions/ExtensionRoots/EnsureOnDebugExtensionRoot.h rename to cpp/Platform.Exceptions/ExtensionRoots/ContractOnDebugExtensionRoot.h diff --git a/csharp/Platform.Exceptions.Tests/EnsuranceTests.cs b/csharp/Platform.Exceptions.Tests/ContractTests.cs similarity index 54% rename from csharp/Platform.Exceptions.Tests/EnsuranceTests.cs rename to csharp/Platform.Exceptions.Tests/ContractTests.cs index 2bb4881..8b1e213 100644 --- a/csharp/Platform.Exceptions.Tests/EnsuranceTests.cs +++ b/csharp/Platform.Exceptions.Tests/ContractTests.cs @@ -3,13 +3,13 @@ namespace Platform.Exceptions.Tests { - public static class EnsuranceTests + public static class ContractTests { [Fact] - public static void ArgumentNotNullEnsuranceTest() + public static void ArgumentNotNullContractTest() { // Should throw an exception (even if in neighbour "Ignore" namespace it was overridden, but here this namespace is not used) - Assert.Throws(() => Ensure.Always.ArgumentNotNull(null, "object")); + Assert.Throws(() => Contract.Always.ArgumentNotNull(null, "object")); } } } diff --git a/csharp/Platform.Exceptions.Tests/Ignore/EnsureExtensions.cs b/csharp/Platform.Exceptions.Tests/Ignore/ContractExtensions.cs similarity index 51% rename from csharp/Platform.Exceptions.Tests/Ignore/EnsureExtensions.cs rename to csharp/Platform.Exceptions.Tests/Ignore/ContractExtensions.cs index 676a1c2..4048004 100644 --- a/csharp/Platform.Exceptions.Tests/Ignore/EnsureExtensions.cs +++ b/csharp/Platform.Exceptions.Tests/Ignore/ContractExtensions.cs @@ -3,13 +3,13 @@ namespace Platform.Exceptions.Tests.Ignore { - public static class EnsureExtensions + public static class ContractExtensions { [Conditional("DEBUG")] - public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot root, TArgument argument, string argumentName) + public static void ArgumentNotNull(this ContractAlwaysExtensionRoot root, TArgument argument, string argumentName) where TArgument : class { - // Override logic to do nothing (this should be used to reduce the overhead of the Ensure checks, when it is critical to performance) + // Override logic to do nothing (this should be used to reduce the overhead of the Contract checks, when it is critical to performance) } } } diff --git a/csharp/Platform.Exceptions.Tests/Ignore/IgnoredEnsuranceTests.cs b/csharp/Platform.Exceptions.Tests/Ignore/IgnoredContractTests.cs similarity index 62% rename from csharp/Platform.Exceptions.Tests/Ignore/IgnoredEnsuranceTests.cs rename to csharp/Platform.Exceptions.Tests/Ignore/IgnoredContractTests.cs index ed12efa..62acc62 100644 --- a/csharp/Platform.Exceptions.Tests/Ignore/IgnoredEnsuranceTests.cs +++ b/csharp/Platform.Exceptions.Tests/Ignore/IgnoredContractTests.cs @@ -2,15 +2,15 @@ namespace Platform.Exceptions.Tests.Ignore { - public static class IgnoredEnsuranceTests + public static class IgnoredContractTests { [Fact] - public static void EnsuranceIgnoredTest() + public static void ContractIgnoredTest() { - // Should not throw an exception (because logic is overriden in EnsureAlwaysExtensions that is located within the same namespace) + // Should not throw an exception (because logic is overriden in ContractAlwaysExtensions that is located within the same namespace) // And even should be optimized out at RELEASE (because method is now marked conditional DEBUG) // This can be useful in performance critical situations there even an check for exception is hurting performance enough - Ensure.Always.ArgumentNotNull(null, "object"); + Contract.Always.ArgumentNotNull(null, "object"); } } } diff --git a/csharp/Platform.Exceptions/Ensure.cs b/csharp/Platform.Exceptions/Contract.cs similarity index 87% rename from csharp/Platform.Exceptions/Ensure.cs rename to csharp/Platform.Exceptions/Contract.cs index 295e1fe..6969a46 100644 --- a/csharp/Platform.Exceptions/Ensure.cs +++ b/csharp/Platform.Exceptions/Contract.cs @@ -6,18 +6,18 @@ namespace Platform.Exceptions /// Contains two extensible classes instances that can be supplemented with static helper methods by using the extension mechanism. These methods ensure the contract compliance. /// Содержит два экземпляра расширяемых класса, которые можно дополнять статическими вспомогательными методами путём использования механизма расширений. Эти методы занимаются гарантированием соответствия контракту. /// - public static class Ensure + public static class Contract { /// /// Gets an instance of the extension root class that contains helper methods to guarantee compliance with the contract. /// Возвращает экземпляр класса корня-расширения, который содержит вспомогательные методы для гарантирования соответствия контракту. /// - public static readonly EnsureAlwaysExtensionRoot Always = new EnsureAlwaysExtensionRoot(); + public static readonly ContractAlwaysExtensionRoot Always = new ContractAlwaysExtensionRoot(); /// /// Gets an instance of the extension root class that contains helper methods to guarantee compliance with the contract, but are executed only during debugging. /// Возвращает экземпляр класса корня-расширения, который содержит вспомогательные методы для гарантирования соответствия контракту, но выполняются только во время отладки. /// - public static readonly EnsureOnDebugExtensionRoot OnDebug = new EnsureOnDebugExtensionRoot(); + public static readonly ContractOnDebugExtensionRoot OnDebug = new ContractOnDebugExtensionRoot(); } } diff --git a/csharp/Platform.Exceptions/EnsureExtensions.cs b/csharp/Platform.Exceptions/ContractExtensions.cs similarity index 85% rename from csharp/Platform.Exceptions/EnsureExtensions.cs rename to csharp/Platform.Exceptions/ContractExtensions.cs index 83501a6..46984ba 100644 --- a/csharp/Platform.Exceptions/EnsureExtensions.cs +++ b/csharp/Platform.Exceptions/ContractExtensions.cs @@ -8,10 +8,10 @@ namespace Platform.Exceptions { /// - /// Provides a set of extension methods for and objects. - /// Предоставляет набор методов расширения для объектов и . + /// Provides a set of extension methods for and objects. + /// Предоставляет набор методов расширения для объектов и . /// - public static class EnsureExtensions + public static class ContractExtensions { #region Always @@ -25,7 +25,7 @@ public static class EnsureExtensions /// The argument's name.Имя аргумента. /// The message of the thrown exception.Сообщение выбрасываемого исключения. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot root, TArgument argument, string argumentName, string message) + public static void ArgumentNotNull(this ContractAlwaysExtensionRoot root, TArgument argument, string argumentName, string message) where TArgument : class { if (argument == null) @@ -43,7 +43,7 @@ public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot roo /// The argument.Аргумент. /// The argument's name.Имя аргумента. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot root, TArgument argument, string argumentName) where TArgument : class => ArgumentNotNull(root, argument, argumentName, $"Argument {argumentName} is null."); + public static void ArgumentNotNull(this ContractAlwaysExtensionRoot root, TArgument argument, string argumentName) where TArgument : class => ArgumentNotNull(root, argument, argumentName, $"Argument {argumentName} is null."); /// /// Ensures that argument is not null. This check is performed regardless of the build configuration. @@ -53,7 +53,7 @@ public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot roo /// The extension root to which this method is bound.Корень-расширения, к которому привязан этот метод. /// The argument.Аргумент. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot root, TArgument argument) where TArgument : class => ArgumentNotNull(root, argument, null); + public static void ArgumentNotNull(this ContractAlwaysExtensionRoot root, TArgument argument) where TArgument : class => ArgumentNotNull(root, argument, null); /// /// Ensures that the argument meets the criteria. This check is performed regardless of the build configuration. @@ -66,7 +66,7 @@ public static void ArgumentNotNull(this EnsureAlwaysExtensionRoot roo /// The argument's name.Имя аргумента. /// The message of the thrown exception.Сообщение выбрасываемого исключения. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRoot root, TArgument argument, Predicate predicate, string argumentName, string message) + public static void ArgumentMeetsCriteria(this ContractAlwaysExtensionRoot root, TArgument argument, Predicate predicate, string argumentName, string message) { if (!predicate(argument)) { @@ -84,7 +84,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// A predicate that determines whether the argument meets a criterion.Предикат определяющий, соответствует ли аргумент критерию. /// The argument's name.Имя аргумента. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRoot root, TArgument argument, Predicate predicate, string argumentName) => ArgumentMeetsCriteria(root, argument, predicate, argumentName, $"Argument {argumentName} does not meet the criteria."); + public static void ArgumentMeetsCriteria(this ContractAlwaysExtensionRoot root, TArgument argument, Predicate predicate, string argumentName) => ArgumentMeetsCriteria(root, argument, predicate, argumentName, $"Argument {argumentName} does not meet the criteria."); /// /// Ensures that the argument meets the criteria. This check is performed regardless of the build configuration. @@ -95,7 +95,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// The argument.Аргумент. /// A predicate that determines whether the argument meets a criterion.Предикат определяющий, соответствует ли аргумент критерию. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRoot root, TArgument argument, Predicate predicate) => ArgumentMeetsCriteria(root, argument, predicate, null); + public static void ArgumentMeetsCriteria(this ContractAlwaysExtensionRoot root, TArgument argument, Predicate predicate) => ArgumentMeetsCriteria(root, argument, predicate, null); #endregion @@ -111,7 +111,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// The argument's name.Имя аргумента. /// The message of the thrown exception.Сообщение выбрасываемого исключения. [Conditional("DEBUG")] - public static void ArgumentNotNull(this EnsureOnDebugExtensionRoot root, TArgument argument, string argumentName, string message) where TArgument : class => Ensure.Always.ArgumentNotNull(argument, argumentName, message); + public static void ArgumentNotNull(this ContractOnDebugExtensionRoot root, TArgument argument, string argumentName, string message) where TArgument : class => Contract.Always.ArgumentNotNull(argument, argumentName, message); /// /// Ensures that argument is not null. This check is performed only for DEBUG build configuration. @@ -122,7 +122,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// The argument.Аргумент. /// The argument's name.Имя аргумента. [Conditional("DEBUG")] - public static void ArgumentNotNull(this EnsureOnDebugExtensionRoot root, TArgument argument, string argumentName) where TArgument : class => Ensure.Always.ArgumentNotNull(argument, argumentName); + public static void ArgumentNotNull(this ContractOnDebugExtensionRoot root, TArgument argument, string argumentName) where TArgument : class => Contract.Always.ArgumentNotNull(argument, argumentName); /// /// Ensures that argument is not null. This check is performed only for DEBUG build configuration. @@ -132,7 +132,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// The extension root to which this method is bound.Корень-расширения, к которому привязан этот метод. /// The argument.Аргумент. [Conditional("DEBUG")] - public static void ArgumentNotNull(this EnsureOnDebugExtensionRoot root, TArgument argument) where TArgument : class => Ensure.Always.ArgumentNotNull(argument); + public static void ArgumentNotNull(this ContractOnDebugExtensionRoot root, TArgument argument) where TArgument : class => Contract.Always.ArgumentNotNull(argument); /// /// Ensures that the argument meets the criteria. This check is performed only for DEBUG build configuration. @@ -145,7 +145,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// The argument's name.Имя аргумента. /// The message of the thrown exception.Сообщение выбрасываемого исключения. [Conditional("DEBUG")] - public static void ArgumentMeetsCriteria(this EnsureOnDebugExtensionRoot root, TArgument argument, Predicate predicate, string argumentName, string message) => Ensure.Always.ArgumentMeetsCriteria(argument, predicate, argumentName, message); + public static void ArgumentMeetsCriteria(this ContractOnDebugExtensionRoot root, TArgument argument, Predicate predicate, string argumentName, string message) => Contract.Always.ArgumentMeetsCriteria(argument, predicate, argumentName, message); /// /// Ensures that the argument meets the criteria. This check is performed only for DEBUG build configuration. @@ -157,7 +157,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// A predicate that determines whether the argument meets a criterion.Предикат определяющий, соответствует ли аргумент критерию. /// The argument's name.Имя аргумента. [Conditional("DEBUG")] - public static void ArgumentMeetsCriteria(this EnsureOnDebugExtensionRoot root, TArgument argument, Predicate predicate, string argumentName) => Ensure.Always.ArgumentMeetsCriteria(argument, predicate, argumentName); + public static void ArgumentMeetsCriteria(this ContractOnDebugExtensionRoot root, TArgument argument, Predicate predicate, string argumentName) => Contract.Always.ArgumentMeetsCriteria(argument, predicate, argumentName); /// /// Ensures that the argument meets the criteria. This check is performed only for DEBUG build configuration. @@ -168,7 +168,7 @@ public static void ArgumentMeetsCriteria(this EnsureAlwaysExtensionRo /// The argument.Аргумент. /// A predicate that determines whether the argument meets a criterion.Предикат определяющий, соответствует ли аргумент критерию. [Conditional("DEBUG")] - public static void ArgumentMeetsCriteria(this EnsureOnDebugExtensionRoot root, TArgument argument, Predicate predicate) => Ensure.Always.ArgumentMeetsCriteria(argument, predicate); + public static void ArgumentMeetsCriteria(this ContractOnDebugExtensionRoot root, TArgument argument, Predicate predicate) => Contract.Always.ArgumentMeetsCriteria(argument, predicate); #endregion } diff --git a/csharp/Platform.Exceptions/ExtensionRoots/ContractAlwaysExtensionRoot.cs b/csharp/Platform.Exceptions/ExtensionRoots/ContractAlwaysExtensionRoot.cs new file mode 100644 index 0000000..ad342e9 --- /dev/null +++ b/csharp/Platform.Exceptions/ExtensionRoots/ContractAlwaysExtensionRoot.cs @@ -0,0 +1,10 @@ +namespace Platform.Exceptions.ExtensionRoots +{ + /// + /// Represents the extension root class for Contract.Always. + /// Представляет класс корень-расширения для Contract.Always. + /// + public class ContractAlwaysExtensionRoot + { + } +} diff --git a/csharp/Platform.Exceptions/ExtensionRoots/ContractOnDebugExtensionRoot.cs b/csharp/Platform.Exceptions/ExtensionRoots/ContractOnDebugExtensionRoot.cs new file mode 100644 index 0000000..1e5a979 --- /dev/null +++ b/csharp/Platform.Exceptions/ExtensionRoots/ContractOnDebugExtensionRoot.cs @@ -0,0 +1,10 @@ +namespace Platform.Exceptions.ExtensionRoots +{ + /// + /// Represents the extension root class for Contract.OnDebug. + /// Представляет класс корень-расширения для Contract.OnDebug. + /// + public class ContractOnDebugExtensionRoot + { + } +} diff --git a/csharp/Platform.Exceptions/ExtensionRoots/EnsureAlwaysExtensionRoot.cs b/csharp/Platform.Exceptions/ExtensionRoots/EnsureAlwaysExtensionRoot.cs deleted file mode 100644 index fa2ddcd..0000000 --- a/csharp/Platform.Exceptions/ExtensionRoots/EnsureAlwaysExtensionRoot.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Platform.Exceptions.ExtensionRoots -{ - /// - /// Represents the extension root class for Ensure.Always. - /// Представляет класс корень-расширения для Ensure.Always. - /// - public class EnsureAlwaysExtensionRoot - { - } -} diff --git a/csharp/Platform.Exceptions/ExtensionRoots/EnsureOnDebugExtensionRoot.cs b/csharp/Platform.Exceptions/ExtensionRoots/EnsureOnDebugExtensionRoot.cs deleted file mode 100644 index 73dabae..0000000 --- a/csharp/Platform.Exceptions/ExtensionRoots/EnsureOnDebugExtensionRoot.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Platform.Exceptions.ExtensionRoots -{ - /// - /// Represents the extension root class for Ensure.OnDebug. - /// Представляет класс корень-расширения для Ensure.OnDebug. - /// - public class EnsureOnDebugExtensionRoot - { - } -}