From 35f2d0745c610858cce4286b4a67d726b11f8c1b Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 27 Dec 2024 14:31:53 +0100 Subject: [PATCH 01/46] Add interpolated string handler overloads for Assert.IsTrue/IsFalse --- .../TestFramework/Assertions/Assert.IsTrue.cs | 90 +++++++++++++++++++ .../PublicAPI/PublicAPI.Unshipped.txt | 16 ++++ 2 files changed, 106 insertions(+) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 62e96b5470..e18ed059fc 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.ComponentModel; + namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -10,6 +12,58 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertIsTrueInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) + { + shouldAppend = condition is false or null; + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertIsFalseInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) + { + shouldAppend = condition is true or null; + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + /// /// Tests whether the specified condition is true and throws an exception /// if the condition is false. @@ -53,6 +107,15 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition) public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? message) => IsTrue(condition, message, null); + /// + public static void IsTrue([DoesNotReturnIf(false)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) + { + if (!condition) + { + ThrowAssertFailed("Assert.IsTrue", message.ToStringAndClear()); + } + } + /// /// Tests whether the specified condition is true and throws an exception /// if the condition is false. @@ -70,6 +133,15 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? messa public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? message) => IsTrue(condition, message, null); + /// + public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) + { + if (condition is false or null) + { + ThrowAssertFailed("Assert.IsTrue", message.ToStringAndClear()); + } + } + /// /// Tests whether the specified condition is true and throws an exception /// if the condition is false. @@ -165,6 +237,15 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition) public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? message) => IsFalse(condition, message, null); + /// + public static void IsFalse([DoesNotReturnIf(true)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) + { + if (condition) + { + ThrowAssertFailed("Assert.IsFalse", message.ToStringAndClear()); + } + } + /// /// Tests whether the specified condition is false and throws an exception /// if the condition is true. @@ -182,6 +263,15 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? messa public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? message) => IsFalse(condition, message, null); + /// + public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) + { + if (condition is true or null) + { + ThrowAssertFailed("Assert.IsFalse", message.ToStringAndClear()); + } + } + /// /// Tests whether the specified condition is false and throws an exception /// if the condition is true. diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 3ceaf8e88e..ba274639d4 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,4 +1,16 @@ #nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType) -> void @@ -6,6 +18,10 @@ Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAtt Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.AutoDetect = 2 -> Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! From 13d599fa81c1b0b50bae972739a89a94a4d79ebd Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 27 Dec 2024 14:38:00 +0100 Subject: [PATCH 02/46] Add interpolated string handler overloads for Assert.IsNull/IsNotNull --- .../TestFramework/Assertions/Assert.IsNull.cs | 72 +++++++++++++++++++ .../PublicAPI/PublicAPI.Unshipped.txt | 14 ++++ 2 files changed, 86 insertions(+) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 96df80dd1d..57399e95a0 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.ComponentModel; + namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -10,6 +12,58 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertIsNullInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) + { + shouldAppend = value is not null; + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertIsNotNullInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertIsNotNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) + { + shouldAppend = value is null; + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + /// /// Tests whether the specified object is null and throws an exception /// if it is not. @@ -40,6 +94,15 @@ public static void IsNull(object? value) public static void IsNull(object? value, string? message) => IsNull(value, message, null); + /// + public static void IsNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNullInterpolatedStringHandler message) + { + if (value is not null) + { + ThrowAssertFailed("Assert.IsNull", message.ToStringAndClear()); + } + } + /// /// Tests whether the specified object is null and throws an exception /// if it is not. @@ -95,6 +158,15 @@ public static void IsNotNull([NotNull] object? value) public static void IsNotNull([NotNull] object? value, string? message) => IsNotNull(value, message, null); + /// + public static void IsNotNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) + { + if (value is null) + { + ThrowAssertFailed("Assert.IsNotNull", message.ToStringAndClear()); + } + } + /// /// Tests whether the specified object is non-null and throws an exception /// if it is null. diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index ba274639d4..4df009b168 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -5,6 +5,18 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStr Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value) -> void @@ -20,6 +32,8 @@ Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.AutoDetect = *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! From 7cbafc10b6f0703c7969c90e1d9e61da99c7660d Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 27 Dec 2024 15:03:10 +0100 Subject: [PATCH 03/46] Refactor --- .../TestFramework/Assertions/Assert.IsNull.cs | 24 +++++++--- .../TestFramework/Assertions/Assert.IsTrue.cs | 45 ++++++++++++++----- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 57399e95a0..d070464376 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -20,13 +20,15 @@ public readonly struct AssertIsNullInterpolatedStringHandler public AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) { - shouldAppend = value is not null; + shouldAppend = IsNullFailing(value); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); } } + internal bool ShouldAppend => _builder is not null; + internal readonly string ToStringAndClear() => _builder!.ToString(); public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -46,13 +48,15 @@ public readonly struct AssertIsNotNullInterpolatedStringHandler public AssertIsNotNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) { - shouldAppend = value is null; + shouldAppend = IsNotNullFailing(value); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); } } + internal bool ShouldAppend => _builder is not null; + internal readonly string ToStringAndClear() => _builder!.ToString(); public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -95,9 +99,11 @@ public static void IsNull(object? value, string? message) => IsNull(value, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The value parameter is used via the interpolated string handler. public static void IsNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNullInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter { - if (value is not null) + if (message.ShouldAppend) { ThrowAssertFailed("Assert.IsNull", message.ToStringAndClear()); } @@ -122,12 +128,14 @@ public static void IsNull(object? value, [InterpolatedStringHandlerArgument(name /// public static void IsNull(object? value, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (value != null) + if (IsNullFailing(value)) { ThrowAssertFailed("Assert.IsNull", BuildUserMessage(message, parameters)); } } + private static bool IsNullFailing(object? value) => value is not null; + /// /// Tests whether the specified object is non-null and throws an exception /// if it is null. @@ -159,9 +167,11 @@ public static void IsNotNull([NotNull] object? value, string? message) => IsNotNull(value, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The value parameter is used via the interpolated string handler. public static void IsNotNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter { - if (value is null) + if (message.ShouldAppend) { ThrowAssertFailed("Assert.IsNotNull", message.ToStringAndClear()); } @@ -186,9 +196,11 @@ public static void IsNotNull(object? value, [InterpolatedStringHandlerArgument(n /// public static void IsNotNull([NotNull] object? value, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (value == null) + if (IsNotNullFailing(value)) { ThrowAssertFailed("Assert.IsNotNull", BuildUserMessage(message, parameters)); } } + + private static bool IsNotNullFailing([NotNullWhen(false)] object? value) => value is null; } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index e18ed059fc..04fdd615ba 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -20,13 +20,15 @@ public readonly struct AssertIsTrueInterpolatedStringHandler public AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) { - shouldAppend = condition is false or null; + shouldAppend = IsTrueFailing(condition); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); } } + internal bool ShouldAppend => _builder is not null; + internal readonly string ToStringAndClear() => _builder!.ToString(); public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -46,13 +48,15 @@ public readonly struct AssertIsFalseInterpolatedStringHandler public AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) { - shouldAppend = condition is true or null; + shouldAppend = IsFalseFailing(condition); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); } } + internal bool ShouldAppend => _builder is not null; + internal readonly string ToStringAndClear() => _builder!.ToString(); public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -108,9 +112,11 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? messa => IsTrue(condition, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsTrue([DoesNotReturnIf(false)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter { - if (!condition) + if (message.ShouldAppend) { ThrowAssertFailed("Assert.IsTrue", message.ToStringAndClear()); } @@ -134,9 +140,11 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? mess => IsTrue(condition, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter { - if (condition is false or null) + if (message.ShouldAppend) { ThrowAssertFailed("Assert.IsTrue", message.ToStringAndClear()); } @@ -162,7 +170,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [Interpolate public static void IsTrue([DoesNotReturnIf(false)] bool condition, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (!condition) + if (IsTrueFailing(condition)) { ThrowAssertFailed("Assert.IsTrue", BuildUserMessage(message, parameters)); } @@ -188,12 +196,18 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, [StringSyntax public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (condition is false or null) + if (IsTrueFailing(condition)) { ThrowAssertFailed("Assert.IsTrue", BuildUserMessage(message, parameters)); } } + private static bool IsTrueFailing(bool? condition) + => condition is false or null; + + private static bool IsTrueFailing(bool condition) + => !condition; + /// /// Tests whether the specified condition is false and throws an exception /// if the condition is true. @@ -238,9 +252,11 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? messa => IsFalse(condition, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsFalse([DoesNotReturnIf(true)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter { - if (condition) + if (message.ShouldAppend) { ThrowAssertFailed("Assert.IsFalse", message.ToStringAndClear()); } @@ -264,9 +280,11 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? mess => IsFalse(condition, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter { - if (condition is true or null) + if (message.ShouldAppend) { ThrowAssertFailed("Assert.IsFalse", message.ToStringAndClear()); } @@ -292,7 +310,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [Interpolate public static void IsFalse([DoesNotReturnIf(true)] bool condition, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (condition) + if (IsFalseFailing(condition)) { ThrowAssertFailed("Assert.IsFalse", BuildUserMessage(message, parameters)); } @@ -318,9 +336,16 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, [StringSyntax public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (condition is true or null) + if (IsFalseFailing(condition)) { ThrowAssertFailed("Assert.IsFalse", BuildUserMessage(message, parameters)); } } + + private static bool IsFalseFailing(bool? condition) + => condition is true or null; + + private static bool IsFalseFailing(bool condition) + => condition; + } From 94084b11f1b71a7457c083d842fcf27b61cecc42 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 27 Dec 2024 16:06:47 +0100 Subject: [PATCH 04/46] Assert.AreEqual/AreNotEqual [WIP] --- .../Assertions/Assert.AreEqual.cs | 307 ++++++++++++++++-- .../PublicAPI/PublicAPI.Unshipped.txt | 30 ++ 2 files changed, 301 insertions(+), 36 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 2079f60160..52d5e42db3 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.ComponentModel; + namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -10,6 +12,89 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertAreEqualInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, IEqualityComparer? comparer, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual, comparer); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, IEquatable? expected, IEquatable? actual, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal bool ShouldAppend => _builder is not null; + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertAreNotEqualInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(notExpected, actual); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, IEqualityComparer? comparer, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(notExpected, actual, comparer); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal bool ShouldAppend => _builder is not null; + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. @@ -80,6 +165,15 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com public static void AreEqual(T? expected, T? actual, string? message) => AreEqual(expected, actual, null, message, null); + /// + public static void AreEqual(T? expected, T? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + ThrowAssertFailed("Assert.AreEqual", GetAreEqualFinalMessage(expected, actual, message.ToStringAndClear())); + } + } + /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. @@ -110,6 +204,17 @@ public static void AreEqual(T? expected, T? actual, string? message) public static void AreEqual(T? expected, T? actual, IEqualityComparer? comparer, string? message) => AreEqual(expected, actual, comparer, message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The comparer parameter is used via the interpolated string handler. + public static void AreEqual(T? expected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(comparer))] ref AssertAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + { + if (message.ShouldAppend) + { + ThrowAssertFailed("Assert.AreEqual", GetAreEqualFinalMessage(expected, actual, message.ToStringAndClear())); + } + } + /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. @@ -172,14 +277,19 @@ public static void AreEqual(T? expected, T? actual, [StringSyntax(StringSynta public static void AreEqual(T? expected, T? actual, IEqualityComparer? comparer, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - IEqualityComparer localComparer = comparer ?? EqualityComparer.Default; - if (localComparer.Equals(expected!, actual!)) + if (!AreEqualFailing(expected, actual, comparer)) { return; } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) + string finalMessage = GetAreEqualFinalMessage(expected, actual, userMessage); + + ThrowAssertFailed("Assert.AreEqual", finalMessage); + } + + private static string GetAreEqualFinalMessage(object? expected, object? actual, string userMessage) + => actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) ? string.Format( CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDifferentTypesFailMsg, @@ -195,9 +305,6 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com ReplaceNulls(expected), ReplaceNulls(actual)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); - } - /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. @@ -244,6 +351,15 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual) public static void AreEqual(IEquatable? expected, IEquatable? actual, string? message) => AreEqual(expected, actual, message, null); + /// + public static void AreEqual(IEquatable? expected, IEquatable? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + ThrowAssertFailed("Assert.AreEqual", GetAreEqualFinalMessage(expected, actual, message.ToStringAndClear())); + } + } + /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. @@ -272,36 +388,26 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, s /// public static void AreEqual(IEquatable? expected, IEquatable? actual, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (actual is null && expected is null) - { - return; - } - - if (actual?.Equals(expected) == true) + if (!AreEqualFailing(expected, actual)) { return; } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) - ? string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDifferentTypesFailMsg, - userMessage, - ReplaceNulls(expected), - expected.GetType().FullName, - ReplaceNulls(actual), - actual.GetType().FullName) - : string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); + string finalMessage = GetAreEqualFinalMessage(expected, actual, userMessage); ThrowAssertFailed("Assert.AreEqual", finalMessage); } + private static bool AreEqualFailing(T? expected, T? actual) + => AreEqualFailing(expected, actual, null); + + private static bool AreEqualFailing(T? expected, T? actual, IEqualityComparer? comparer) + => !(comparer ?? EqualityComparer.Default).Equals(expected!, actual!); + + private static bool AreEqualFailing(IEquatable? expected, IEquatable? actual) + => (actual is not null || expected is not null) && actual?.Equals(expected) != true; + /// /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. @@ -374,6 +480,15 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer(T? notExpected, T? actual, string? message) => AreNotEqual(notExpected, actual, null, message, null); + /// + public static void AreNotEqual(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] ref AssertAreNotEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + ThrowAssertFailed("Assert.AreNotEqual", GetAreNotEqualFinalMessage(notExpected, actual, message.ToStringAndClear())); + } + } + /// /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. @@ -404,6 +519,17 @@ public static void AreNotEqual(T? notExpected, T? actual, string? message) public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer? comparer, string? message) => AreNotEqual(notExpected, actual, comparer, message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - false positive. The comparer parameter is used via the interpolated string handler. + public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(comparer))] ref AssertAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + { + if (message.ShouldAppend) + { + ThrowAssertFailed("Assert.AreNotEqual", GetAreNotEqualFinalMessage(notExpected, actual, message.ToStringAndClear())); + } + } + /// /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. @@ -473,12 +599,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer AreEqual(expected, actual, delta, message, null); + /// + public static void AreEqual(float expected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler? message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified floats are equal and throws an exception /// if they are not equal. @@ -625,6 +755,14 @@ public static void AreNotEqual(float notExpected, float actual, float delta) public static void AreNotEqual(float notExpected, float actual, float delta, string? message) => AreNotEqual(notExpected, actual, delta, message, null); + public static void AreNotEqual(float notExpected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified floats are unequal and throws an exception /// if they are equal. @@ -718,6 +856,15 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta) public static void AreEqual(decimal expected, decimal actual, decimal delta, string? message) => AreEqual(expected, actual, delta, message, null); + /// + public static void AreEqual(decimal expected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified decimals are equal and throws an exception /// if they are not equal. @@ -811,6 +958,15 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt public static void AreNotEqual(decimal notExpected, decimal actual, decimal delta, string? message) => AreNotEqual(notExpected, actual, delta, message, null); + /// + public static void AreNotEqual(decimal notExpected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified decimals are unequal and throws an exception /// if they are equal. @@ -904,6 +1060,15 @@ public static void AreEqual(long expected, long actual, long delta) public static void AreEqual(long expected, long actual, long delta, string? message) => AreEqual(expected, actual, delta, message, null); + /// + public static void AreEqual(long expected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified longs are equal and throws an exception /// if they are not equal. @@ -997,6 +1162,15 @@ public static void AreNotEqual(long notExpected, long actual, long delta) public static void AreNotEqual(long notExpected, long actual, long delta, string? message) => AreNotEqual(notExpected, actual, delta, message, null); + /// + public static void AreNotEqual(long notExpected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified longs are unequal and throws an exception /// if they are equal. @@ -1089,6 +1263,15 @@ public static void AreEqual(double expected, double actual, double delta) public static void AreEqual(double expected, double actual, double delta, string? message) => AreEqual(expected, actual, delta, message, null); + /// + public static void AreEqual(double expected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified doubles are equal and throws an exception /// if they are not equal. @@ -1182,6 +1365,15 @@ public static void AreNotEqual(double notExpected, double actual, double delta) public static void AreNotEqual(double notExpected, double actual, double delta, string? message) => AreNotEqual(notExpected, actual, delta, message, null); + /// + public static void AreNotEqual(double notExpected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified doubles are unequal and throws an exception /// if they are equal. @@ -1271,6 +1463,15 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase) public static void AreEqual(string? expected, string? actual, bool ignoreCase, string? message) => AreEqual(expected, actual, ignoreCase, message, null); + /// + public static void AreEqual(string? expected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified strings are equal and throws an exception /// if they are not equal. The invariant culture is used for the comparison. @@ -1353,6 +1554,17 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, string? message) => AreEqual(expected, actual, ignoreCase, culture, message, null); + /// + public static void AreEqual(string? expected, string? actual, bool ignoreCase, + [NotNull] CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) + { + CheckParameterNotNull(culture, "Assert.AreEqual", nameof(culture), string.Empty); + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified strings are equal and throws an exception /// if they are not equal. @@ -1456,6 +1668,15 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, string? message) => AreNotEqual(notExpected, actual, ignoreCase, message, null); + /// + public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) + { + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified strings are unequal and throws an exception /// if they are equal. The invariant culture is used for the comparison. @@ -1540,6 +1761,17 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC CultureInfo? culture, string? message) => AreNotEqual(notExpected, actual, ignoreCase, culture, message, null); + /// + public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, + CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) + { + CheckParameterNotNull(culture, "Assert.AreEqual", nameof(culture), string.Empty); + if (message.ShouldAppend) + { + // TODO: + } + } + /// /// Tests whether the specified strings are unequal and throws an exception /// if they are equal. @@ -1579,12 +1811,15 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( + string finalMessage = GetAreNotEqualFinalMessage(notExpected, actual, userMessage); + ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + } + + private static string GetAreNotEqualFinalMessage(object? notExpected, object? actual, string userMessage) + => string.Format( CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualFailMsg, userMessage, ReplaceNulls(notExpected), ReplaceNulls(actual)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); - } } diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 4df009b168..f8c8649c7d 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,4 +1,17 @@ #nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, System.IEquatable? expected, System.IEquatable? actual, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void @@ -30,6 +43,22 @@ Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAtt Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.AutoDetect = 2 -> Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(decimal expected, decimal actual, decimal delta, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(double expected, double actual, double delta, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(long expected, long actual, long delta, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(string? expected, string? actual, bool ignoreCase, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(System.IEquatable? expected, System.IEquatable? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(T? expected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(T? expected, T? actual, System.Collections.Generic.IEqualityComparer? comparer, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(decimal notExpected, decimal actual, decimal delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(double notExpected, double actual, double delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(float notExpected, float actual, float delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(long notExpected, long actual, long delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, System.Collections.Generic.IEqualityComparer? comparer, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler message) -> void @@ -40,3 +69,4 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(Sy static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactlyAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! +~static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(float expected, float actual, float delta, ref AssertNonGenericAreEqualInterpolatedStringHandler? message) -> void From 4c21c0b4f380aeeeab6976465c012145c61d34d5 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 06:04:16 +0100 Subject: [PATCH 05/46] Refactor --- .../TestFramework/Assertions/Assert.IsNull.cs | 45 ++++++++------ .../TestFramework/Assertions/Assert.IsTrue.cs | 62 +++++++++---------- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index d070464376..5d99256b25 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -27,9 +27,13 @@ public AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCou } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsNull(_builder.ToString()); + } + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -55,9 +59,13 @@ public AssertIsNotNullInterpolatedStringHandler(int literalLength, int formatted } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsNotNull(_builder.ToString()); + } + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -102,12 +110,7 @@ public static void IsNull(object? value, string? message) #pragma warning disable IDE0060 // Remove unused parameter - false positive. The value parameter is used via the interpolated string handler. public static void IsNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.IsNull", message.ToStringAndClear()); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified object is null and throws an exception @@ -130,12 +133,15 @@ public static void IsNull(object? value, [StringSyntax(StringSyntaxAttribute.Com { if (IsNullFailing(value)) { - ThrowAssertFailed("Assert.IsNull", BuildUserMessage(message, parameters)); + FailIsNull(BuildUserMessage(message, parameters)); } } private static bool IsNullFailing(object? value) => value is not null; + private static void FailIsNull(string message) + => ThrowAssertFailed("Assert.IsNull", message); + /// /// Tests whether the specified object is non-null and throws an exception /// if it is null. @@ -170,12 +176,7 @@ public static void IsNotNull([NotNull] object? value, string? message) #pragma warning disable IDE0060 // Remove unused parameter - false positive. The value parameter is used via the interpolated string handler. public static void IsNotNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.IsNotNull", message.ToStringAndClear()); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified object is non-null and throws an exception @@ -198,9 +199,13 @@ public static void IsNotNull([NotNull] object? value, [StringSyntax(StringSyntax { if (IsNotNullFailing(value)) { - ThrowAssertFailed("Assert.IsNotNull", BuildUserMessage(message, parameters)); + FailIsNotNull(BuildUserMessage(message, parameters)); } } private static bool IsNotNullFailing([NotNullWhen(false)] object? value) => value is null; + + [DoesNotReturn] + private static void FailIsNotNull(string message) + => ThrowAssertFailed("Assert.IsNotNull", message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 04fdd615ba..06741b8a4c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -27,9 +27,13 @@ public AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCou } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsTrue(_builder.ToString()); + } + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -55,9 +59,13 @@ public AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCo } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsFalse(_builder.ToString()); + } + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -115,12 +123,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? messa #pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsTrue([DoesNotReturnIf(false)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.IsTrue", message.ToStringAndClear()); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified condition is true and throws an exception @@ -143,12 +146,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? mess #pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.IsTrue", message.ToStringAndClear()); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified condition is true and throws an exception @@ -172,7 +170,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, [StringSyntax { if (IsTrueFailing(condition)) { - ThrowAssertFailed("Assert.IsTrue", BuildUserMessage(message, parameters)); + FailIsTrue(BuildUserMessage(message, parameters)); } } @@ -198,7 +196,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [StringSynta { if (IsTrueFailing(condition)) { - ThrowAssertFailed("Assert.IsTrue", BuildUserMessage(message, parameters)); + FailIsTrue(BuildUserMessage(message, parameters)); } } @@ -208,6 +206,9 @@ private static bool IsTrueFailing(bool? condition) private static bool IsTrueFailing(bool condition) => !condition; + private static void FailIsTrue(string message) + => ThrowAssertFailed("Assert.IsTrue", message); + /// /// Tests whether the specified condition is false and throws an exception /// if the condition is true. @@ -255,12 +256,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? messa #pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsFalse([DoesNotReturnIf(true)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.IsFalse", message.ToStringAndClear()); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified condition is false and throws an exception @@ -283,12 +279,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? mess #pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.IsFalse", message.ToStringAndClear()); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified condition is false and throws an exception @@ -312,7 +303,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, [StringSyntax { if (IsFalseFailing(condition)) { - ThrowAssertFailed("Assert.IsFalse", BuildUserMessage(message, parameters)); + FailIsFalse(BuildUserMessage(message, parameters)); } } @@ -338,7 +329,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [StringSynta { if (IsFalseFailing(condition)) { - ThrowAssertFailed("Assert.IsFalse", BuildUserMessage(message, parameters)); + FailIsFalse(BuildUserMessage(message, parameters)); } } @@ -348,4 +339,7 @@ private static bool IsFalseFailing(bool? condition) private static bool IsFalseFailing(bool condition) => condition; + [DoesNotReturn] + private static void FailIsFalse(string userMessage) + => ThrowAssertFailed("Assert.IsFalse", userMessage); } From 5f92199b5a7450c5da3f54ef172c6450a97fd5bf Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 06:28:05 +0100 Subject: [PATCH 06/46] AreEqual progress [WIP] --- .../Assertions/Assert.AreEqual.cs | 150 +++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 52d5e42db3..f4f1ebb6ac 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -90,6 +90,154 @@ public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formatt public readonly void AppendFormatted(T value) => _builder!.Append(value); +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertNonGenericAreEqualInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, float expected, float actual, float delta, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal expected, decimal actual, decimal delta, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, long expected, long actual, long delta, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, double expected, double actual, double delta, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) + { + shouldAppend = AreEqualFailing(expected, actual, ignoreCase); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, out bool shouldAppend) + { + Guard.NotNull(culture); + shouldAppend = AreEqualFailing(expected, actual, ignoreCase, culture); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal bool ShouldAppend => _builder is not null; + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NET + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertNonGenericAreNotEqualInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, float expected, float actual, float delta, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal expected, decimal actual, decimal delta, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, long expected, long actual, long delta, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, double expected, double actual, double delta, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(expected, actual, delta); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) + { + shouldAppend = AreNotEqualFailing(expected, actual, ignoreCase); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, out bool shouldAppend) + { + Guard.NotNull(culture); + shouldAppend = AreNotEqualFailing(expected, actual, ignoreCase, culture); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal bool ShouldAppend => _builder is not null; + + internal readonly string ToStringAndClear() => _builder!.ToString(); + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + #if NET public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif @@ -653,7 +801,7 @@ public static void AreEqual(float expected, float actual, float delta, string? m => AreEqual(expected, actual, delta, message, null); /// - public static void AreEqual(float expected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler? message) + public static void AreEqual(float expected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) { if (message.ShouldAppend) { From 9eb961557eb69f27155057e4e2fb90ac58f741df Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 09:40:36 +0100 Subject: [PATCH 07/46] Progress [WIP] --- .../Assertions/Assert.AreEqual.cs | 338 ++++++++---------- 1 file changed, 144 insertions(+), 194 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index f4f1ebb6ac..9dbcc784e1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -17,13 +17,18 @@ public sealed partial class Assert public readonly struct AssertAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly object? _expected; + private readonly object? _actual; public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) { + _expected = expected!; shouldAppend = AreEqualFailing(expected, actual); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _expected = expected; + _actual = actual; } } @@ -33,6 +38,8 @@ public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedC if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _expected = expected; + _actual = actual; } } @@ -42,12 +49,18 @@ public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedC if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _expected = expected; + _actual = actual; } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailAreEqual(_expected, _actual, _builder.ToString()); + } + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -63,6 +76,8 @@ public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedC public readonly struct AssertAreNotEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly object? _notExpected; + private readonly object? _actual; public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) { @@ -70,6 +85,8 @@ public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formatt if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _notExpected = notExpected; + _actual = actual; } } @@ -79,12 +96,18 @@ public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formatt if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _notExpected = notExpected; + _actual = actual; } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailAreNotEqual(_notExpected, _actual, _builder.ToString()); + } + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -100,6 +123,7 @@ public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formatt public readonly struct AssertNonGenericAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly Action? _failAction; public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, float expected, float actual, float delta, out bool shouldAppend) { @@ -107,6 +131,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); } } @@ -116,6 +141,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); } } @@ -125,6 +151,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); } } @@ -134,16 +161,13 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); } } public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) + : this(literalLength, formattedCount, expected, actual, ignoreCase, CultureInfo.InvariantCulture, out shouldAppend) { - shouldAppend = AreEqualFailing(expected, actual, ignoreCase); - if (shouldAppend) - { - _builder = new StringBuilder(literalLength + formattedCount); - } } public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, out bool shouldAppend) @@ -153,12 +177,12 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreEqual(expected, actual, ignoreCase, culture, userMessage); } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + => _failAction?.Invoke(_builder!.ToString()); public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -230,9 +254,10 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i } } - internal bool ShouldAppend => _builder is not null; - - internal readonly string ToStringAndClear() => _builder!.ToString(); + internal void FailIfNeeded() + { + // TODO: + } public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -315,12 +340,7 @@ public static void AreEqual(T? expected, T? actual, string? message) /// public static void AreEqual(T? expected, T? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.AreEqual", GetAreEqualFinalMessage(expected, actual, message.ToStringAndClear())); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified values are equal and throws an exception @@ -356,12 +376,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com #pragma warning disable IDE0060 // Remove unused parameter - false positive. The comparer parameter is used via the interpolated string handler. public static void AreEqual(T? expected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(comparer))] ref AssertAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.AreEqual", GetAreEqualFinalMessage(expected, actual, message.ToStringAndClear())); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified values are equal and throws an exception @@ -431,28 +446,9 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = GetAreEqualFinalMessage(expected, actual, userMessage); - - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, userMessage); } - private static string GetAreEqualFinalMessage(object? expected, object? actual, string userMessage) - => actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) - ? string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDifferentTypesFailMsg, - userMessage, - ReplaceNulls(expected), - expected.GetType().FullName, - ReplaceNulls(actual), - actual.GetType().FullName) - : string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); - /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. @@ -501,12 +497,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, s /// public static void AreEqual(IEquatable? expected, IEquatable? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.AreEqual", GetAreEqualFinalMessage(expected, actual, message.ToStringAndClear())); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified values are equal and throws an exception @@ -542,9 +533,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, [ } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = GetAreEqualFinalMessage(expected, actual, userMessage); - - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, userMessage); } private static bool AreEqualFailing(T? expected, T? actual) @@ -556,6 +545,78 @@ private static bool AreEqualFailing(T? expected, T? actual, IEqualityComparer private static bool AreEqualFailing(IEquatable? expected, IEquatable? actual) => (actual is not null || expected is not null) && actual?.Equals(expected) != true; + private static bool AreEqualFailing(string? expected, string? actual, bool ignoreCase, CultureInfo culture) + => CompareInternal(expected, actual, ignoreCase, culture) != 0; + + private static bool AreEqualFailing(float expected, float actual, float delta) + => float.IsNaN(expected) || float.IsNaN(actual) || float.IsNaN(delta) || + Math.Abs(expected - actual) > delta; + + private static bool AreEqualFailing(double expected, double actual, double delta) + => double.IsNaN(expected) || double.IsNaN(actual) || double.IsNaN(delta) || + Math.Abs(expected - actual) > delta; + + private static bool AreEqualFailing(decimal expected, decimal actual, decimal delta) + => Math.Abs(expected - actual) > delta; + + private static bool AreEqualFailing(long expected, long actual, long delta) + => Math.Abs(expected - actual) > delta; + + [DoesNotReturn] + private static void FailAreEqual(object? expected, object? actual, string userMessage) + { + string finalMessage = actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) + ? string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreEqualDifferentTypesFailMsg, + userMessage, + ReplaceNulls(expected), + expected.GetType().FullName, + ReplaceNulls(actual), + actual.GetType().FullName) + : string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreEqualFailMsg, + userMessage, + ReplaceNulls(expected), + ReplaceNulls(actual)); + ThrowAssertFailed("Assert.AreEqual", finalMessage); + } + + [DoesNotReturn] + private static void FailAreEqual(T expected, T actual, T delta, string userMessage) + where T : struct, IConvertible + { + string finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreEqualDeltaFailMsg, + userMessage, + expected.ToString(CultureInfo.CurrentCulture.NumberFormat), + actual.ToString(CultureInfo.CurrentCulture.NumberFormat), + delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); + ThrowAssertFailed("Assert.AreEqual", finalMessage); + } + + [DoesNotReturn] + private static void FailAreEqual(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string userMessage) + { + string finalMessage = !ignoreCase && CompareInternal(expected, actual, ignoreCase, culture) == 0 + ? string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreEqualCaseFailMsg, + userMessage, + ReplaceNulls(expected), + ReplaceNulls(actual)) + : string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreEqualFailMsg, + userMessage, + ReplaceNulls(expected), + ReplaceNulls(actual)); + + ThrowAssertFailed("Assert.AreEqual", finalMessage); + } + /// /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. @@ -630,12 +691,7 @@ public static void AreNotEqual(T? notExpected, T? actual, string? message) /// public static void AreNotEqual(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] ref AssertAreNotEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.AreNotEqual", GetAreNotEqualFinalMessage(notExpected, actual, message.ToStringAndClear())); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified values are unequal and throws an exception @@ -671,12 +727,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer(T? notExpected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(comparer))] ref AssertAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - { - if (message.ShouldAppend) - { - ThrowAssertFailed("Assert.AreNotEqual", GetAreNotEqualFinalMessage(notExpected, actual, message.ToStringAndClear())); - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified values are unequal and throws an exception @@ -802,12 +853,7 @@ public static void AreEqual(float expected, float actual, float delta, string? m /// public static void AreEqual(float expected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified floats are equal and throws an exception @@ -839,18 +885,10 @@ public static void AreEqual(float expected, float actual, float delta, [Interpol public static void AreEqual(float expected, float actual, float delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (float.IsNaN(expected) || float.IsNaN(actual) || float.IsNaN(delta) || - Math.Abs(expected - actual) > delta) + if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDeltaFailMsg, - userMessage, - expected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, delta, userMessage); } } @@ -904,12 +942,7 @@ public static void AreNotEqual(float notExpected, float actual, float delta, str => AreNotEqual(notExpected, actual, delta, message, null); public static void AreNotEqual(float notExpected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified floats are unequal and throws an exception @@ -1006,12 +1039,7 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta, str /// public static void AreEqual(decimal expected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified decimals are equal and throws an exception @@ -1043,17 +1071,10 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta, [In public static void AreEqual(decimal expected, decimal actual, decimal delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (Math.Abs(expected - actual) > delta) + if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDeltaFailMsg, - userMessage, - expected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, delta, userMessage); } } @@ -1108,12 +1129,7 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt /// public static void AreNotEqual(decimal notExpected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified decimals are unequal and throws an exception @@ -1210,12 +1226,7 @@ public static void AreEqual(long expected, long actual, long delta, string? mess /// public static void AreEqual(long expected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified longs are equal and throws an exception @@ -1247,17 +1258,10 @@ public static void AreEqual(long expected, long actual, long delta, [Interpolate public static void AreEqual(long expected, long actual, long delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (Math.Abs(expected - actual) > delta) + if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDeltaFailMsg, - userMessage, - expected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, delta, userMessage); } } @@ -1312,12 +1316,7 @@ public static void AreNotEqual(long notExpected, long actual, long delta, string /// public static void AreNotEqual(long notExpected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified longs are unequal and throws an exception @@ -1413,12 +1412,7 @@ public static void AreEqual(double expected, double actual, double delta, string /// public static void AreEqual(double expected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified doubles are equal and throws an exception @@ -1449,18 +1443,10 @@ public static void AreEqual(double expected, double actual, double delta, [Inter public static void AreEqual(double expected, double actual, double delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (double.IsNaN(expected) || double.IsNaN(actual) || double.IsNaN(delta) || - Math.Abs(expected - actual) > delta) + if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDeltaFailMsg, - userMessage, - expected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, delta, userMessage); } } @@ -1515,12 +1501,7 @@ public static void AreNotEqual(double notExpected, double actual, double delta, /// public static void AreNotEqual(double notExpected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified doubles are unequal and throws an exception @@ -1613,12 +1594,7 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, s /// public static void AreEqual(string? expected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified strings are equal and throws an exception @@ -1707,10 +1683,7 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) { CheckParameterNotNull(culture, "Assert.AreEqual", nameof(culture), string.Empty); - if (message.ShouldAppend) - { - // TODO: - } + message.FailIfNeeded(); } /// @@ -1745,28 +1718,13 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { CheckParameterNotNull(culture, "Assert.AreEqual", "culture", string.Empty); - if (CompareInternal(expected, actual, ignoreCase, culture) == 0) + if (!AreEqualFailing(expected, actual, ignoreCase, culture)) { return; } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = !ignoreCase && CompareInternal(expected, actual, ignoreCase, culture) == 0 - ? string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualCaseFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)) - : string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); - - // Comparison failed. Check if it was a case-only failure. - ThrowAssertFailed("Assert.AreEqual", finalMessage); + FailAreEqual(expected, actual, ignoreCase, culture, userMessage); } /// @@ -1818,12 +1776,7 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC /// public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) - { - if (message.ShouldAppend) - { - // TODO: - } - } + => message.FailIfNeeded(); /// /// Tests whether the specified strings are unequal and throws an exception @@ -1913,11 +1866,8 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) { - CheckParameterNotNull(culture, "Assert.AreEqual", nameof(culture), string.Empty); - if (message.ShouldAppend) - { - // TODO: - } + CheckParameterNotNull(culture, "Assert.AreNotEqual", nameof(culture), string.Empty); + message.FailIfNeeded(); } /// From d02035367e36b42d453b5c508c88b94cbce87434 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 10:42:39 +0100 Subject: [PATCH 08/46] Better progress for AreEqual --- .../Assertions/Assert.AreEqual.cs | 141 +++++++++--------- 1 file changed, 70 insertions(+), 71 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 9dbcc784e1..6a3cc3cbb1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -80,14 +80,8 @@ public readonly struct AssertAreNotEqualInterpolatedStringHandler private readonly object? _actual; public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) + : this(literalLength, formattedCount, notExpected, actual, null, out shouldAppend) { - shouldAppend = AreNotEqualFailing(notExpected, actual); - if (shouldAppend) - { - _builder = new StringBuilder(literalLength + formattedCount); - _notExpected = notExpected; - _actual = actual; - } } public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, IEqualityComparer? comparer, out bool shouldAppend) @@ -198,66 +192,66 @@ internal void FailIfNeeded() public readonly struct AssertNonGenericAreNotEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly Action? _failAction; - public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, float expected, float actual, float delta, out bool shouldAppend) + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, float notExpected, float actual, float delta, out bool shouldAppend) { - shouldAppend = AreNotEqualFailing(expected, actual, delta); + shouldAppend = AreNotEqualFailing(notExpected, actual, delta); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); } } - public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal expected, decimal actual, decimal delta, out bool shouldAppend) + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal notExpected, decimal actual, decimal delta, out bool shouldAppend) { - shouldAppend = AreNotEqualFailing(expected, actual, delta); + shouldAppend = AreNotEqualFailing(notExpected, actual, delta); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); } } - public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, long expected, long actual, long delta, out bool shouldAppend) + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, long notExpected, long actual, long delta, out bool shouldAppend) { - shouldAppend = AreNotEqualFailing(expected, actual, delta); + shouldAppend = AreNotEqualFailing(notExpected, actual, delta); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); } } - public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, double expected, double actual, double delta, out bool shouldAppend) + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, double notExpected, double actual, double delta, out bool shouldAppend) { - shouldAppend = AreNotEqualFailing(expected, actual, delta); + shouldAppend = AreNotEqualFailing(notExpected, actual, delta); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); } } - public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, out bool shouldAppend) + : this(literalLength, formattedCount, notExpected, actual, ignoreCase, CultureInfo.InvariantCulture, out shouldAppend) { - shouldAppend = AreNotEqualFailing(expected, actual, ignoreCase); - if (shouldAppend) - { - _builder = new StringBuilder(literalLength + formattedCount); - } } - public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, out bool shouldAppend) + public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, out bool shouldAppend) { Guard.NotNull(culture); - shouldAppend = AreNotEqualFailing(expected, actual, ignoreCase, culture); + shouldAppend = AreNotEqualFailing(notExpected, actual, ignoreCase, culture); if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _failAction = userMessage => FailAreNotEqual(notExpected, actual, userMessage); } } internal void FailIfNeeded() - { - // TODO: - } + => _failAction?.Invoke(_builder!.ToString()); public readonly void AppendLiteral(string value) => _builder!.Append(value); @@ -791,15 +785,13 @@ public static void AreNotEqual(T? notExpected, T? actual, [StringSyntax(Strin public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer? comparer, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - IEqualityComparer localComparer = comparer ?? EqualityComparer.Default; - if (!localComparer.Equals(notExpected!, actual!)) + if (!AreNotEqualFailing(notExpected, actual, comparer)) { return; } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = GetAreNotEqualFinalMessage(notExpected, actual, userMessage); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + FailAreNotEqual(notExpected, actual, userMessage); } /// @@ -974,20 +966,16 @@ public static void AreNotEqual(float notExpected, float actual, float delta, [In public static void AreNotEqual(float notExpected, float actual, float delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (Math.Abs(notExpected - actual) <= delta) + if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreNotEqualDeltaFailMsg, - userMessage, - notExpected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + FailAreNotEqual(notExpected, actual, delta, userMessage); } } + private static bool AreNotEqualFailing(float notExpected, float actual, float delta) + => Math.Abs(notExpected - actual) <= delta; + /// /// Tests whether the specified decimals are equal and throws an exception /// if they are not equal. @@ -1161,20 +1149,16 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt public static void AreNotEqual(decimal notExpected, decimal actual, decimal delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (Math.Abs(notExpected - actual) <= delta) + if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreNotEqualDeltaFailMsg, - userMessage, - notExpected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + FailAreNotEqual(notExpected, actual, delta, userMessage); } } + private static bool AreNotEqualFailing(decimal notExpected, decimal actual, decimal delta) + => Math.Abs(notExpected - actual) <= delta; + /// /// Tests whether the specified longs are equal and throws an exception /// if they are not equal. @@ -1348,20 +1332,16 @@ public static void AreNotEqual(long notExpected, long actual, long delta, [Inter public static void AreNotEqual(long notExpected, long actual, long delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (Math.Abs(notExpected - actual) <= delta) + if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreNotEqualDeltaFailMsg, - userMessage, - notExpected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + FailAreNotEqual(notExpected, actual, delta, userMessage); } } + private static bool AreNotEqualFailing(long notExpected, long actual, long delta) + => Math.Abs(notExpected - actual) <= delta; + /// /// Tests whether the specified doubles are equal and throws an exception /// if they are not equal. @@ -1533,20 +1513,30 @@ public static void AreNotEqual(double notExpected, double actual, double delta, public static void AreNotEqual(double notExpected, double actual, double delta, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (Math.Abs(notExpected - actual) <= delta) + if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreNotEqualDeltaFailMsg, - userMessage, - notExpected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + FailAreNotEqual(notExpected, actual, delta, userMessage); } } + private static bool AreNotEqualFailing(double notExpected, double actual, double delta) + => Math.Abs(notExpected - actual) <= delta; + + [DoesNotReturn] + private static void FailAreNotEqual(T notExpected, T actual, T delta, string userMessage) + where T : struct, IConvertible + { + string finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreNotEqualDeltaFailMsg, + userMessage, + notExpected.ToString(CultureInfo.CurrentCulture.NumberFormat), + actual.ToString(CultureInfo.CurrentCulture.NumberFormat), + delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); + ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + } + /// /// Tests whether the specified strings are equal and throws an exception /// if they are not equal. The invariant culture is used for the comparison. @@ -1903,21 +1893,30 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC CultureInfo? culture, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { CheckParameterNotNull(culture, "Assert.AreNotEqual", "culture", string.Empty); - if (CompareInternal(notExpected, actual, ignoreCase, culture) != 0) + if (!AreNotEqualFailing(notExpected, actual, ignoreCase, culture)) { return; } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = GetAreNotEqualFinalMessage(notExpected, actual, userMessage); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + FailAreNotEqual(notExpected, actual, userMessage); } - private static string GetAreNotEqualFinalMessage(object? notExpected, object? actual, string userMessage) - => string.Format( + private static bool AreNotEqualFailing(string? notExpected, string? actual, bool ignoreCase, CultureInfo culture) + => CompareInternal(notExpected, actual, ignoreCase, culture) == 0; + + private static bool AreNotEqualFailing(T? notExpected, T? actual, IEqualityComparer? comparer) + => (comparer ?? EqualityComparer.Default).Equals(notExpected!, actual!); + + [DoesNotReturn] + private static void FailAreNotEqual(object? notExpected, object? actual, string userMessage) + { + string finalMessage = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualFailMsg, userMessage, ReplaceNulls(notExpected), ReplaceNulls(actual)); + ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + } } From 8dffd673d4c0780d59f50094e62f905b4500718e Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 10:48:40 +0100 Subject: [PATCH 09/46] Suppress FPs --- .../Assertions/Assert.AreEqual.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 6a3cc3cbb1..ae5c58b796 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -333,7 +333,9 @@ public static void AreEqual(T? expected, T? actual, string? message) => AreEqual(expected, actual, null, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(T? expected, T? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -490,7 +492,9 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, s => AreEqual(expected, actual, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(IEquatable? expected, IEquatable? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -684,7 +688,9 @@ public static void AreNotEqual(T? notExpected, T? actual, string? message) => AreNotEqual(notExpected, actual, null, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] ref AssertAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -844,7 +850,9 @@ public static void AreEqual(float expected, float actual, float delta, string? m => AreEqual(expected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(float expected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -933,7 +941,9 @@ public static void AreNotEqual(float notExpected, float actual, float delta) public static void AreNotEqual(float notExpected, float actual, float delta, string? message) => AreNotEqual(notExpected, actual, delta, message, null); +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(float notExpected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1026,7 +1036,9 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta, str => AreEqual(expected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(decimal expected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1116,7 +1128,9 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt => AreNotEqual(notExpected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(decimal notExpected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1209,7 +1223,9 @@ public static void AreEqual(long expected, long actual, long delta, string? mess => AreEqual(expected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(long expected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1299,7 +1315,9 @@ public static void AreNotEqual(long notExpected, long actual, long delta, string => AreNotEqual(notExpected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(long notExpected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1391,7 +1409,9 @@ public static void AreEqual(double expected, double actual, double delta, string => AreEqual(expected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(double expected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1480,7 +1500,9 @@ public static void AreNotEqual(double notExpected, double actual, double delta, => AreNotEqual(notExpected, actual, delta, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(double notExpected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1583,7 +1605,9 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, s => AreEqual(expected, actual, ignoreCase, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(string? expected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1669,7 +1693,9 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, => AreEqual(expected, actual, ignoreCase, culture, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(string? expected, string? actual, bool ignoreCase, +#pragma warning restore IDE0060 // Remove unused parameter [NotNull] CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) { CheckParameterNotNull(culture, "Assert.AreEqual", nameof(culture), string.Empty); @@ -1765,7 +1791,9 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC => AreNotEqual(notExpected, actual, ignoreCase, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); /// @@ -1853,7 +1881,9 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC => AreNotEqual(notExpected, actual, ignoreCase, culture, message, null); /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, +#pragma warning restore IDE0060 // Remove unused parameter CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) { CheckParameterNotNull(culture, "Assert.AreNotEqual", nameof(culture), string.Empty); From ebd0bc553709207b982406501a90117fa4e95482 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 10:52:51 +0100 Subject: [PATCH 10/46] PublicAPI --- .../PublicAPI/PublicAPI.Unshipped.txt | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index f8c8649c7d..c4c616867e 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,5 +1,6 @@ #nullable enable Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler() -> void @@ -7,6 +8,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedSt Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler() -> void @@ -36,6 +38,26 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStri Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal expected, decimal actual, decimal delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, double expected, double actual, double delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, float expected, float actual, float delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, long expected, long actual, long delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal notExpected, decimal actual, decimal delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, double notExpected, double actual, double delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, float notExpected, float actual, float delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, long notExpected, long actual, long delta, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType) -> void @@ -43,20 +65,21 @@ Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAtt Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.AutoDetect = 2 -> Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void *REMOVED*Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType = Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType.Property) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(decimal expected, decimal actual, decimal delta, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(double expected, double actual, double delta, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(long expected, long actual, long delta, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(string? expected, string? actual, bool ignoreCase, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref AssertNonGenericAreEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(decimal expected, decimal actual, decimal delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(double expected, double actual, double delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(float expected, float actual, float delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(long expected, long actual, long delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(string? expected, string? actual, bool ignoreCase, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(System.IEquatable? expected, System.IEquatable? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(T? expected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(T? expected, T? actual, System.Collections.Generic.IEqualityComparer? comparer, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(decimal notExpected, decimal actual, decimal delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(double notExpected, double actual, double delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(float notExpected, float actual, float delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(long notExpected, long actual, long delta, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref AssertNonGenericAreNotEqualInterpolatedStringHandler! message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(decimal notExpected, decimal actual, decimal delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(double notExpected, double actual, double delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(float notExpected, float actual, float delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(long notExpected, long actual, long delta, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, System.Collections.Generic.IEqualityComparer? comparer, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void @@ -69,4 +92,3 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(Sy static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactlyAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! -~static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(float expected, float actual, float delta, ref AssertNonGenericAreEqualInterpolatedStringHandler? message) -> void From 7c903d2bf340936bd9f0f873d7adfc414380c615 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 11:43:11 +0100 Subject: [PATCH 11/46] PublicAPI --- .../TestFramework/PublicAPI/PublicAPI.Unshipped.txt | 8 ++------ .../TestFramework/PublicAPI/net/PublicAPI.Shipped.txt | 1 + .../TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt | 7 +++++++ src/TestFramework/TestFramework/TestFramework.csproj | 3 +++ 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Shipped.txt create mode 100644 src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index c4c616867e..5a5effe5ea 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,6 +1,5 @@ #nullable enable Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler() -> void @@ -8,37 +7,33 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedSt Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler() -> void @@ -49,6 +44,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInte Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler() -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Shipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..593cf5e674 --- /dev/null +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -0,0 +1,7 @@ +#nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void diff --git a/src/TestFramework/TestFramework/TestFramework.csproj b/src/TestFramework/TestFramework/TestFramework.csproj index 8f67b0069d..79ae688ade 100644 --- a/src/TestFramework/TestFramework/TestFramework.csproj +++ b/src/TestFramework/TestFramework/TestFramework.csproj @@ -14,6 +14,9 @@ + + + From 90a460a847324d1ec3b1e5391396c64166d68203 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 12:15:22 +0100 Subject: [PATCH 12/46] Fix conditionals --- .../TestFramework/Assertions/Assert.AreEqual.cs | 8 ++++---- .../TestFramework/Assertions/Assert.IsNull.cs | 4 ++-- .../TestFramework/Assertions/Assert.IsTrue.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index ae5c58b796..750fbfe7d9 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -66,7 +66,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } @@ -107,7 +107,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } @@ -182,7 +182,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } @@ -257,7 +257,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 5d99256b25..a07230a32b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -39,7 +39,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } @@ -71,7 +71,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 06741b8a4c..30c34e25ca 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -39,7 +39,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } @@ -71,7 +71,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); -#if NET +#if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif } From bbce272ecfc6cc04e8e6e6f2646561630c0e42ef Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 12:42:35 +0100 Subject: [PATCH 13/46] PublicAPI --- .../TestFramework/PublicAPI/PublicAPI.Unshipped.txt | 2 -- .../TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 5a5effe5ea..b3370546f8 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -33,7 +33,6 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStri Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler() -> void @@ -44,7 +43,6 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInte Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler() -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt index 593cf5e674..ae5329b42a 100644 --- a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -5,3 +5,5 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStr Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void From aaa98bb6a425931e002ead817ecbebd82f8a2c7f Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 13:16:35 +0100 Subject: [PATCH 14/46] Progress for IsInstanceOfType/IsNotInstanceOfType --- .../Assertions/Assert.IsInstanceOfType.cs | 124 +++++++++++++++--- .../PublicAPI/PublicAPI.Unshipped.txt | 10 ++ .../PublicAPI/net/PublicAPI.Unshipped.txt | 4 +- 3 files changed, 117 insertions(+), 21 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 84adbb12b5..0adf8b68bd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.ComponentModel; + namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -10,6 +12,78 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertIsInstanceOfTypeInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + private readonly object? _value; + private readonly Type? _expectedType; + + public AssertIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, Type? expectedType, out bool shouldAppend) + { + _value = value; + _expectedType = expectedType; + shouldAppend = IsInstanceOfTypeFailing(value, expectedType); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsInstanceOfType(_value, _expectedType, _builder.ToString()); + } + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertIsNotInstanceOfTypeInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + private readonly object? _value; + private readonly Type? _wrongType; + + public AssertIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, Type? wrongType, out bool shouldAppend) + { + _value = value; + _wrongType = wrongType; + shouldAppend = IsNotInstanceOfTypeFailing(value, wrongType); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsNotInstanceOfType(_value, _wrongType, _builder.ToString()); + } + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + /// /// Tests whether the specified object is an instance of the expected /// type and throws an exception if the expected type is not in the @@ -116,23 +190,30 @@ public static void IsInstanceOfType([NotNull] object? value, out T instance, public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? expectedType, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (expectedType == null || value == null) + if (IsInstanceOfTypeFailing(value, expectedType)) { - ThrowAssertFailed("Assert.IsInstanceOfType", BuildUserMessage(message, parameters)); + FailIsInstanceOfType(value, expectedType, BuildUserMessage(message, parameters)); } + } + + private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, [NotNullWhen(false)] Type? expectedType) + => expectedType == null || value == null || !expectedType.IsAssignableFrom(value.GetType()); - Type elementType = value.GetType(); - if (!expectedType.IsAssignableFrom(elementType)) + [DoesNotReturn] + private static void FailIsInstanceOfType(object? value, Type? expectedType, string userMessage) + { + string finalMessage = userMessage; + if (expectedType is not null && value is not null) { - string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( + finalMessage = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.IsInstanceOfFailMsg, userMessage, expectedType.ToString(), value.GetType().ToString()); - ThrowAssertFailed("Assert.IsInstanceOfType", finalMessage); } + + ThrowAssertFailed("Assert.IsInstanceOfType", finalMessage); } /// @@ -246,29 +327,32 @@ public static void IsNotInstanceOfType(object? value, string? message) public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (wrongType == null) + if (IsNotInstanceOfTypeFailing(value, wrongType)) { - ThrowAssertFailed("Assert.IsNotInstanceOfType", BuildUserMessage(message, parameters)); + FailIsNotInstanceOfType(value, wrongType, BuildUserMessage(message, parameters)); } + } - // Null is not an instance of any type. - if (value == null) - { - return; - } + private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false)] Type? wrongType) + => wrongType is null || + // Null is not an instance of any type. + (value is not null && wrongType.IsAssignableFrom(value.GetType())); - Type elementType = value.GetType(); - if (wrongType.IsAssignableFrom(elementType)) + [DoesNotReturn] + private static void FailIsNotInstanceOfType(object? value, Type? wrongType, string userMessage) + { + string finalMessage = userMessage; + if (wrongType is not null) { - string userMessage = BuildUserMessage(message, parameters); - string finalMessage = string.Format( + finalMessage = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.IsNotInstanceOfFailMsg, userMessage, wrongType.ToString(), - value.GetType().ToString()); - ThrowAssertFailed("Assert.IsNotInstanceOfType", finalMessage); + value!.GetType().ToString()); } + + ThrowAssertFailed("Assert.IsNotInstanceOfType", finalMessage); } /// diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index b3370546f8..876e2ac672 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -17,6 +17,16 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStr Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AssertIsInstanceOfTypeInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AssertIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, System.Type? expectedType, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AssertIsNotInstanceOfTypeInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AssertIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, System.Type? wrongType, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendLiteral(string! value) -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt index ae5329b42a..29c1f21f45 100644 --- a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -2,8 +2,10 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void From 8e437e3ab6b123ac7bc613d9c19c8578335fba2d Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 13:42:26 +0100 Subject: [PATCH 15/46] AreSame/AreNotSame progress --- .../Assertions/Assert.AreSame.cs | 119 ++++++++++++++++-- .../PublicAPI/PublicAPI.Unshipped.txt | 12 ++ .../PublicAPI/net/PublicAPI.Unshipped.txt | 2 + 3 files changed, 121 insertions(+), 12 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index b2fd9113d1..7dcc0acbf5 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.ComponentModel; + namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// @@ -10,6 +12,75 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertAreSameInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + private readonly TArgument? _expected; + private readonly TArgument? _actual; + + public AssertAreSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) + { + _expected = expected; + _actual = actual; + shouldAppend = IsAreSameFailing(expected, actual); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailAreSame(_expected, _actual, _builder.ToString()); + } + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertAreNotSameInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + + public AssertAreNotSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) + { + shouldAppend = IsAreNotSameFailing(notExpected, actual); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailAreNotSame(_builder.ToString()); + } + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + /// /// Tests whether the specified objects both refer to the same object and /// throws an exception if the two inputs do not refer to the same object. @@ -55,6 +126,12 @@ public static void AreSame(T? expected, T? actual) public static void AreSame(T? expected, T? actual, string? message) => AreSame(expected, actual, message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static void AreSame(T? expected, T? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreSameInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + => message.FailIfNeeded(); + /// /// Tests whether the specified objects both refer to the same object and /// throws an exception if the two inputs do not refer to the same object. @@ -82,23 +159,28 @@ public static void AreSame(T? expected, T? actual, string? message) /// public static void AreSame(T? expected, T? actual, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (ReferenceEquals(expected, actual)) + if (!IsAreSameFailing(expected, actual)) { return; } string userMessage = BuildUserMessage(message, parameters); - string finalMessage = userMessage; + FailAreSame(expected, actual, userMessage); + } - if (expected is ValueType) + private static bool IsAreSameFailing(T? expected, T? actual) + => !ReferenceEquals(expected, actual); + + [DoesNotReturn] + private static void FailAreSame(T? expected, T? actual, string userMessage) + { + string finalMessage = userMessage; + if (expected is ValueType && actual is ValueType) { - if (actual is ValueType) - { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreSameGivenValues, - userMessage); - } + finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.AreSameGivenValues, + userMessage); } ThrowAssertFailed("Assert.AreSame", finalMessage); @@ -151,6 +233,12 @@ public static void AreNotSame(T? notExpected, T? actual) public static void AreNotSame(T? notExpected, T? actual, string? message) => AreNotSame(notExpected, actual, message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static void AreNotSame(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] AssertAreNotSameInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + => message.FailIfNeeded(); + /// /// Tests whether the specified objects refer to different objects and /// throws an exception if the two inputs refer to the same object. @@ -179,9 +267,16 @@ public static void AreNotSame(T? notExpected, T? actual, string? message) /// public static void AreNotSame(T? notExpected, T? actual, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[]? parameters) { - if (ReferenceEquals(notExpected, actual)) + if (IsAreNotSameFailing(notExpected, actual)) { - ThrowAssertFailed("Assert.AreNotSame", BuildUserMessage(message, parameters)); + FailAreNotSame(BuildUserMessage(message, parameters)); } } + + private static bool IsAreNotSameFailing(T? notExpected, T? actual) + => ReferenceEquals(notExpected, actual); + + [DoesNotReturn] + private static void FailAreNotSame(string userMessage) + => ThrowAssertFailed("Assert.AreNotSame", userMessage); } diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 876e2ac672..0324d2a631 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -12,6 +12,16 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolate Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AssertAreNotSameInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AssertAreNotSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void @@ -86,6 +96,8 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? n static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, System.Collections.Generic.IEqualityComparer? comparer, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotSame(T? notExpected, T? actual, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreSame(T? expected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler message) -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt index 29c1f21f45..1144679b37 100644 --- a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -1,6 +1,8 @@ #nullable enable Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void From 3ed20e8fafde0bce53866acd4b9af550dc69f8c0 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 13:46:44 +0100 Subject: [PATCH 16/46] Fix formatting --- src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 7dcc0acbf5..53510f0bdd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -12,7 +12,6 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { - [InterpolatedStringHandler] [EditorBrowsable(EditorBrowsableState.Never)] public readonly struct AssertAreSameInterpolatedStringHandler From 41392d317a656803cc1e17dcca3a5a6a4590f901 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 14:14:18 +0100 Subject: [PATCH 17/46] Better coverage for IsTrue/IsFalse --- .../Assertions/AssertTests.IsTrueTests.cs | 221 +++++++++++++++++- 1 file changed, 219 insertions(+), 2 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 437a0919f9..498884e907 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -7,18 +7,235 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; public partial class AssertTests { - public void IsFalseNullableBooleansShouldFailWithNull() + public void IsFalseNullableBooleanShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool)); Verify(ex.Message.Contains("Assert.IsFalse failed")); } - public void IsTrueNullableBooleansShouldFailWithNull() + public void IsFalseNullableBooleanShouldFailWithTrue() + { + bool? nullBool = true; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool)); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanShouldNotFailWithFalse() + { + bool? nullBool = false; + Assert.IsFalse(nullBool); + } + + public void IsFalseBooleanShouldFailWithTrue() + { + Exception ex = VerifyThrows(() => Assert.IsFalse(true)); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseBooleanShouldNotFailWithFalse() + => Assert.IsFalse(false); + + public void IsFalseNullableBooleanStringMessageShouldFailWithNull() + { + bool? nullBool = null; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message")); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() + { + bool? nullBool = true; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message")); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanStringMessageShouldNotFailWithFalse() + { + bool? nullBool = false; + Assert.IsFalse(nullBool, "User-provided message"); + } + + public void IsFalseBooleanStringMessageShouldFailWithTrue() + { + Exception ex = VerifyThrows(() => Assert.IsFalse(true, "User-provided message")); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseBooleanStringMessageShouldNotFailWithFalse() + => Assert.IsFalse(false, "User-provided message"); + + public void IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithNull() + { + bool? nullBool = null; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}")); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithTrue() + { + bool? nullBool = true; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}")); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanInterpolatedStringMessageShouldNotFailWithFalse() + { + bool? nullBool = false; + Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}"); + } + + public void IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() + { + Exception ex = VerifyThrows(() => Assert.IsFalse(true, $"User-provided message. Input: {true}")); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseBooleanInterpolatedStringMessageShouldNotFailWithFalse() + => Assert.IsFalse(false, $"User-provided message. Input: {false}"); + + public void IsFalseNullableBooleanMessageArgsShouldFailWithNull() { bool? nullBool = null; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message. Input: {0}", nullBool)); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanMessageArgsShouldFailWithTrue() + { + bool? nullBool = true; + Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message. Input: {0}", nullBool)); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseNullableBooleanMessageArgsShouldNotFailWithFalse() + { + bool? nullBool = false; + Assert.IsFalse(nullBool, "User-provided message. Input: {0}", nullBool); + } + public void IsFalseBooleanMessageArgsShouldFailWithTrue() + { + Exception ex = VerifyThrows(() => Assert.IsFalse(true, "User-provided message. Input: {0}", true)); + Verify(ex.Message.Contains("Assert.IsFalse failed")); + } + + public void IsFalseBooleanMessageArgsShouldNotFailWithFalse() + => Assert.IsFalse(false, "User-provided message. Input: {0}", false); + + public void IsTrueNullableBooleanShouldFailWithNull() + { + bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool)); Verify(ex.Message.Contains("Assert.IsTrue failed")); } + + public void IsTrueNullableBooleanShouldFailWithFalse() + { + bool? nullBool = false; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool)); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanShouldNotFailWithTrue() + { + bool? nullBool = true; + Assert.IsTrue(nullBool); + } + + public void IsTrueBooleanShouldFailWithFalse() + { + Exception ex = VerifyThrows(() => Assert.IsTrue(false)); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueBooleanShouldNotFailWithTrue() + => Assert.IsTrue(true); + + public void IsTrueNullableBooleanStringMessageShouldFailWithNull() + { + bool? nullBool = null; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message")); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() + { + bool? nullBool = false; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message")); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanStringMessageShouldNotFailWithTrue() + { + bool? nullBool = true; + Assert.IsTrue(nullBool, "User-provided message"); + } + + public void IsTrueBooleanStringMessageShouldFailWithFalse() + { + Exception ex = VerifyThrows(() => Assert.IsTrue(false, "User-provided message")); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueBooleanStringMessageShouldNotFailWithTrue() + => Assert.IsTrue(true, "User-provided message"); + + public void IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNull() + { + bool? nullBool = null; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}")); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFalse() + { + bool? nullBool = false; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}")); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanInterpolatedStringMessageShouldNotFailWithTrue() + { + bool? nullBool = true; + Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}"); + } + + public void IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() + { + Exception ex = VerifyThrows(() => Assert.IsTrue(false, $"User-provided message. Input: {false}")); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueBooleanInterpolatedStringMessageShouldNotFailWithTrue() + => Assert.IsTrue(true, $"User-provided message. Input: {true}"); + + public void IsTrueNullableBooleanMessageArgsShouldFailWithNull() + { + bool? nullBool = null; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message. Input: {0}", nullBool)); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanMessageArgsShouldFailWithFalse() + { + bool? nullBool = false; + Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message. Input: {0}", nullBool)); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueNullableBooleanMessageArgsShouldNotFailWithTrue() + { + bool? nullBool = true; + Assert.IsTrue(nullBool, "User-provided message. Input: {0}", nullBool); + } + + public void IsTrueBooleanMessageArgsShouldFailWithFalse() + { + Exception ex = VerifyThrows(() => Assert.IsTrue(false, "User-provided message. Input: {0}", false)); + Verify(ex.Message.Contains("Assert.IsTrue failed")); + } + + public void IsTrueBooleanMessageArgsShouldNotFailWithTrue() + => Assert.IsTrue(true, "User-provided message. Input: {0}", true); } From 60cd5addef726986576b5bd31241b90ed0d8a920 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 14:27:07 +0100 Subject: [PATCH 18/46] Better coverage --- .../Assertions/AssertTests.IsTrueTests.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 498884e907..70d6b7652e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -11,14 +11,14 @@ public void IsFalseNullableBooleanShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool)); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. "); } public void IsFalseNullableBooleanShouldFailWithTrue() { bool? nullBool = true; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool)); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. "); } public void IsFalseNullableBooleanShouldNotFailWithFalse() @@ -30,7 +30,7 @@ public void IsFalseNullableBooleanShouldNotFailWithFalse() public void IsFalseBooleanShouldFailWithTrue() { Exception ex = VerifyThrows(() => Assert.IsFalse(true)); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. "); } public void IsFalseBooleanShouldNotFailWithFalse() @@ -40,14 +40,14 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message")); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message"); } public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() { bool? nullBool = true; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message")); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message"); } public void IsFalseNullableBooleanStringMessageShouldNotFailWithFalse() @@ -59,7 +59,7 @@ public void IsFalseNullableBooleanStringMessageShouldNotFailWithFalse() public void IsFalseBooleanStringMessageShouldFailWithTrue() { Exception ex = VerifyThrows(() => Assert.IsFalse(true, "User-provided message")); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message"); } public void IsFalseBooleanStringMessageShouldNotFailWithFalse() @@ -69,14 +69,14 @@ public void IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: "); } public void IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithTrue() { bool? nullBool = true; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: True"); } public void IsFalseNullableBooleanInterpolatedStringMessageShouldNotFailWithFalse() @@ -88,7 +88,7 @@ public void IsFalseNullableBooleanInterpolatedStringMessageShouldNotFailWithFals public void IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() { Exception ex = VerifyThrows(() => Assert.IsFalse(true, $"User-provided message. Input: {true}")); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: True"); } public void IsFalseBooleanInterpolatedStringMessageShouldNotFailWithFalse() @@ -98,14 +98,14 @@ public void IsFalseNullableBooleanMessageArgsShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message. Input: {0}", nullBool)); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: "); } public void IsFalseNullableBooleanMessageArgsShouldFailWithTrue() { bool? nullBool = true; Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, "User-provided message. Input: {0}", nullBool)); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: True"); } public void IsFalseNullableBooleanMessageArgsShouldNotFailWithFalse() @@ -117,7 +117,7 @@ public void IsFalseNullableBooleanMessageArgsShouldNotFailWithFalse() public void IsFalseBooleanMessageArgsShouldFailWithTrue() { Exception ex = VerifyThrows(() => Assert.IsFalse(true, "User-provided message. Input: {0}", true)); - Verify(ex.Message.Contains("Assert.IsFalse failed")); + Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: True"); } public void IsFalseBooleanMessageArgsShouldNotFailWithFalse() @@ -127,14 +127,14 @@ public void IsTrueNullableBooleanShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool)); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. "); } public void IsTrueNullableBooleanShouldFailWithFalse() { bool? nullBool = false; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool)); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. "); } public void IsTrueNullableBooleanShouldNotFailWithTrue() @@ -146,7 +146,7 @@ public void IsTrueNullableBooleanShouldNotFailWithTrue() public void IsTrueBooleanShouldFailWithFalse() { Exception ex = VerifyThrows(() => Assert.IsTrue(false)); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. "); } public void IsTrueBooleanShouldNotFailWithTrue() @@ -156,14 +156,14 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message")); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message"); } public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() { bool? nullBool = false; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message")); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message"); } public void IsTrueNullableBooleanStringMessageShouldNotFailWithTrue() @@ -175,7 +175,7 @@ public void IsTrueNullableBooleanStringMessageShouldNotFailWithTrue() public void IsTrueBooleanStringMessageShouldFailWithFalse() { Exception ex = VerifyThrows(() => Assert.IsTrue(false, "User-provided message")); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message"); } public void IsTrueBooleanStringMessageShouldNotFailWithTrue() @@ -185,14 +185,14 @@ public void IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: "); } public void IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFalse() { bool? nullBool = false; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: False"); } public void IsTrueNullableBooleanInterpolatedStringMessageShouldNotFailWithTrue() @@ -204,7 +204,7 @@ public void IsTrueNullableBooleanInterpolatedStringMessageShouldNotFailWithTrue( public void IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() { Exception ex = VerifyThrows(() => Assert.IsTrue(false, $"User-provided message. Input: {false}")); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: False"); } public void IsTrueBooleanInterpolatedStringMessageShouldNotFailWithTrue() @@ -214,14 +214,14 @@ public void IsTrueNullableBooleanMessageArgsShouldFailWithNull() { bool? nullBool = null; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message. Input: {0}", nullBool)); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: "); } public void IsTrueNullableBooleanMessageArgsShouldFailWithFalse() { bool? nullBool = false; Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, "User-provided message. Input: {0}", nullBool)); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: False"); } public void IsTrueNullableBooleanMessageArgsShouldNotFailWithTrue() @@ -233,7 +233,7 @@ public void IsTrueNullableBooleanMessageArgsShouldNotFailWithTrue() public void IsTrueBooleanMessageArgsShouldFailWithFalse() { Exception ex = VerifyThrows(() => Assert.IsTrue(false, "User-provided message. Input: {0}", false)); - Verify(ex.Message.Contains("Assert.IsTrue failed")); + Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: False"); } public void IsTrueBooleanMessageArgsShouldNotFailWithTrue() From 56a258d5b50f1afe9fdc96834c6b081099faa1ed Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 15:03:13 +0100 Subject: [PATCH 19/46] Refactor Assert.Throws in preparation for interpolated string handler support --- .../Assertions/Assert.ThrowsException.cs | 155 ++++++++++++------ 1 file changed, 103 insertions(+), 52 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index e926389093..06de8eb6c3 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -229,41 +229,18 @@ private static TException ThrowsException(Action action, bool isStri Guard.NotNull(action); Guard.NotNull(message); - string userMessage, finalMessage; - try + ThrowsExceptionState state = IsThrowsFailing(action, isStrictType, assertMethodName); + if (state.FailAction is not null) { - action(); + state.FailAction(BuildUserMessage(message, parameters)); } - catch (Exception ex) + else { - bool isExceptionOfType = isStrictType - ? typeof(TException) == ex.GetType() - : ex is TException; - if (!isExceptionOfType) - { - userMessage = BuildUserMessage(message, parameters); - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.WrongExceptionThrown, - userMessage, - typeof(TException), - ex.GetType()); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); - } - - return (TException)ex; + return (TException)state.ExceptionWhenNotFailing!; } - userMessage = BuildUserMessage(message, parameters); - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.NoExceptionThrown, - userMessage, - typeof(TException)); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); - // This will not hit, but need it for compiler. - return null; + return null!; } /// @@ -398,7 +375,23 @@ private static async Task ThrowsExceptionAsync(Func(action, isStrictType, assertMethodName).ConfigureAwait(false); + if (state.FailAction is not null) + { + state.FailAction(BuildUserMessage(message, parameters)); + } + else + { + return (TException)state.ExceptionWhenNotFailing!; + } + + // This will not hit, but need it for compiler. + return null!; + } + + private static async Task IsThrowsAsyncFailingAsync(Func action, bool isStrictType, string assertMethodName) + where TException : Exception + { try { await action().ConfigureAwait(false); @@ -409,30 +402,88 @@ private static async Task ThrowsExceptionAsync(Func + { + string finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.WrongExceptionThrown, + userMessage, + typeof(TException), + ex.GetType()); + ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + }); } - userMessage = BuildUserMessage(message, parameters); - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.NoExceptionThrown, - userMessage, - typeof(TException)); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + return ThrowsExceptionState.CreateFailingState(failAction: userMessage => + { + string finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.NoExceptionThrown, + userMessage, + typeof(TException)); + ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + }); + } - // This will not hit, but need it for compiler. - return null!; + private static ThrowsExceptionState IsThrowsFailing(Action action, bool isStrictType, string assertMethodName) + where TException : Exception + { + try + { + action(); + } + catch (Exception ex) + { + bool isExceptionOfType = isStrictType + ? typeof(TException) == ex.GetType() + : ex is TException; + + return isExceptionOfType + ? ThrowsExceptionState.CreateNotFailingState(ex) + : ThrowsExceptionState.CreateFailingState(userMessage => + { + string finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.WrongExceptionThrown, + userMessage, + typeof(TException), + ex.GetType()); + ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + }); + } + + return ThrowsExceptionState.CreateFailingState(failAction: userMessage => + { + string finalMessage = string.Format( + CultureInfo.CurrentCulture, + FrameworkMessages.NoExceptionThrown, + userMessage, + typeof(TException)); + ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + }); + } + + private readonly struct ThrowsExceptionState + { + public Exception? ExceptionWhenNotFailing { get; } + + public Action? FailAction { get; } + + private ThrowsExceptionState(Exception? exceptionWhenNotFailing, Action? failAction) + { + // If the assert is failing, failAction should be non-null, and exceptionWhenNotFailing should be null. + // If the assert is not failing, exceptionWhenNotFailing should be non-null, and failAction should be null. + Debug.Assert(exceptionWhenNotFailing is null ^ failAction is null, "Exactly one of exceptionWhenNotFailing and failAction should be null."); + ExceptionWhenNotFailing = exceptionWhenNotFailing; + FailAction = failAction; + } + + public static ThrowsExceptionState CreateFailingState(Action failAction) + => new(exceptionWhenNotFailing: null, failAction); + + public static ThrowsExceptionState CreateNotFailingState(Exception exception) + => new(exception, failAction: null); } } From 15731f0afc76b0333a11f93a484735cdd2bd26dd Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 15:14:54 +0100 Subject: [PATCH 20/46] Progress for Assert.Throws/ThrowsExactly --- .../Assertions/Assert.ThrowsException.cs | 98 ++++++++++++++++++- .../PublicAPI/PublicAPI.Unshipped.txt | 12 +++ .../PublicAPI/net/PublicAPI.Unshipped.txt | 2 + 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 06de8eb6c3..9086e5b8b0 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -12,6 +12,90 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// public sealed partial class Assert { + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertNonStrictThrowsInterpolatedStringHandler + where TException : Exception + { + private readonly StringBuilder? _builder; + private readonly ThrowsExceptionState _state; + + public AssertNonStrictThrowsInterpolatedStringHandler(int literalLength, int formattedCount, Action action, out bool shouldAppend) + { + ThrowsExceptionState state = IsThrowsFailing(action, isStrictType: false, "Throws"); + shouldAppend = state.FailAction is not null; + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal TException FailIfNeeded() + { + if (_state.FailAction is not null) + { + _state.FailAction(_builder!.ToString()); + } + else + { + return (TException)_state.ExceptionWhenNotFailing!; + } + + // This will not hit, but need it for compiler. + return null!; + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertThrowsExactlyInterpolatedStringHandler + where TException : Exception + { + private readonly StringBuilder? _builder; + private readonly ThrowsExceptionState _state; + + public AssertThrowsExactlyInterpolatedStringHandler(int literalLength, int formattedCount, Action action, out bool shouldAppend) + { + ThrowsExceptionState state = IsThrowsFailing(action, isStrictType: true, "ThrowsExactly"); + shouldAppend = state.FailAction is not null; + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal TException FailIfNeeded() + { + if (_state.FailAction is not null) + { + _state.FailAction(_builder!.ToString()); + } + else + { + return (TException)_state.ExceptionWhenNotFailing!; + } + + // This will not hit, but need it for compiler. + return null!; + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + /// /// Asserts that the delegate throws an exception of type /// (or derived type) and throws AssertFailedException if code does not throws exception or throws @@ -39,6 +123,12 @@ public static TException Throws(Action action, string message = "", where TException : Exception => ThrowsException(action, isStrictType: false, message, parameters: messageArgs); +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static TException Throws(Action action, [InterpolatedStringHandlerArgument(nameof(action))] AssertNonStrictThrowsInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + where TException : Exception + => message.FailIfNeeded(); + /// /// Asserts that the delegate throws an exception of type /// (and not of derived type) and throws AssertFailedException if code does not throws exception or throws @@ -66,6 +156,12 @@ public static TException ThrowsExactly(Action action, string message where TException : Exception => ThrowsException(action, isStrictType: true, message, parameters: messageArgs); +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static TException ThrowsExactly(Action action, [InterpolatedStringHandlerArgument(nameof(action))] AssertThrowsExactlyInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + where TException : Exception + => message.FailIfNeeded(); + /// /// Tests whether the code specified by delegate throws exact given exception /// of type (and not of derived type) and throws AssertFailedException @@ -428,7 +524,7 @@ private static async Task IsThrowsAsyncFailingAsync(Action action, bool isStrictType, string assertMethodName) - where TException : Exception + where TException : Exception { try { diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 0324d2a631..862e9c818b 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -72,6 +72,16 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualI Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, long notExpected, long actual, long delta, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AssertNonStrictThrowsInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AssertNonStrictThrowsInterpolatedStringHandler(int literalLength, int formattedCount, System.Action! action, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AssertThrowsExactlyInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AssertThrowsExactlyInterpolatedStringHandler(int literalLength, int formattedCount, System.Action! action, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataSourceType dynamicDataSourceType) -> void Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataAttribute(string! dynamicDataSourceName, System.Type! dynamicDataDeclaringType) -> void @@ -104,7 +114,9 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(object? val static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler message) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler message) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactlyAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt index 1144679b37..e9bed4a2f8 100644 --- a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -11,3 +11,5 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStri Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void From 715bb309756a1e41efa9a640ade920555fc2e6dc Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 17:56:09 +0100 Subject: [PATCH 21/46] Fix missing assignment to _state --- .../TestFramework/Assertions/Assert.ThrowsException.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 9086e5b8b0..355e219747 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -22,8 +22,8 @@ public readonly struct AssertNonStrictThrowsInterpolatedStringHandler(action, isStrictType: false, "Throws"); - shouldAppend = state.FailAction is not null; + _state = IsThrowsFailing(action, isStrictType: false, "Throws"); + shouldAppend = _state.FailAction is not null; if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); @@ -64,8 +64,8 @@ public readonly struct AssertThrowsExactlyInterpolatedStringHandler public AssertThrowsExactlyInterpolatedStringHandler(int literalLength, int formattedCount, Action action, out bool shouldAppend) { - ThrowsExceptionState state = IsThrowsFailing(action, isStrictType: true, "ThrowsExactly"); - shouldAppend = state.FailAction is not null; + _state = IsThrowsFailing(action, isStrictType: true, "ThrowsExactly"); + shouldAppend = _state.FailAction is not null; if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); From 409afc169dbda4df281202369b9a7bf0726b6791 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 18:21:27 +0100 Subject: [PATCH 22/46] Test coverage for AreSame/AreNotSame --- .../Assertions/AssertTests.AreSame.cs | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs new file mode 100644 index 0000000000..a619f6b00d --- /dev/null +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -0,0 +1,118 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#nullable enable + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; + +public partial class AssertTests +{ + private sealed class DummyClassTrackingToStringCalls + { + public bool WasToStringCalled { get; private set; } + + public override string ToString() + { + WasToStringCalled = true; + return nameof(DummyClassTrackingToStringCalls); + } + } + + public void AreSame_PassSameObject_ShouldPass() + { + object o = new(); + Assert.AreSame(o, o); + } + + public void AreSame_PassDifferentObject_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.AreSame(new object(), new object())); + Verify(ex.Message == "Assert.AreSame failed. "); + } + + public void AreSame_StringMessage_PassSameObject_ShouldPass() + { + object o = new(); + Assert.AreSame(o, o, "User-provided message"); + } + + public void AreSame_StringMessage_PassDifferentObject_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.AreSame(new object(), new object(), "User-provided message")); + Verify(ex.Message == "Assert.AreSame failed. User-provided message"); + } + + public void AreSame_InterpolatedString_PassSameObject_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreSame(o, o, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public void AreSame_InterpolatedString_PassDifferentObject_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.AreSame(new object(), new object(), $"User-provided message. {o}")); + Verify(ex.Message == "Assert.AreSame failed. User-provided message. DummyClassTrackingToStringCalls"); + Verify(o.WasToStringCalled); + } + + public void AreSame_MessageArgs_PassSameObject_ShouldPass() + { + object o = new(); + Assert.AreSame(o, o, "User-provided message: {0}", new object().GetType()); + } + + public void AreSame_MessageArgs_PassDifferentObject_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.AreSame(new object(), new object(), "User-provided message: System.Object type: {0}", new object().GetType())); + Verify(ex.Message == "Assert.AreSame failed. User-provided message: System.Object type: System.Object"); + } + + public void AreNotSame_PassDifferentObject_ShouldPass() + => Assert.AreNotSame(new object(), new object()); + + public void AreNotSame_PassSameObject_ShouldFail() + { + object o = new(); + Exception ex = VerifyThrows(() => Assert.AreNotSame(o, o)); + Verify(ex.Message == "Assert.AreNotSame failed. "); + } + + public void AreNotSame_StringMessage_PassDifferentObject_ShouldPass() + => Assert.AreNotSame(new object(), new object(), "User-provided message"); + + public void AreNotSame_StringMessage_PassSameObject_ShouldFail() + { + object o = new(); + Exception ex = VerifyThrows(() => Assert.AreNotSame(o, o, "User-provided message")); + Verify(ex.Message == "Assert.AreNotSame failed. User-provided message"); + } + + public void AreNotSame_InterpolatedString_PassDifferentObject_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreNotSame(new object(), new object(), $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public void AreNotSame_InterpolatedString_PassSameObject_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.AreNotSame(o, o, $"User-provided message. {o}")); + Verify(ex.Message == "Assert.AreNotSame failed. User-provided message. DummyClassTrackingToStringCalls"); + Verify(o.WasToStringCalled); + } + + public void AreNotSame_MessageArgs_PassDifferentObject_ShouldPass() + => Assert.AreNotSame(new object(), new object(), "User-provided message: {0}", new object().GetType()); + + public void AreNotSame_MessageArgs_PassSameObject_ShouldFail() + { + object o = new(); + Exception ex = VerifyThrows(() => Assert.AreNotSame(o, o, "User-provided message: System.Object type: {0}", new object().GetType())); + Verify(ex.Message == "Assert.AreNotSame failed. User-provided message: System.Object type: System.Object"); + } +} From 9f7780ebc7fc1e106e089c16fb9d4e17cd00b73f Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 18:26:07 +0100 Subject: [PATCH 23/46] Reference Roslyn issue link --- .../TestFramework/Assertions/Assert.AreEqual.cs | 4 ++-- .../TestFramework/Assertions/Assert.IsNull.cs | 4 ++-- .../TestFramework/Assertions/Assert.IsTrue.cs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 750fbfe7d9..deac521a8f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -369,7 +369,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com => AreEqual(expected, actual, comparer, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The comparer parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(T? expected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(comparer))] ref AssertAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); @@ -724,7 +724,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer AreNotEqual(notExpected, actual, comparer, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The comparer parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(comparer))] ref AssertAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index a07230a32b..abe9810ebb 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -107,7 +107,7 @@ public static void IsNull(object? value, string? message) => IsNull(value, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The value parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); @@ -173,7 +173,7 @@ public static void IsNotNull([NotNull] object? value, string? message) => IsNotNull(value, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The value parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsNotNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 30c34e25ca..f1f8e71998 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -120,7 +120,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? messa => IsTrue(condition, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsTrue([DoesNotReturnIf(false)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); @@ -143,7 +143,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? mess => IsTrue(condition, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); @@ -253,7 +253,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? messa => IsFalse(condition, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsFalse([DoesNotReturnIf(true)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); @@ -276,7 +276,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? mess => IsFalse(condition, message, null); /// -#pragma warning disable IDE0060 // Remove unused parameter - false positive. The condition parameter is used via the interpolated string handler. +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); From 271a7ef4fe5c86abf7d9fd99ab947f5940bd8538 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 18:36:55 +0100 Subject: [PATCH 24/46] More AreSame tests --- .../Assertions/AssertTests.AreSame.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index a619f6b00d..0811f67a69 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -74,6 +74,30 @@ public void AreSame_MessageArgs_PassDifferentObject_ShouldFail() public void AreNotSame_PassDifferentObject_ShouldPass() => Assert.AreNotSame(new object(), new object()); + public void AreSame_BothAreValueTypes_ShouldFailWithSpecializedMessage() + { + Exception ex = VerifyThrows(() => Assert.AreSame(1, 1)); + Verify(ex.Message == "Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). "); + } + + public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMessage() + { + Exception ex = VerifyThrows(() => Assert.AreSame(1, 1, "User-provided message")); + Verify(ex.Message == "Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). User-provided message"); + } + + public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializedMessage() + { + Exception ex = VerifyThrows(() => Assert.AreSame(1, 1, $"User-provided message {new object().GetType()}")); + Verify(ex.Message == "Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). User-provided message System.Object"); + } + + public void AreSame_MessageArgs_BothAreValueTypes_ShouldFailWithSpecializedMessage() + { + Exception ex = VerifyThrows(() => Assert.AreSame(1, 1, "User-provided message {0}", new object().GetType())); + Verify(ex.Message == "Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). User-provided message System.Object"); + } + public void AreNotSame_PassSameObject_ShouldFail() { object o = new(); From 4b9c7989eaaff3e25330c1afe78e916dbb41ccee Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 30 Dec 2024 18:57:32 +0100 Subject: [PATCH 25/46] More prgoress --- .../Assertions/Assert.AreEqual.cs | 1 + .../Assertions/Assert.AreSame.cs | 2 +- .../TestFramework/Assertions/Assert.IsNull.cs | 4 +- .../Assertions/Assert.ThrowsException.cs | 6 +- .../PublicAPI/PublicAPI.Unshipped.txt | 6 +- .../Assertions/AssertTests.AreSame.cs | 11 --- .../Assertions/AssertTests.IsNull.cs | 79 ++++++++++++++++++- .../Assertions/AssertTests.cs | 11 +++ 8 files changed, 100 insertions(+), 20 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index deac521a8f..a70c1551e0 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -941,6 +941,7 @@ public static void AreNotEqual(float notExpected, float actual, float delta) public static void AreNotEqual(float notExpected, float actual, float delta, string? message) => AreNotEqual(notExpected, actual, delta, message, null); + /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(float notExpected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 53510f0bdd..0c62ebdb07 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -234,7 +234,7 @@ public static void AreNotSame(T? notExpected, T? actual, string? message) /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 - public static void AreNotSame(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] AssertAreNotSameInterpolatedStringHandler message) + public static void AreNotSame(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] ref AssertAreNotSameInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter => message.FailIfNeeded(); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index abe9810ebb..f154f0ded7 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -174,9 +174,11 @@ public static void IsNotNull([NotNull] object? value, string? message) /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 - public static void IsNotNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) + public static void IsNotNull([NotNull] object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter +#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. => message.FailIfNeeded(); +#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. /// /// Tests whether the specified object is non-null and throws an exception diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 355e219747..23c34e8660 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -123,8 +123,9 @@ public static TException Throws(Action action, string message = "", where TException : Exception => ThrowsException(action, isStrictType: false, message, parameters: messageArgs); + /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 - public static TException Throws(Action action, [InterpolatedStringHandlerArgument(nameof(action))] AssertNonStrictThrowsInterpolatedStringHandler message) + public static TException Throws(Action action, [InterpolatedStringHandlerArgument(nameof(action))] ref AssertNonStrictThrowsInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter where TException : Exception => message.FailIfNeeded(); @@ -156,8 +157,9 @@ public static TException ThrowsExactly(Action action, string message where TException : Exception => ThrowsException(action, isStrictType: true, message, parameters: messageArgs); + /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 - public static TException ThrowsExactly(Action action, [InterpolatedStringHandlerArgument(nameof(action))] AssertThrowsExactlyInterpolatedStringHandler message) + public static TException ThrowsExactly(Action action, [InterpolatedStringHandlerArgument(nameof(action))] ref AssertThrowsExactlyInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter where TException : Exception => message.FailIfNeeded(); diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 862e9c818b..8772760a0d 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -106,7 +106,7 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? n static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(T? notExpected, T? actual, System.Collections.Generic.IEqualityComparer? comparer, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotSame(T? notExpected, T? actual, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotSame(T? notExpected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreSame(T? expected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void @@ -114,9 +114,9 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(object? val static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler message) -> TException! +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler message) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Throws(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! -static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler message) -> TException! +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler message) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactly(System.Action! action, string! message = "", params object![]! messageArgs) -> TException! static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExactlyAsync(System.Func! action, string! message = "", params object![]! messageArgs) -> System.Threading.Tasks.Task! diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 0811f67a69..ca11dd4a33 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -9,17 +9,6 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; public partial class AssertTests { - private sealed class DummyClassTrackingToStringCalls - { - public bool WasToStringCalled { get; private set; } - - public override string ToString() - { - WasToStringCalled = true; - return nameof(DummyClassTrackingToStringCalls); - } - } - public void AreSame_PassSameObject_ShouldPass() { object o = new(); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index bec3b88580..e2ebe13410 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -7,10 +7,52 @@ using TestFramework.ForTestingMSTest; -namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.Assertions; +namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; public partial class AssertTests : TestContainer { + public void IsNull_PassNull_ShouldPass() + => Assert.IsNull(null); + + public void IsNull_PassNonNull_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.IsNull(new object())); + Verify(ex.Message == "Assert.IsNull failed. "); + } + + public void IsNull_StringMessage_PassNull_ShouldPass() + => Assert.IsNull(null, "User-provided message"); + + public void IsNull_StringMessage_PassNonNull_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.IsNull(new object(), "User-provided message")); + Verify(ex.Message == "Assert.IsNull failed. User-provided message"); + } + + public void IsNull_InterpolatedString_PassNull_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.IsNull(null, $"User-provided message {o}"); + Verify(!o.WasToStringCalled); + } + + public void IsNull_InterpolatedString_PassNonNull_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.IsNull(new object(), $"User-provided message {o}")); + Verify(ex.Message == "Assert.IsNull failed. User-provided message DummyClassTrackingToStringCalls"); + Verify(o.WasToStringCalled); + } + + public void IsNull_MessageFormat_PassNull_ShouldPass() + => Assert.IsNull(null, "User-provided message {0}", new object().GetType()); + + public void IsNull_MessageFormat_PassNonNull_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.IsNull(new object(), "User-provided message {0}", new object().GetType())); + Verify(ex.Message == "Assert.IsNull failed. User-provided message System.Object"); + } + public void IsNotNull_WhenNonNullNullableValue_DoesNotThrowAndLearnNotNull() { object? obj = GetObj(); @@ -25,6 +67,15 @@ public void IsNotNull_WhenNonNullNullableValueAndMessage_DoesNotThrowAndLearnNot _ = obj.ToString(); // No potential NRE warning } + public void IsNotNull_WhenNonNullNullableValueAndInterpolatedStringMessage_DoesNotThrowAndLearnNotNull() + { + object? obj = GetObj(); + DummyClassTrackingToStringCalls o = new(); + Assert.IsNotNull(obj, $"my message {o}"); + Verify(!o.WasToStringCalled); + _ = obj.ToString(); // No potential NRE warning + } + public void IsNotNull_WhenNonNullNullableValueAndCompositeMessage_DoesNotThrowAndLearnNotNull() { object? obj = GetObj(); @@ -32,5 +83,29 @@ public void IsNotNull_WhenNonNullNullableValueAndCompositeMessage_DoesNotThrowAn _ = obj.ToString(); // No potential NRE warning } - private object? GetObj() => new(); + public void IsNotNull_PassNull_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.IsNotNull(null)); + Verify(ex.Message == "Assert.IsNotNull failed. "); + } + + public void IsNotNull_StringMessage_PassNonNull_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.IsNotNull(null, "User-provided message")); + Verify(ex.Message == "Assert.IsNotNull failed. User-provided message"); + } + + public void IsNotNull_InterpolatedString_PassNonNull_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.IsNotNull(null, $"User-provided message {o}")); + Verify(ex.Message == "Assert.IsNotNull failed. User-provided message DummyClassTrackingToStringCalls"); + Verify(o.WasToStringCalled); + } + + public void IsNotNull_MessageFormat_PassNonNull_ShouldFail() + { + Exception ex = VerifyThrows(() => Assert.IsNotNull(null, "User-provided message {0}", new object().GetType())); + Verify(ex.Message == "Assert.IsNotNull failed. User-provided message System.Object"); + } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 8b3584fc46..21023dadfb 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -39,4 +39,15 @@ public void BuildUserMessageDoesNotThrowWhenMessageContainsInvalidStringFormatCo Verify(message == "{"); } #endregion + + private sealed class DummyClassTrackingToStringCalls + { + public bool WasToStringCalled { get; private set; } + + public override string ToString() + { + WasToStringCalled = true; + return nameof(DummyClassTrackingToStringCalls); + } + } } From cecdbc5715fa07bbe8a566960b00181bbca08f9f Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 31 Dec 2024 06:12:23 +0100 Subject: [PATCH 26/46] Missing changes for IsInstanceOf --- .../Assertions/Assert.IsInstanceOfType.cs | 107 ++++++++++++++++++ .../PublicAPI/PublicAPI.Unshipped.txt | 15 +++ .../PublicAPI/net/PublicAPI.Unshipped.txt | 2 + 3 files changed, 124 insertions(+) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 0adf8b68bd..bd1b63f1a5 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -43,6 +43,40 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertGenericIsInstanceOfTypeInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + private readonly object? _value; + + public AssertGenericIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) + { + _value = value; + shouldAppend = IsInstanceOfTypeFailing(value, typeof(TArg)); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsInstanceOfType(_value, typeof(TArg), _builder.ToString()); + } + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + #if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif @@ -79,6 +113,40 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); +#if NETCOREAPP3_1_OR_GREATER + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); +#endif + } + + [InterpolatedStringHandler] + [EditorBrowsable(EditorBrowsableState.Never)] + public readonly struct AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler + { + private readonly StringBuilder? _builder; + private readonly object? _value; + + public AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) + { + _value = value; + shouldAppend = IsNotInstanceOfTypeFailing(value, typeof(TArg)); + if (shouldAppend) + { + _builder = new StringBuilder(literalLength + formattedCount); + } + } + + internal void FailIfNeeded() + { + if (_builder is not null) + { + FailIsNotInstanceOfType(_value, typeof(TArg), _builder.ToString()); + } + } + + public readonly void AppendLiteral(string value) => _builder!.Append(value); + + public readonly void AppendFormatted(T value) => _builder!.Append(value); + #if NETCOREAPP3_1_OR_GREATER public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); #endif @@ -145,6 +213,14 @@ public static void IsInstanceOfType([NotNull] object? value, out T instance) public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? expectedType, string? message) => IsInstanceOfType(value, expectedType, message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? expectedType, [InterpolatedStringHandlerArgument(nameof(value), nameof(expectedType))] ref AssertIsInstanceOfTypeInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter +#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. + => message.FailIfNeeded(); +#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + /// /// Tests whether the specified object is an instance of the generic /// type and throws an exception if the generic type is not in the @@ -154,6 +230,14 @@ public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? exp public static void IsInstanceOfType([NotNull] object? value, string? message) => IsInstanceOfType(value, typeof(T), message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static void IsInstanceOfType([NotNull] object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertGenericIsInstanceOfTypeInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter +#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. + => message.FailIfNeeded(); +#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + /// /// Tests whether the specified object is an instance of the generic /// type and throws an exception if the generic type is not in the @@ -163,6 +247,15 @@ public static void IsInstanceOfType([NotNull] object? value, string? message) public static void IsInstanceOfType([NotNull] object? value, out T instance, string? message) => IsInstanceOfType(value, out instance, message, null); + /// + public static void IsInstanceOfType([NotNull] object? value, out T instance, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertGenericIsInstanceOfTypeInterpolatedStringHandler message) +#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. + { + message.FailIfNeeded(); + instance = (T)value!; + } +#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + /// /// Tests whether the specified object is an instance of the expected /// type and throws an exception if the expected type is not in the @@ -291,6 +384,14 @@ public static void IsNotInstanceOfType(object? value) public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, string? message) => IsNotInstanceOfType(value, wrongType, message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, [InterpolatedStringHandlerArgument(nameof(value), nameof(wrongType))] ref AssertIsNotInstanceOfTypeInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter +#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. + => message.FailIfNeeded(); +#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + /// /// Tests whether the specified object is not an instance of the wrong generic /// type and throws an exception if the specified type is in the @@ -300,6 +401,12 @@ public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, public static void IsNotInstanceOfType(object? value, string? message) => IsNotInstanceOfType(value, typeof(T), message, null); + /// +#pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 + public static void IsNotInstanceOfType(object? value, [InterpolatedStringHandlerArgument(nameof(value))] AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler message) +#pragma warning restore IDE0060 // Remove unused parameter + => message.FailIfNeeded(); + /// /// Tests whether the specified object is not an instance of the wrong /// type and throws an exception if the specified type is in the diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 8772760a0d..a044e88224 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -22,6 +22,16 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStr Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AssertGenericIsInstanceOfTypeInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AssertGenericIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler() -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void @@ -110,6 +120,11 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotSame(T? notE static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreSame(T? expected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(bool? condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType(object? value, System.Type? expectedType, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType(object? value, out T instance, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotInstanceOfType(object? value, System.Type? wrongType, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler message) -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotInstanceOfType(object? value, Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNull(object? value, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler message) -> void static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(bool condition, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler message) -> void diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt index e9bed4a2f8..a6b7bbe2f2 100644 --- a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -3,6 +3,8 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedSt Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void From f6753aaee9c6b2c87a88e32adba27eb82e77dba0 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 31 Dec 2024 06:28:55 +0100 Subject: [PATCH 27/46] Little more coverage for IsInstanceOfType --- .../AssertTests.IsInstanceOfTypeTests.cs | 91 +++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index fc2d51bf56..639920359e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -10,16 +10,80 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; [SuppressMessage("Usage", "CA2263:Prefer generic overload when type is known", Justification = "We want to test also the non-generic API")] public partial class AssertTests { - public void InstanceOfTypeShouldFailWhenValueIsNull() => - VerifyThrows(() => Assert.IsInstanceOfType(null, typeof(AssertTests))); + public void InstanceOfTypeShouldFailWhenValueIsNull() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(null, typeof(AssertTests))); + Verify(ex.Message == "Assert.IsInstanceOfType failed. "); + } + + public void InstanceOfTypeShouldFailWhenTypeIsNull() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, null)); + Verify(ex.Message == "Assert.IsInstanceOfType failed. "); + } - public void InstanceOfTypeShouldFailWhenTypeIsNull() => - VerifyThrows(() => Assert.IsInstanceOfType(5, null)); + public void InstanceOfTypeShouldFailWhenTypeIsMismatched() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, typeof(string))); + Verify(ex.Message == "Assert.IsInstanceOfType failed. Expected type:. Actual type:."); + } public void InstanceOfTypeShouldPassOnSameInstance() => Assert.IsInstanceOfType(5, typeof(int)); public void InstanceOfTypeShouldPassOnHigherInstance() => Assert.IsInstanceOfType(5, typeof(object)); + public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(null, typeof(AssertTests), "User-provided message")); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message"); + } + + public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, null, "User-provided message")); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message"); + } + + public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, typeof(string), "User-provided message")); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message Expected type:. Actual type:."); + } + + public void InstanceOfType_WithStringMessage_ShouldPassWhenTypeIsCorrect() + => Assert.IsInstanceOfType(5, typeof(int), "User-provided message"); + + public void InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNull() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message {o}")); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls"); + Verify(o.WasToStringCalled); + } + + public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, null, $"User-provided message {o}")); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message"); + Verify(o.WasToStringCalled); + } + + public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched() + { + DummyClassTrackingToStringCalls o = new(); + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, typeof(string), $"User-provided message {o}")); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message Expected type:. Actual type:."); + Verify(o.WasToStringCalled); + } + + public void InstanceOfType_WithInterpolatedString_ShouldPassWhenTypeIsCorrect() + { + DummyClassTrackingToStringCalls o = new(); + Assert.IsInstanceOfType(5, typeof(int), $"User-provided message {o}"); + Verify(!o.WasToStringCalled); + } + public void InstanceNotOfTypeShouldFailWhenValueIsNull() => Assert.IsNotInstanceOfType(null, typeof(object)); public void InstanceNotOfTypeShouldFailWhenTypeIsNull() => @@ -30,8 +94,17 @@ public void InstanceNotOfTypeShouldFailWhenTypeIsNull() => public void InstanceNotOfTypeShouldPassOnSubInstance() => Assert.IsNotInstanceOfType(new object(), typeof(int)); [TestMethod] - public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() => - VerifyThrows(() => Assert.IsInstanceOfType(null)); + public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(null)); + Verify(ex.Message == "Assert.IsInstanceOfType failed. "); + } + + public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5)); + Verify(ex.Message == "Assert.IsInstanceOfType failed. Expected type:. Actual type:."); + } [TestMethod] public void IsInstanceOfTypeUsingGenericTypeWithOutParameter_WhenValueIsNull_Fails() @@ -41,6 +114,12 @@ public void IsInstanceOfTypeUsingGenericTypeWithOutParameter_WhenValueIsNull_Fai Verify(assertTests is null); } + public void IsInstanceOfTypeUsingGenericTypeWithOutParameter_WhenTypeMismatch_Fails() + { + Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, out _)); + Verify(ex.Message == "Assert.IsInstanceOfType failed. Expected type:. Actual type:."); + } + [TestMethod] public void IsInstanceOfTypeUsingGenericType_OnSameInstance_DoesNotThrow() => Assert.IsInstanceOfType(5); From 5fe77b12a419a1e6735cbb34183d8eb5da01067a Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 31 Dec 2024 09:46:42 +0100 Subject: [PATCH 28/46] Fix test --- .../Assertions/AssertTests.IsInstanceOfTypeTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 639920359e..244d658b72 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. #nullable enable @@ -65,7 +65,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() { DummyClassTrackingToStringCalls o = new(); Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, null, $"User-provided message {o}")); - Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message"); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls"); Verify(o.WasToStringCalled); } From 32d15fc490d17fb78ccac6f84c8d0d295c8fb52b Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 31 Dec 2024 10:22:10 +0100 Subject: [PATCH 29/46] Fix test --- .../Assertions/AssertTests.IsInstanceOfTypeTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 244d658b72..764336e288 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. #nullable enable @@ -73,7 +73,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched { DummyClassTrackingToStringCalls o = new(); Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(5, typeof(string), $"User-provided message {o}")); - Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message Expected type:. Actual type:."); + Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls Expected type:. Actual type:."); Verify(o.WasToStringCalled); } From 12a011c61930bd8b0e2337192c9e905be53d2fed Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 31 Dec 2024 16:12:49 +0100 Subject: [PATCH 30/46] Avoid extra ToString --- .../TestFramework/Assertions/Assert.AreEqual.cs | 10 +++++----- .../TestFramework/Assertions/Assert.AreSame.cs | 4 ++-- .../Assertions/Assert.IsInstanceOfType.cs | 8 ++++---- .../TestFramework/Assertions/Assert.IsNull.cs | 4 ++-- .../TestFramework/Assertions/Assert.IsTrue.cs | 4 ++-- .../TestFramework/Assertions/Assert.ThrowsException.cs | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index a70c1551e0..877355abd9 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -14,7 +14,7 @@ public sealed partial class Assert { [InterpolatedStringHandler] [EditorBrowsable(EditorBrowsableState.Never)] - public readonly struct AssertAreEqualInterpolatedStringHandler + public readonly ref struct AssertAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; private readonly object? _expected; @@ -67,7 +67,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -108,7 +108,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -183,7 +183,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -258,7 +258,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 0c62ebdb07..84eff3b4c8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -44,7 +44,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -76,7 +76,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index bd1b63f1a5..623446d5c5 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -44,7 +44,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -78,7 +78,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -114,7 +114,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -148,7 +148,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index f154f0ded7..9765475485 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -40,7 +40,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -72,7 +72,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index f1f8e71998..484c2a587c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -40,7 +40,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -72,7 +72,7 @@ internal void FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 23c34e8660..3c06a302a4 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -50,7 +50,7 @@ internal TException FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -92,7 +92,7 @@ internal TException FailIfNeeded() public readonly void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value.ToString()); + public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } From 38f6c91d7bbd6f3d7b3420e304c7fd455f0460c9 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 31 Dec 2024 16:14:52 +0100 Subject: [PATCH 31/46] Revert temporarily, will apply globally once it's more understood --- src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 877355abd9..4be996dd80 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -14,7 +14,7 @@ public sealed partial class Assert { [InterpolatedStringHandler] [EditorBrowsable(EditorBrowsableState.Never)] - public readonly ref struct AssertAreEqualInterpolatedStringHandler + public readonly struct AssertAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; private readonly object? _expected; From 7795c53b3e2894dd3210ef7f7d2df86ef16f7816 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 31 Dec 2024 16:17:24 +0100 Subject: [PATCH 32/46] Remove redundant readonly --- .../Assertions/Assert.AreEqual.cs | 24 +++++++++---------- .../Assertions/Assert.AreSame.cs | 12 +++++----- .../Assertions/Assert.IsInstanceOfType.cs | 24 +++++++++---------- .../TestFramework/Assertions/Assert.IsNull.cs | 12 +++++----- .../TestFramework/Assertions/Assert.IsTrue.cs | 12 +++++----- .../Assertions/Assert.ThrowsException.cs | 12 +++++----- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 4be996dd80..d13c2827dc 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -62,12 +62,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -103,12 +103,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -178,12 +178,12 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int internal void FailIfNeeded() => _failAction?.Invoke(_builder!.ToString()); - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -253,12 +253,12 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i internal void FailIfNeeded() => _failAction?.Invoke(_builder!.ToString()); - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 84eff3b4c8..0de0726f28 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -39,12 +39,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -71,12 +71,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 623446d5c5..6d2a925650 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -39,12 +39,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -73,12 +73,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -109,12 +109,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -143,12 +143,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 9765475485..30fa76b301 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -35,12 +35,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -67,12 +67,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 484c2a587c..82b84016c1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -35,12 +35,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -67,12 +67,12 @@ internal void FailIfNeeded() } } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 3c06a302a4..4d24f876ec 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -45,12 +45,12 @@ internal TException FailIfNeeded() return null!; } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } @@ -87,12 +87,12 @@ internal TException FailIfNeeded() return null!; } - public readonly void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string value) => _builder!.Append(value); - public readonly void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER - public readonly void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); #endif } From cb56d77499353ac81a05f9508d729d8f1467ca89 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 1 Jan 2025 14:51:29 +0100 Subject: [PATCH 33/46] More AppendFormatted overloads, modulo tests --- .../Assertions/Assert.AreEqual.cs | 77 ++++++++++++++++++- .../Assertions/Assert.AreSame.cs | 36 +++++++++ .../Assertions/Assert.IsInstanceOfType.cs | 72 +++++++++++++++++ .../TestFramework/Assertions/Assert.IsNull.cs | 36 +++++++++ .../TestFramework/Assertions/Assert.IsTrue.cs | 36 +++++++++ .../Assertions/Assert.ThrowsException.cs | 36 +++++++++ 6 files changed, 291 insertions(+), 2 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index d13c2827dc..09559ef965 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -14,7 +14,7 @@ public sealed partial class Assert { [InterpolatedStringHandler] [EditorBrowsable(EditorBrowsableState.Never)] - public readonly struct AssertAreEqualInterpolatedStringHandler + public readonly ref struct AssertAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; private readonly object? _expected; @@ -62,13 +62,32 @@ internal void FailIfNeeded() } } - public void AppendLiteral(string value) => _builder!.Append(value); + public void AppendLiteral(string? value) => _builder!.Append(value); + // TODO (IMPORTANT): Verify that the behavior here is correct with enums, ISpanFormattable, and IFormattable arguments. public void AppendFormatted(T value) => _builder!.Append(value); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -109,7 +128,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -184,7 +221,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -259,7 +314,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 0de0726f28..10d2d88d8f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -45,7 +45,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -77,7 +95,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 6d2a925650..9964024907 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -45,7 +45,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -79,7 +97,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -115,7 +151,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -149,7 +203,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 30fa76b301..e8becd48fa 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -41,7 +41,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -73,7 +91,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 82b84016c1..03336843c6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -41,7 +41,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -73,7 +91,25 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 4d24f876ec..a30fda6127 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -51,7 +51,25 @@ internal TException FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } [InterpolatedStringHandler] @@ -93,7 +111,25 @@ internal TException FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); + + public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); #endif + + // NOTE: All the overloads involving format and/or alignment are not super efficient. + // This code path is only for when an assert is failing, so that's not the common scenario + // and should be okay if not very optimized. + // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to + // the BCL's StringBuilder.AppendInterpolatedStringHandler + // TODO: Is InvariantCulture the right thing to use here? + public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + + public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + + public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); } /// From bffbd6347547e3b95dc83facb2924563eafc13ec Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 1 Jan 2025 16:27:33 +0100 Subject: [PATCH 34/46] Use AppendFormat --- .../Assertions/Assert.AreEqual.cs | 40 +++++++++---------- .../Assertions/Assert.AreSame.cs | 20 +++++----- .../Assertions/Assert.IsInstanceOfType.cs | 40 +++++++++---------- .../TestFramework/Assertions/Assert.IsNull.cs | 20 +++++----- .../TestFramework/Assertions/Assert.IsTrue.cs | 20 +++++----- .../Assertions/Assert.ThrowsException.cs | 20 +++++----- 6 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 09559ef965..c3cdefc8a6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -79,15 +79,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -138,15 +138,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -231,15 +231,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -324,15 +324,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 10d2d88d8f..d93d6f1f9a 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -55,15 +55,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -105,15 +105,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 9964024907..2e0cb5ccbe 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -55,15 +55,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -107,15 +107,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -161,15 +161,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -213,15 +213,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index e8becd48fa..be0837d58a 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -51,15 +51,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -101,15 +101,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 03336843c6..9041ac528c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -51,15 +51,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -101,15 +101,15 @@ internal void FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index a30fda6127..de3d2f0ae6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -61,15 +61,15 @@ internal TException FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } [InterpolatedStringHandler] @@ -121,15 +121,15 @@ internal TException FailIfNeeded() // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0:{format}}}", value)); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value)); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.Append(string.Format(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value)); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); } /// From 15c42ed5098e0752d3ab83265630c5122425b037 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 1 Jan 2025 17:07:04 +0100 Subject: [PATCH 35/46] Fix build --- .../Assertions/Assert.AreEqual.cs | 16 ++++ .../Assertions/Assert.AreSame.cs | 8 ++ .../Assertions/Assert.IsInstanceOfType.cs | 16 ++++ .../TestFramework/Assertions/Assert.IsNull.cs | 8 ++ .../TestFramework/Assertions/Assert.IsTrue.cs | 8 ++ .../Assertions/Assert.ThrowsException.cs | 8 ++ .../PublicAPI/PublicAPI.Unshipped.txt | 82 ++++++++++++++++++- 7 files changed, 145 insertions(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index c3cdefc8a6..16d12393cf 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -85,9 +85,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -144,9 +148,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -237,9 +245,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -330,9 +342,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index d93d6f1f9a..7bba431fb1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -61,9 +61,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -111,9 +115,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 2e0cb5ccbe..84231610bc 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -61,9 +61,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -113,9 +117,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -167,9 +175,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -219,9 +231,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index be0837d58a..60c59b5d6a 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -57,9 +57,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -107,9 +111,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 9041ac528c..abdf122877 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -57,9 +57,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } [InterpolatedStringHandler] @@ -107,9 +111,13 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index de3d2f0ae6..9f2db5ee98 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -67,9 +67,13 @@ internal TException FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters } [InterpolatedStringHandler] @@ -127,9 +131,13 @@ internal TException FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } /// diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index a044e88224..90562d3a33 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,69 +1,134 @@ #nullable enable Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void -Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendLiteral(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, System.IEquatable? expected, System.IEquatable? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AssertAreNotSameInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AssertAreNotSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AssertGenericIsInstanceOfTypeInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AssertGenericIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AssertIsInstanceOfTypeInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AssertIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, System.Type? expectedType, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AssertIsNotInstanceOfTypeInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AssertIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, System.Type? wrongType, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal expected, decimal actual, decimal delta, out bool shouldAppend) -> void @@ -73,7 +138,12 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInte Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, decimal notExpected, decimal actual, decimal delta, out bool shouldAppend) -> void @@ -83,12 +153,22 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualI Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AssertNonStrictThrowsInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AssertNonStrictThrowsInterpolatedStringHandler(int literalLength, int formattedCount, System.Action! action, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value, int alignment, string? format) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value, string? format) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendLiteral(string! value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AssertThrowsExactlyInterpolatedStringHandler() -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AssertThrowsExactlyInterpolatedStringHandler(int literalLength, int formattedCount, System.Action! action, out bool shouldAppend) -> void From 8ec485d4b09964405c6b7ce2625dd76b9913612f Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 1 Jan 2025 17:21:32 +0100 Subject: [PATCH 36/46] Address TODO --- .../Assertions/Assert.AreEqual.cs | 44 +++++++++---------- .../Assertions/Assert.AreSame.cs | 22 +++++----- .../Assertions/Assert.IsInstanceOfType.cs | 44 +++++++++---------- .../TestFramework/Assertions/Assert.IsNull.cs | 22 +++++----- .../TestFramework/Assertions/Assert.IsTrue.cs | 22 +++++----- .../Assertions/Assert.ThrowsException.cs | 22 +++++----- 6 files changed, 80 insertions(+), 96 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 16d12393cf..c83c0a8742 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -78,18 +78,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -141,18 +140,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -238,18 +236,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -335,18 +332,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 7bba431fb1..b9211561ee 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -54,18 +54,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -108,18 +107,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 84231610bc..3565ff24fc 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -54,18 +54,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -110,18 +109,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -168,18 +166,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -224,18 +221,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 60c59b5d6a..d7bbb92202 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -50,18 +50,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -104,18 +103,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index abdf122877..24564408cf 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -50,18 +50,17 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } @@ -104,19 +103,18 @@ internal void FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 9f2db5ee98..db00ac73e4 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -60,18 +60,17 @@ internal TException FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters } @@ -124,18 +123,17 @@ internal TException FailIfNeeded() // and should be okay if not very optimized. // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to // the BCL's StringBuilder.AppendInterpolatedStringHandler - // TODO: Is InvariantCulture the right thing to use here? - public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0:{format}}}", value); + public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); - public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}}}", value); + public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); - public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); - public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(CultureInfo.InvariantCulture, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } From abcf0140e883f8b8550293a768d7ec0bbfdbffa7 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 1 Jan 2025 17:27:26 +0100 Subject: [PATCH 37/46] Fix build --- .../TestFramework/Assertions/Assert.AreEqual.cs | 8 ++++++++ .../TestFramework/Assertions/Assert.AreSame.cs | 4 ++++ .../Assertions/Assert.IsInstanceOfType.cs | 8 ++++++++ .../TestFramework/Assertions/Assert.IsNull.cs | 4 ++++ .../TestFramework/Assertions/Assert.IsTrue.cs | 4 ++++ .../Assertions/Assert.ThrowsException.cs | 4 ++++ .../PublicAPI/net/PublicAPI.Unshipped.txt | 16 ++++++++++++++++ 7 files changed, 48 insertions(+) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index c83c0a8742..53b5ac9999 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -70,7 +70,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -132,7 +134,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -228,7 +232,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -324,7 +330,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index b9211561ee..0b6176636f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -46,7 +46,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -99,7 +101,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 3565ff24fc..f0e0b19f7f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -46,7 +46,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -101,7 +103,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -158,7 +162,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -213,7 +219,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index d7bbb92202..98e79c74b6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -42,7 +42,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -95,7 +97,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 24564408cf..d381d451a1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -42,7 +42,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -95,7 +97,9 @@ internal void FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index db00ac73e4..0cf3f71e21 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -52,7 +52,9 @@ internal TException FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. @@ -115,7 +117,9 @@ internal TException FailIfNeeded() #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); +#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads #endif // NOTE: All the overloads involving format and/or alignment are not super efficient. diff --git a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt index a6b7bbe2f2..9a182b770a 100644 --- a/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/net/PublicAPI.Unshipped.txt @@ -1,17 +1,33 @@ #nullable enable Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(System.ReadOnlySpan value, int alignment = 0, string? format = null) -> void From 672374537ea7d1a286feead78928ce84842570c8 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 08:14:27 +0100 Subject: [PATCH 38/46] Fix build --- .../TestFramework/Assertions/Assert.IsTrue.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index d381d451a1..9180810abb 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -113,12 +113,11 @@ internal void FailIfNeeded() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); -#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads - public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); -#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); -#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters #pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads } From 99d3e8b90bc50712926afcb1681c1a6125e4d058 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 09:00:39 +0100 Subject: [PATCH 39/46] More progress --- .../Assertions/Assert.AreEqual.cs | 8 ++++---- .../Assertions/Assert.AreSame.cs | 4 ++-- .../Assertions/Assert.IsInstanceOfType.cs | 8 ++++---- .../TestFramework/Assertions/Assert.IsNull.cs | 4 ++-- .../TestFramework/Assertions/Assert.IsTrue.cs | 4 ++-- .../Assertions/Assert.ThrowsException.cs | 4 ++-- .../Assertions/AssertTests.AreSame.cs | 16 +++++++++------ .../Assertions/AssertTests.cs | 9 +++++++++ .../TestContainer.cs | 20 +++++++++++++++++++ 9 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 53b5ac9999..8a30fba3f3 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -65,7 +65,7 @@ internal void FailIfNeeded() public void AppendLiteral(string? value) => _builder!.Append(value); // TODO (IMPORTANT): Verify that the behavior here is correct with enums, ISpanFormattable, and IFormattable arguments. - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -129,7 +129,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -227,7 +227,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -325,7 +325,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 0b6176636f..f6bb473a0b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -41,7 +41,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -96,7 +96,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index f0e0b19f7f..d8a41f73c8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -41,7 +41,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -98,7 +98,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -157,7 +157,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -214,7 +214,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 98e79c74b6..53ff468bcd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -37,7 +37,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -92,7 +92,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 9180810abb..e62e42516c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -37,7 +37,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -92,7 +92,7 @@ internal void FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 0cf3f71e21..ae83dbaf68 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -47,7 +47,7 @@ internal TException FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); @@ -112,7 +112,7 @@ internal TException FailIfNeeded() public void AppendLiteral(string value) => _builder!.Append(value); - public void AppendFormatted(T value) => _builder!.Append(value); + public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index ca11dd4a33..45e4582493 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -3,6 +3,8 @@ #nullable enable +using System; + using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; @@ -40,11 +42,12 @@ public void AreSame_InterpolatedString_PassSameObject_ShouldPass() Verify(!o.WasToStringCalled); } - public void AreSame_InterpolatedString_PassDifferentObject_ShouldFail() + public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() { DummyClassTrackingToStringCalls o = new(); - Exception ex = VerifyThrows(() => Assert.AreSame(new object(), new object(), $"User-provided message. {o}")); - Verify(ex.Message == "Assert.AreSame failed. User-provided message. DummyClassTrackingToStringCalls"); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); Verify(o.WasToStringCalled); } @@ -111,11 +114,12 @@ public void AreNotSame_InterpolatedString_PassDifferentObject_ShouldPass() Verify(!o.WasToStringCalled); } - public void AreNotSame_InterpolatedString_PassSameObject_ShouldFail() + public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() { DummyClassTrackingToStringCalls o = new(); - Exception ex = VerifyThrows(() => Assert.AreNotSame(o, o, $"User-provided message. {o}")); - Verify(ex.Message == "Assert.AreNotSame failed. User-provided message. DummyClassTrackingToStringCalls"); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreNotSame(o, o, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreNotSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); Verify(o.WasToStringCalled); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 21023dadfb..49cdeb4897 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -40,6 +40,9 @@ public void BuildUserMessageDoesNotThrowWhenMessageContainsInvalidStringFormatCo } #endregion + private static Task GetHelloStringAsync() + => Task.FromResult("Hello"); + private sealed class DummyClassTrackingToStringCalls { public bool WasToStringCalled { get; private set; } @@ -50,4 +53,10 @@ public override string ToString() return nameof(DummyClassTrackingToStringCalls); } } + + private sealed class DummyIFormattable : IFormattable + { + public string ToString(string format, IFormatProvider formatProvider) + => "DummyIFormattable.ToString()"; + } } diff --git a/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs b/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs index 0c85b5f063..8d707c95d0 100644 --- a/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs +++ b/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs @@ -80,6 +80,26 @@ public static Exception VerifyThrows( return null; } + public static async Task VerifyThrowsAsync( + Func taskGetter, + [CallerArgumentExpression(nameof(taskGetter))] string? expression = default, + [CallerMemberName] string? caller = default, + [CallerFilePath] string? filePath = default, + [CallerLineNumber] int lineNumber = default) + { + try + { + await taskGetter(); + } + catch (Exception ex) + { + return ex; + } + + Throw(expression, caller, filePath, lineNumber); + return null; + } + public static T VerifyThrows( Action action, [CallerArgumentExpression(nameof(action))] From df8264ddca33447a4dfcbe538bf31e84f6e28bab Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 09:01:16 +0100 Subject: [PATCH 40/46] AppendFormatted --- src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 8a30fba3f3..9420020133 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -64,7 +64,6 @@ internal void FailIfNeeded() public void AppendLiteral(string? value) => _builder!.Append(value); - // TODO (IMPORTANT): Verify that the behavior here is correct with enums, ISpanFormattable, and IFormattable arguments. public void AppendFormatted(T value) => AppendFormatted(value, format: null); #if NETCOREAPP3_1_OR_GREATER From 56fa24cbd15c83817e06c9eda02bc5415414baea Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 09:02:21 +0100 Subject: [PATCH 41/46] Remove unused using --- .../TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 45e4582493..eaced7c334 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -3,8 +3,6 @@ #nullable enable -using System; - using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; From cf1c8686f34e99cb1dafe478dd4b58a2a98c3acc Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 09:47:47 +0100 Subject: [PATCH 42/46] More test coverage --- .../Assertions/Assert.AreEqual.cs | 2 +- .../Assertions/AssertTests.AreEqualTests.cs | 160 ++++++++++++++++++ .../AssertTests.IsInstanceOfTypeTests.cs | 7 +- .../Assertions/AssertTests.IsNull.cs | 14 +- .../Assertions/AssertTests.IsTrueTests.cs | 48 ++++-- .../TestContainer.cs | 22 +++ 6 files changed, 225 insertions(+), 28 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 9420020133..08c5188a88 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -14,7 +14,7 @@ public sealed partial class Assert { [InterpolatedStringHandler] [EditorBrowsable(EditorBrowsableState.Never)] - public readonly ref struct AssertAreEqualInterpolatedStringHandler + public readonly struct AssertAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; private readonly object? _expected; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index e059628875..4760984225 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -290,6 +290,166 @@ public void AreEqualUsingDynamicsDoesNotFail() #pragma warning restore IDE0004 + public void GenericAreEqual_InterpolatedString_EqualValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreEqual(o, o, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task GenericAreEqual_InterpolatedString_DifferentValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreEqual(0, 1, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreEqual failed. Expected:<0>. Actual:<1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void GenericAreNotEqual_InterpolatedString_DifferentValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreNotEqual(0, 1, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreNotEqual(0, 0, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreNotEqual failed. Expected any value except:<0>. Actual:<0>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void FloatAreEqual_InterpolatedString_EqualValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreEqual(1.0f, 1.1f, delta: 0.2f, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreEqual(1.0f, 1.1f, 0.001f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreEqual failed. Expected a difference no greater than <0.001> between expected value <1> and actual value <1.1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void FloatAreNotEqual_InterpolatedString_DifferentValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreNotEqual(1.0f, 1.1f, 0.001f, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreNotEqual(1.0f, 1.1f, 0.2f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreNotEqual failed. Expected a difference greater than <0.2> between expected value <1> and actual value <1.1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void DecimalAreEqual_InterpolatedString_EqualValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreEqual(1.0m, 1.1m, delta: 0.2m, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreEqual(1.0m, 1.1m, 0.001m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreEqual failed. Expected a difference no greater than <0.001> between expected value <1.0> and actual value <1.1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void DecimalAreNotEqual_InterpolatedString_DifferentValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreNotEqual(1.0m, 1.1m, 0.001m, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreNotEqual(1.0m, 1.1m, 0.2m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreNotEqual failed. Expected a difference greater than <0.2> between expected value <1.0> and actual value <1.1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void LongAreEqual_InterpolatedString_EqualValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreEqual(1L, 2L, delta: 1L, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreEqual(1L, 2L, 0L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreEqual failed. Expected a difference no greater than <0> between expected value <1> and actual value <2>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void LongAreNotEqual_InterpolatedString_DifferentValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreNotEqual(1L, 2L, 0L, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreNotEqual(1L, 2L, 1L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreNotEqual failed. Expected a difference greater than <1> between expected value <1> and actual value <2>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void DoubleAreEqual_InterpolatedString_EqualValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreEqual(1.0d, 1.1d, delta: 0.2d, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreEqual(1.0d, 1.1d, 0.001d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreEqual failed. Expected a difference no greater than <0.001> between expected value <1> and actual value <1.1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + + public void DoubleAreNotEqual_InterpolatedString_DifferentValues_ShouldPass() + { + DummyClassTrackingToStringCalls o = new(); + Assert.AreNotEqual(1.0d, 1.1d, 0.001d, $"User-provided message: {o}"); + Verify(!o.WasToStringCalled); + } + + public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() + { + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.AreNotEqual(1.0d, 1.1d, 0.2d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.AreNotEqual failed. Expected a difference greater than <0.2> between expected value <1> and actual value <1.1>. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + Verify(o.WasToStringCalled); + } + private CultureInfo? GetCultureInfo() => CultureInfo.CurrentCulture; private class TypeOverridesEquals diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 764336e288..4ec85f34d3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -53,11 +53,12 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() public void InstanceOfType_WithStringMessage_ShouldPassWhenTypeIsCorrect() => Assert.IsInstanceOfType(5, typeof(int), "User-provided message"); - public void InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNull() + public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNull() { DummyClassTrackingToStringCalls o = new(); - Exception ex = VerifyThrows(() => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message {o}")); - Verify(ex.Message == "Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls"); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsInstanceOfType failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); Verify(o.WasToStringCalled); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index e2ebe13410..15eb6d2249 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -36,11 +36,12 @@ public void IsNull_InterpolatedString_PassNull_ShouldPass() Verify(!o.WasToStringCalled); } - public void IsNull_InterpolatedString_PassNonNull_ShouldFail() + public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() { DummyClassTrackingToStringCalls o = new(); - Exception ex = VerifyThrows(() => Assert.IsNull(new object(), $"User-provided message {o}")); - Verify(ex.Message == "Assert.IsNull failed. User-provided message DummyClassTrackingToStringCalls"); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsNull(new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsNull failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); Verify(o.WasToStringCalled); } @@ -95,11 +96,12 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() Verify(ex.Message == "Assert.IsNotNull failed. User-provided message"); } - public void IsNotNull_InterpolatedString_PassNonNull_ShouldFail() + public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() { DummyClassTrackingToStringCalls o = new(); - Exception ex = VerifyThrows(() => Assert.IsNotNull(null, $"User-provided message {o}")); - Verify(ex.Message == "Assert.IsNotNull failed. User-provided message DummyClassTrackingToStringCalls"); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsNotNull(null, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsNotNull failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); Verify(o.WasToStringCalled); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 70d6b7652e..3cf8d1ea23 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -65,18 +65,22 @@ public void IsFalseBooleanStringMessageShouldFailWithTrue() public void IsFalseBooleanStringMessageShouldNotFailWithFalse() => Assert.IsFalse(false, "User-provided message"); - public void IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithNull() + public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithNull() { bool? nullBool = null; - Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: "); + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); } - public void IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithTrue() + public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithTrue() { bool? nullBool = true; - Exception ex = VerifyThrows(() => Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: True"); + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); } public void IsFalseNullableBooleanInterpolatedStringMessageShouldNotFailWithFalse() @@ -85,10 +89,12 @@ public void IsFalseNullableBooleanInterpolatedStringMessageShouldNotFailWithFals Assert.IsFalse(nullBool, $"User-provided message. Input: {nullBool}"); } - public void IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() + public async Task IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() { - Exception ex = VerifyThrows(() => Assert.IsFalse(true, $"User-provided message. Input: {true}")); - Verify(ex.Message == "Assert.IsFalse failed. User-provided message. Input: True"); + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsFalse(true, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); } public void IsFalseBooleanInterpolatedStringMessageShouldNotFailWithFalse() @@ -181,18 +187,22 @@ public void IsTrueBooleanStringMessageShouldFailWithFalse() public void IsTrueBooleanStringMessageShouldNotFailWithTrue() => Assert.IsTrue(true, "User-provided message"); - public void IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNull() + public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNull() { bool? nullBool = null; - Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: "); + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); } - public void IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFalse() + public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFalse() { bool? nullBool = false; - Exception ex = VerifyThrows(() => Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}")); - Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: False"); + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); } public void IsTrueNullableBooleanInterpolatedStringMessageShouldNotFailWithTrue() @@ -201,10 +211,12 @@ public void IsTrueNullableBooleanInterpolatedStringMessageShouldNotFailWithTrue( Assert.IsTrue(nullBool, $"User-provided message. Input: {nullBool}"); } - public void IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() + public async Task IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() { - Exception ex = VerifyThrows(() => Assert.IsTrue(false, $"User-provided message. Input: {false}")); - Verify(ex.Message == "Assert.IsTrue failed. User-provided message. Input: False"); + DummyClassTrackingToStringCalls o = new(); + DateTime dateTime = DateTime.Now; + Exception ex = await VerifyThrowsAsync(async () => Assert.IsTrue(false, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}")); + Verify(ex.Message == $"Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); } public void IsTrueBooleanInterpolatedStringMessageShouldNotFailWithTrue() diff --git a/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs b/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs index 8d707c95d0..5c4cd8aff2 100644 --- a/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs +++ b/test/Utilities/TestFramework.ForTestingMSTest/TestContainer.cs @@ -122,6 +122,28 @@ public static T VerifyThrows( return null; } + public static async Task VerifyThrowsAsync( + Func taskGetter, + [CallerArgumentExpression(nameof(taskGetter))] + string? expression = default, + [CallerMemberName] string? caller = default, + [CallerFilePath] string? filePath = default, + [CallerLineNumber] int lineNumber = default) + where T : Exception + { + try + { + await taskGetter(); + } + catch (T ex) + { + return ex; + } + + Throw(expression, caller, filePath, lineNumber); + return null; + } + public static void Fail( [CallerMemberName] string? caller = default, [CallerFilePath] string? filePath = default, From f51cb70dad054df4883e5c653192446f365ec853 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 10:08:14 +0100 Subject: [PATCH 43/46] Renames --- .../Assertions/Assert.AreEqual.cs | 60 +++++++++---------- .../Assertions/Assert.AreSame.cs | 12 ++-- .../Assertions/Assert.IsInstanceOfType.cs | 16 ++--- .../TestFramework/Assertions/Assert.IsNull.cs | 12 ++-- .../TestFramework/Assertions/Assert.IsTrue.cs | 16 ++--- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 08c5188a88..9f17fbec15 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -58,7 +58,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailAreEqual(_expected, _actual, _builder.ToString()); + ThrowAssertAreEqualFailed(_expected, _actual, _builder.ToString()); } } @@ -122,7 +122,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailAreNotEqual(_notExpected, _actual, _builder.ToString()); + ThrowAssertAreNotEqualFailed(_notExpected, _actual, _builder.ToString()); } } @@ -171,7 +171,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -181,7 +181,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -191,7 +191,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -201,7 +201,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreEqual(expected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -217,7 +217,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreEqual(expected, actual, ignoreCase, culture, userMessage); + _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, ignoreCase, culture, userMessage); } } @@ -269,7 +269,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -279,7 +279,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -289,7 +289,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -299,7 +299,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreNotEqual(notExpected, actual, delta, userMessage); + _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -315,7 +315,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => FailAreNotEqual(notExpected, actual, userMessage); + _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, userMessage); } } @@ -534,7 +534,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com } string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, userMessage); + ThrowAssertAreEqualFailed(expected, actual, userMessage); } /// @@ -623,7 +623,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, [ } string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, userMessage); + ThrowAssertAreEqualFailed(expected, actual, userMessage); } private static bool AreEqualFailing(T? expected, T? actual) @@ -653,7 +653,7 @@ private static bool AreEqualFailing(long expected, long actual, long delta) => Math.Abs(expected - actual) > delta; [DoesNotReturn] - private static void FailAreEqual(object? expected, object? actual, string userMessage) + private static void ThrowAssertAreEqualFailed(object? expected, object? actual, string userMessage) { string finalMessage = actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) ? string.Format( @@ -674,7 +674,7 @@ private static void FailAreEqual(object? expected, object? actual, string userMe } [DoesNotReturn] - private static void FailAreEqual(T expected, T actual, T delta, string userMessage) + private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, string userMessage) where T : struct, IConvertible { string finalMessage = string.Format( @@ -688,7 +688,7 @@ private static void FailAreEqual(T expected, T actual, T delta, string userMe } [DoesNotReturn] - private static void FailAreEqual(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string userMessage) + private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string userMessage) { string finalMessage = !ignoreCase && CompareInternal(expected, actual, ignoreCase, culture) == 0 ? string.Format( @@ -889,7 +889,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer @@ -980,7 +980,7 @@ public static void AreEqual(float expected, float actual, float delta, [StringSy if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -1072,7 +1072,7 @@ public static void AreNotEqual(float notExpected, float actual, float delta, [St if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreNotEqual(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -1167,7 +1167,7 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta, [St if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -1259,7 +1259,7 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreNotEqual(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -1354,7 +1354,7 @@ public static void AreEqual(long expected, long actual, long delta, [StringSynta if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -1446,7 +1446,7 @@ public static void AreNotEqual(long notExpected, long actual, long delta, [Strin if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreNotEqual(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -1539,7 +1539,7 @@ public static void AreEqual(double expected, double actual, double delta, [Strin if (AreEqualFailing(expected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); } } @@ -1631,7 +1631,7 @@ public static void AreNotEqual(double notExpected, double actual, double delta, if (AreNotEqualFailing(notExpected, actual, delta)) { string userMessage = BuildUserMessage(message, parameters); - FailAreNotEqual(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); } } @@ -1639,7 +1639,7 @@ private static bool AreNotEqualFailing(double notExpected, double actual, double => Math.Abs(notExpected - actual) <= delta; [DoesNotReturn] - private static void FailAreNotEqual(T notExpected, T actual, T delta, string userMessage) + private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T delta, string userMessage) where T : struct, IConvertible { string finalMessage = string.Format( @@ -1833,7 +1833,7 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, } string userMessage = BuildUserMessage(message, parameters); - FailAreEqual(expected, actual, ignoreCase, culture, userMessage); + ThrowAssertAreEqualFailed(expected, actual, ignoreCase, culture, userMessage); } /// @@ -2022,7 +2022,7 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC } string userMessage = BuildUserMessage(message, parameters); - FailAreNotEqual(notExpected, actual, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, userMessage); } private static bool AreNotEqualFailing(string? notExpected, string? actual, bool ignoreCase, CultureInfo culture) @@ -2032,7 +2032,7 @@ private static bool AreNotEqualFailing(T? notExpected, T? actual, IEqualityCo => (comparer ?? EqualityComparer.Default).Equals(notExpected!, actual!); [DoesNotReturn] - private static void FailAreNotEqual(object? notExpected, object? actual, string userMessage) + private static void ThrowAssertAreNotEqualFailed(object? notExpected, object? actual, string userMessage) { string finalMessage = string.Format( CultureInfo.CurrentCulture, diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index f6bb473a0b..241199b130 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -35,7 +35,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailAreSame(_expected, _actual, _builder.ToString()); + ThrowAssertAreSameFailed(_expected, _actual, _builder.ToString()); } } @@ -90,7 +90,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailAreNotSame(_builder.ToString()); + ThrowAssertAreNotSameFailed(_builder.ToString()); } } @@ -210,14 +210,14 @@ public static void AreSame(T? expected, T? actual, [StringSyntax(StringSyntax } string userMessage = BuildUserMessage(message, parameters); - FailAreSame(expected, actual, userMessage); + ThrowAssertAreSameFailed(expected, actual, userMessage); } private static bool IsAreSameFailing(T? expected, T? actual) => !ReferenceEquals(expected, actual); [DoesNotReturn] - private static void FailAreSame(T? expected, T? actual, string userMessage) + private static void ThrowAssertAreSameFailed(T? expected, T? actual, string userMessage) { string finalMessage = userMessage; if (expected is ValueType && actual is ValueType) @@ -314,7 +314,7 @@ public static void AreNotSame(T? notExpected, T? actual, [StringSyntax(String { if (IsAreNotSameFailing(notExpected, actual)) { - FailAreNotSame(BuildUserMessage(message, parameters)); + ThrowAssertAreNotSameFailed(BuildUserMessage(message, parameters)); } } @@ -322,6 +322,6 @@ private static bool IsAreNotSameFailing(T? notExpected, T? actual) => ReferenceEquals(notExpected, actual); [DoesNotReturn] - private static void FailAreNotSame(string userMessage) + private static void ThrowAssertAreNotSameFailed(string userMessage) => ThrowAssertFailed("Assert.AreNotSame", userMessage); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index d8a41f73c8..7710bfd198 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -35,7 +35,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsInstanceOfType(_value, _expectedType, _builder.ToString()); + ThrowAssertIsInstanceOfTypeFailed(_value, _expectedType, _builder.ToString()); } } @@ -92,7 +92,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsInstanceOfType(_value, typeof(TArg), _builder.ToString()); + ThrowAssertIsInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString()); } } @@ -151,7 +151,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsNotInstanceOfType(_value, _wrongType, _builder.ToString()); + ThrowAssertIsNotInstanceOfTypeFailed(_value, _wrongType, _builder.ToString()); } } @@ -208,7 +208,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsNotInstanceOfType(_value, typeof(TArg), _builder.ToString()); + ThrowAssertIsNotInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString()); } } @@ -377,7 +377,7 @@ public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? exp { if (IsInstanceOfTypeFailing(value, expectedType)) { - FailIsInstanceOfType(value, expectedType, BuildUserMessage(message, parameters)); + ThrowAssertIsInstanceOfTypeFailed(value, expectedType, BuildUserMessage(message, parameters)); } } @@ -385,7 +385,7 @@ private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, => expectedType == null || value == null || !expectedType.IsAssignableFrom(value.GetType()); [DoesNotReturn] - private static void FailIsInstanceOfType(object? value, Type? expectedType, string userMessage) + private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string userMessage) { string finalMessage = userMessage; if (expectedType is not null && value is not null) @@ -528,7 +528,7 @@ public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, { if (IsNotInstanceOfTypeFailing(value, wrongType)) { - FailIsNotInstanceOfType(value, wrongType, BuildUserMessage(message, parameters)); + ThrowAssertIsNotInstanceOfTypeFailed(value, wrongType, BuildUserMessage(message, parameters)); } } @@ -538,7 +538,7 @@ private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false (value is not null && wrongType.IsAssignableFrom(value.GetType())); [DoesNotReturn] - private static void FailIsNotInstanceOfType(object? value, Type? wrongType, string userMessage) + private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string userMessage) { string finalMessage = userMessage; if (wrongType is not null) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 53ff468bcd..6b7220a198 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -31,7 +31,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsNull(_builder.ToString()); + ThrowAssertIsNullFailed(_builder.ToString()); } } @@ -86,7 +86,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsNotNull(_builder.ToString()); + ThrowAssertIsNotNullFailed(_builder.ToString()); } } @@ -179,13 +179,13 @@ public static void IsNull(object? value, [StringSyntax(StringSyntaxAttribute.Com { if (IsNullFailing(value)) { - FailIsNull(BuildUserMessage(message, parameters)); + ThrowAssertIsNullFailed(BuildUserMessage(message, parameters)); } } private static bool IsNullFailing(object? value) => value is not null; - private static void FailIsNull(string message) + private static void ThrowAssertIsNullFailed(string message) => ThrowAssertFailed("Assert.IsNull", message); /// @@ -247,13 +247,13 @@ public static void IsNotNull([NotNull] object? value, [StringSyntax(StringSyntax { if (IsNotNullFailing(value)) { - FailIsNotNull(BuildUserMessage(message, parameters)); + ThrowAssertIsNotNullFailed(BuildUserMessage(message, parameters)); } } private static bool IsNotNullFailing([NotNullWhen(false)] object? value) => value is null; [DoesNotReturn] - private static void FailIsNotNull(string message) + private static void ThrowAssertIsNotNullFailed(string message) => ThrowAssertFailed("Assert.IsNotNull", message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index e62e42516c..d3836653d7 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -31,7 +31,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsTrue(_builder.ToString()); + ThrowAssertIsTrueFailed(_builder.ToString()); } } @@ -86,7 +86,7 @@ internal void FailIfNeeded() { if (_builder is not null) { - FailIsFalse(_builder.ToString()); + ThrowAssertIsFalseFailed(_builder.ToString()); } } @@ -215,7 +215,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, [StringSyntax { if (IsTrueFailing(condition)) { - FailIsTrue(BuildUserMessage(message, parameters)); + ThrowAssertIsTrueFailed(BuildUserMessage(message, parameters)); } } @@ -241,7 +241,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [StringSynta { if (IsTrueFailing(condition)) { - FailIsTrue(BuildUserMessage(message, parameters)); + ThrowAssertIsTrueFailed(BuildUserMessage(message, parameters)); } } @@ -251,7 +251,7 @@ private static bool IsTrueFailing(bool? condition) private static bool IsTrueFailing(bool condition) => !condition; - private static void FailIsTrue(string message) + private static void ThrowAssertIsTrueFailed(string message) => ThrowAssertFailed("Assert.IsTrue", message); /// @@ -348,7 +348,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, [StringSyntax { if (IsFalseFailing(condition)) { - FailIsFalse(BuildUserMessage(message, parameters)); + ThrowAssertIsFalseFailed(BuildUserMessage(message, parameters)); } } @@ -374,7 +374,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [StringSynta { if (IsFalseFailing(condition)) { - FailIsFalse(BuildUserMessage(message, parameters)); + ThrowAssertIsFalseFailed(BuildUserMessage(message, parameters)); } } @@ -385,6 +385,6 @@ private static bool IsFalseFailing(bool condition) => condition; [DoesNotReturn] - private static void FailIsFalse(string userMessage) + private static void ThrowAssertIsFalseFailed(string userMessage) => ThrowAssertFailed("Assert.IsFalse", userMessage); } From b8738a339a6c2e8fe211c919e5add081dc327066 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 10:09:15 +0100 Subject: [PATCH 44/46] Renames --- .../Assertions/Assert.AreEqual.cs | 42 +++++++++---------- .../Assertions/Assert.AreSame.cs | 8 ++-- .../Assertions/Assert.IsInstanceOfType.cs | 18 ++++---- .../TestFramework/Assertions/Assert.IsNull.cs | 8 ++-- .../TestFramework/Assertions/Assert.IsTrue.cs | 12 +++--- .../Assertions/Assert.ThrowsException.cs | 8 ++-- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 9f17fbec15..1fabf26fe6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -54,7 +54,7 @@ public AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedC } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -118,7 +118,7 @@ public AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formatt } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -221,7 +221,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int } } - internal void FailIfNeeded() + internal void ComputeAssertion() => _failAction?.Invoke(_builder!.ToString()); public void AppendLiteral(string value) => _builder!.Append(value); @@ -319,7 +319,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i } } - internal void FailIfNeeded() + internal void ComputeAssertion() => _failAction?.Invoke(_builder!.ToString()); public void AppendLiteral(string value) => _builder!.Append(value); @@ -428,7 +428,7 @@ public static void AreEqual(T? expected, T? actual, string? message) #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(T? expected, T? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified values are equal and throws an exception @@ -464,7 +464,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(T? expected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(comparer))] ref AssertAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified values are equal and throws an exception @@ -587,7 +587,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, s #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(IEquatable? expected, IEquatable? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified values are equal and throws an exception @@ -783,7 +783,7 @@ public static void AreNotEqual(T? notExpected, T? actual, string? message) #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] ref AssertAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified values are unequal and throws an exception @@ -819,7 +819,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer(T? notExpected, T? actual, IEqualityComparer? comparer, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(comparer))] ref AssertAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified values are unequal and throws an exception @@ -945,7 +945,7 @@ public static void AreEqual(float expected, float actual, float delta, string? m #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(float expected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified floats are equal and throws an exception @@ -1037,7 +1037,7 @@ public static void AreNotEqual(float notExpected, float actual, float delta, str #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(float notExpected, float actual, float delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified floats are unequal and throws an exception @@ -1132,7 +1132,7 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta, str #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(decimal expected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified decimals are equal and throws an exception @@ -1224,7 +1224,7 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(decimal notExpected, decimal actual, decimal delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified decimals are unequal and throws an exception @@ -1319,7 +1319,7 @@ public static void AreEqual(long expected, long actual, long delta, string? mess #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(long expected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified longs are equal and throws an exception @@ -1411,7 +1411,7 @@ public static void AreNotEqual(long notExpected, long actual, long delta, string #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(long notExpected, long actual, long delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified longs are unequal and throws an exception @@ -1505,7 +1505,7 @@ public static void AreEqual(double expected, double actual, double delta, string #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(double expected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(delta))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified doubles are equal and throws an exception @@ -1596,7 +1596,7 @@ public static void AreNotEqual(double notExpected, double actual, double delta, #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(double notExpected, double actual, double delta, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(delta))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified doubles are unequal and throws an exception @@ -1701,7 +1701,7 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, s #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreEqual(string? expected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified strings are equal and throws an exception @@ -1792,7 +1792,7 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, [NotNull] CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreEqualInterpolatedStringHandler message) { CheckParameterNotNull(culture, "Assert.AreEqual", nameof(culture), string.Empty); - message.FailIfNeeded(); + message.ComputeAssertion(); } /// @@ -1887,7 +1887,7 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotEqual(string? notExpected, string? actual, bool ignoreCase, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified strings are unequal and throws an exception @@ -1980,7 +1980,7 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC CultureInfo? culture, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual), nameof(ignoreCase), nameof(culture))] ref AssertNonGenericAreNotEqualInterpolatedStringHandler message) { CheckParameterNotNull(culture, "Assert.AreNotEqual", nameof(culture), string.Empty); - message.FailIfNeeded(); + message.ComputeAssertion(); } /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 241199b130..2375567377 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -31,7 +31,7 @@ public AssertAreSameInterpolatedStringHandler(int literalLength, int formattedCo } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -86,7 +86,7 @@ public AssertAreNotSameInterpolatedStringHandler(int literalLength, int formatte } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -175,7 +175,7 @@ public static void AreSame(T? expected, T? actual, string? message) #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreSame(T? expected, T? actual, [InterpolatedStringHandlerArgument(nameof(expected), nameof(actual))] ref AssertAreSameInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified objects both refer to the same object and @@ -282,7 +282,7 @@ public static void AreNotSame(T? notExpected, T? actual, string? message) #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void AreNotSame(T? notExpected, T? actual, [InterpolatedStringHandlerArgument(nameof(notExpected), nameof(actual))] ref AssertAreNotSameInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified objects refer to different objects and diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 7710bfd198..ff726bfabf 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -31,7 +31,7 @@ public AssertIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int fo } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -88,7 +88,7 @@ public AssertGenericIsInstanceOfTypeInterpolatedStringHandler(int literalLength, } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -147,7 +147,7 @@ public AssertIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -204,7 +204,7 @@ public AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler(int literalLeng } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -310,7 +310,7 @@ public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? exp public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? expectedType, [InterpolatedStringHandlerArgument(nameof(value), nameof(expectedType))] ref AssertIsInstanceOfTypeInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter #pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. - => message.FailIfNeeded(); + => message.ComputeAssertion(); #pragma warning restore CS8777 // Parameter must have a non-null value when exiting. /// @@ -327,7 +327,7 @@ public static void IsInstanceOfType([NotNull] object? value, string? message) public static void IsInstanceOfType([NotNull] object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertGenericIsInstanceOfTypeInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter #pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. - => message.FailIfNeeded(); + => message.ComputeAssertion(); #pragma warning restore CS8777 // Parameter must have a non-null value when exiting. /// @@ -343,7 +343,7 @@ public static void IsInstanceOfType([NotNull] object? value, out T instance, public static void IsInstanceOfType([NotNull] object? value, out T instance, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertGenericIsInstanceOfTypeInterpolatedStringHandler message) #pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. { - message.FailIfNeeded(); + message.ComputeAssertion(); instance = (T)value!; } #pragma warning restore CS8777 // Parameter must have a non-null value when exiting. @@ -481,7 +481,7 @@ public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, [InterpolatedStringHandlerArgument(nameof(value), nameof(wrongType))] ref AssertIsNotInstanceOfTypeInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter #pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. - => message.FailIfNeeded(); + => message.ComputeAssertion(); #pragma warning restore CS8777 // Parameter must have a non-null value when exiting. /// @@ -497,7 +497,7 @@ public static void IsNotInstanceOfType(object? value, string? message) #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsNotInstanceOfType(object? value, [InterpolatedStringHandlerArgument(nameof(value))] AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified object is not an instance of the wrong diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 6b7220a198..547cf9e79c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -27,7 +27,7 @@ public AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCou } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -82,7 +82,7 @@ public AssertIsNotNullInterpolatedStringHandler(int literalLength, int formatted } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -156,7 +156,7 @@ public static void IsNull(object? value, string? message) #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsNull(object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified object is null and throws an exception @@ -223,7 +223,7 @@ public static void IsNotNull([NotNull] object? value, string? message) public static void IsNotNull([NotNull] object? value, [InterpolatedStringHandlerArgument(nameof(value))] ref AssertIsNotNullInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter #pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - Not sure how to express the semantics to the compiler, but the implementation guarantees that. - => message.FailIfNeeded(); + => message.ComputeAssertion(); #pragma warning restore CS8777 // Parameter must have a non-null value when exiting. /// diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index d3836653d7..d51f089954 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -27,7 +27,7 @@ public AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCou } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -82,7 +82,7 @@ public AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCo } } - internal void FailIfNeeded() + internal void ComputeAssertion() { if (_builder is not null) { @@ -168,7 +168,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool condition, string? messa #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsTrue([DoesNotReturnIf(false)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified condition is true and throws an exception @@ -191,7 +191,7 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? mess #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsTrue([DoesNotReturnIf(false)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsTrueInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified condition is true and throws an exception @@ -301,7 +301,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool condition, string? messa #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsFalse([DoesNotReturnIf(true)] bool condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified condition is false and throws an exception @@ -324,7 +324,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? mess #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 public static void IsFalse([DoesNotReturnIf(true)] bool? condition, [InterpolatedStringHandlerArgument(nameof(condition))] ref AssertIsFalseInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the specified condition is false and throws an exception diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index ae83dbaf68..a8e325279e 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -30,7 +30,7 @@ public AssertNonStrictThrowsInterpolatedStringHandler(int literalLength, int for } } - internal TException FailIfNeeded() + internal TException ComputeAssertion() { if (_state.FailAction is not null) { @@ -95,7 +95,7 @@ public AssertThrowsExactlyInterpolatedStringHandler(int literalLength, int forma } } - internal TException FailIfNeeded() + internal TException ComputeAssertion() { if (_state.FailAction is not null) { @@ -174,7 +174,7 @@ public static TException Throws(Action action, string message = "", public static TException Throws(Action action, [InterpolatedStringHandlerArgument(nameof(action))] ref AssertNonStrictThrowsInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter where TException : Exception - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Asserts that the delegate throws an exception of type @@ -208,7 +208,7 @@ public static TException ThrowsExactly(Action action, string message public static TException ThrowsExactly(Action action, [InterpolatedStringHandlerArgument(nameof(action))] ref AssertThrowsExactlyInterpolatedStringHandler message) #pragma warning restore IDE0060 // Remove unused parameter where TException : Exception - => message.FailIfNeeded(); + => message.ComputeAssertion(); /// /// Tests whether the code specified by delegate throws exact given exception From 344196ce915e22560b941a227f93822932355943 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 10:21:32 +0100 Subject: [PATCH 45/46] Small fix --- src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index d51f089954..b2586505b4 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -114,7 +114,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters -#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); +#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads + public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters From 1c137de8472e58c3b9a12cd76863baffbaaf2c46 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 2 Jan 2025 19:36:00 +0100 Subject: [PATCH 46/46] Add AppendFormatted string overload --- .../TestFramework/Assertions/Assert.AreEqual.cs | 8 ++++++++ .../TestFramework/Assertions/Assert.AreSame.cs | 4 ++++ .../Assertions/Assert.IsInstanceOfType.cs | 8 ++++++++ .../TestFramework/Assertions/Assert.IsNull.cs | 4 ++++ .../TestFramework/Assertions/Assert.IsTrue.cs | 4 ++++ .../Assertions/Assert.ThrowsException.cs | 4 ++++ .../PublicAPI/PublicAPI.Unshipped.txt | 16 ++++++++++++++++ 7 files changed, 48 insertions(+) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 1fabf26fe6..274bc26248 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -85,6 +85,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -149,6 +151,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -247,6 +251,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -345,6 +351,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 2375567377..0a7799900d 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -62,6 +62,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -117,6 +119,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index ff726bfabf..63f62e38ba 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -62,6 +62,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -119,6 +121,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -178,6 +182,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -235,6 +241,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 547cf9e79c..74dd9a5e51 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -58,6 +58,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -113,6 +115,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index b2586505b4..53815e5b36 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -58,6 +58,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -113,6 +115,8 @@ internal void ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index a8e325279e..66efac037d 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -68,6 +68,8 @@ internal TException ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); @@ -133,6 +135,8 @@ internal TException ComputeAssertion() public void AppendFormatted(T value, int alignment, string? format) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); + public void AppendFormatted(string? value) => _builder!.Append(value); + #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters #pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index 90562d3a33..9572aa2c29 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1,6 +1,7 @@ #nullable enable Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -13,6 +14,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedSt Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreEqualInterpolatedStringHandler.AssertAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -24,6 +26,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolate Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotEqualInterpolatedStringHandler.AssertAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, System.Collections.Generic.IEqualityComparer? comparer, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -34,6 +37,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolated Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreNotSameInterpolatedStringHandler.AssertAreNotSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -44,6 +48,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStr Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler.AssertAreSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? expected, TArgument? actual, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -54,6 +59,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTyp Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsInstanceOfTypeInterpolatedStringHandler.AssertGenericIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -64,6 +70,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOf Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler.AssertGenericIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -74,6 +81,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStr Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsFalseInterpolatedStringHandler.AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -84,6 +92,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterp Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsInstanceOfTypeInterpolatedStringHandler.AssertIsInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, System.Type? expectedType, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -94,6 +103,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInt Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotInstanceOfTypeInterpolatedStringHandler.AssertIsNotInstanceOfTypeInterpolatedStringHandler(int literalLength, int formattedCount, object? value, System.Type? wrongType, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -104,6 +114,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedS Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNotNullInterpolatedStringHandler.AssertIsNotNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -114,6 +125,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStri Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsNullInterpolatedStringHandler.AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -124,6 +136,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStri Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertIsTrueInterpolatedStringHandler.AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -139,6 +152,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInte Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreEqualInterpolatedStringHandler.AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? expected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -154,6 +168,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualI Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonGenericAreNotEqualInterpolatedStringHandler.AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, string? notExpected, string? actual, bool ignoreCase, System.Globalization.CultureInfo? culture, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void @@ -164,6 +179,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpo Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler.AssertNonStrictThrowsInterpolatedStringHandler(int literalLength, int formattedCount, System.Action! action, out bool shouldAppend) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(object? value, int alignment = 0, string? format = null) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(string? value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(string? value, int alignment = 0, string? format = null) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value) -> void Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertThrowsExactlyInterpolatedStringHandler.AppendFormatted(T value, int alignment) -> void