diff --git a/Source/Testably.Expectations/Core/Ambient/Initialization.cs b/Source/Testably.Expectations/Core/Ambient/Initialization.cs index 80944120..718ac2f0 100644 --- a/Source/Testably.Expectations/Core/Ambient/Initialization.cs +++ b/Source/Testably.Expectations/Core/Ambient/Initialization.cs @@ -57,7 +57,7 @@ public InitializationState(ITestFrameworkAdapter testFramework) public void Throw(string message) => _testFramework.Throw(message); } - private class FallbackTestFramework : ITestFrameworkAdapter + private sealed class FallbackTestFramework : ITestFrameworkAdapter { #region ITestFrameworkAdapter Members diff --git a/Source/Testably.Expectations/Core/ExpectationBuilders/WhichExpectationBuilder.cs b/Source/Testably.Expectations/Core/ExpectationBuilders/WhichExpectationBuilder.cs index 14c98d93..3d619221 100644 --- a/Source/Testably.Expectations/Core/ExpectationBuilders/WhichExpectationBuilder.cs +++ b/Source/Testably.Expectations/Core/ExpectationBuilders/WhichExpectationBuilder.cs @@ -57,7 +57,7 @@ public ExpectationResult ApplyTo(TExpectation actual) public static object? GetPropertyValue(object? obj, string propertyPath) { - if (propertyPath.IndexOf(".", StringComparison.Ordinal) < 0) + if (propertyPath.IndexOf('.', StringComparison.Ordinal) < 0) { Type? objType = obj?.GetType(); return objType?.GetProperty(propertyPath)?.GetValue(obj, null); diff --git a/Source/Testably.Expectations/Core/ShouldVerb.cs b/Source/Testably.Expectations/Core/ShouldVerb.cs index 10d8b4f0..a9059a5f 100644 --- a/Source/Testably.Expectations/Core/ShouldVerb.cs +++ b/Source/Testably.Expectations/Core/ShouldVerb.cs @@ -11,7 +11,7 @@ public abstract class ShouldVerb { private readonly IExpectationBuilderStart _expectationBuilder; - internal ShouldVerb(IExpectationBuilderStart expectationBuilder) + private protected ShouldVerb(IExpectationBuilderStart expectationBuilder) { _expectationBuilder = expectationBuilder; } @@ -40,17 +40,17 @@ public ExpectationWhichShould WithExpectation( #pragma warning disable CS0809 /// - [Obsolete] + [Obsolete("Equals is not part of Testably.Expectations.")] [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object? obj) - => throw new NotSupportedException( - "Equals is not part of Testably.Expectations."); + // ReSharper disable once BaseObjectEqualsIsObjectEquals + => base.Equals(obj); /// - [Obsolete] + [Obsolete("Equals is not part of Testably.Expectations.")] [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() - => throw new NotSupportedException( - "Equals is not part of Testably.Expectations."); - #pragma warning restore CS0809 + // ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode + => base.GetHashCode(); +#pragma warning restore CS0809 } diff --git a/Source/Testably.Expectations/Polyfill/CallerArgumentExpressionAttribute.cs b/Source/Testably.Expectations/Polyfills/CallerArgumentExpressionAttribute.cs similarity index 100% rename from Source/Testably.Expectations/Polyfill/CallerArgumentExpressionAttribute.cs rename to Source/Testably.Expectations/Polyfills/CallerArgumentExpressionAttribute.cs diff --git a/Source/Testably.Expectations/Polyfill/StackTraceHiddenAttribute.cs b/Source/Testably.Expectations/Polyfills/StackTraceHiddenAttribute.cs similarity index 100% rename from Source/Testably.Expectations/Polyfill/StackTraceHiddenAttribute.cs rename to Source/Testably.Expectations/Polyfills/StackTraceHiddenAttribute.cs diff --git a/Source/Testably.Expectations/Polyfills/StringExtensions.cs b/Source/Testably.Expectations/Polyfills/StringExtensions.cs new file mode 100644 index 00000000..7f8c193b --- /dev/null +++ b/Source/Testably.Expectations/Polyfills/StringExtensions.cs @@ -0,0 +1,28 @@ +#if NETSTANDARD2_0 +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Testably.Expectations.Polyfills; + +/// +/// Provides extension methods to simplify writing platform independent tests. +/// +[ExcludeFromCodeCoverage] +internal static class StringExtensionMethods +{ + /// + /// Reports the zero-based index of the first occurrence of the specified Unicode character in this string. A parameter + /// specifies the type of search to use for the specified character. + /// + /// + /// The zero-based index of if that character is found, or -1 if it is not. + /// + internal static int IndexOf( + this string @this, + char value, + StringComparison comparisonType) + { + return @this.IndexOf($"{value}", comparisonType); + } +} +#endif diff --git a/Source/Testably.Expectations/Usings.cs b/Source/Testably.Expectations/Usings.cs new file mode 100644 index 00000000..7232f236 --- /dev/null +++ b/Source/Testably.Expectations/Usings.cs @@ -0,0 +1,3 @@ +#if NETSTANDARD2_0 || NETSTANDARD2_1 +global using Testably.Expectations.Polyfills; +#endif