Skip to content

Commit 3f38950

Browse files
Revert Assert.That obsoletion by @Youssef1313 in #6323 (backport to rel/3.10) (#6324)
Co-authored-by: Youssef1313 <youssefvictor00@gmail.com>
1 parent 2e0413d commit 3f38950

File tree

8 files changed

+16
-61
lines changed

8 files changed

+16
-61
lines changed

src/TestFramework/TestFramework/Assertions/Assert.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ private Assert()
1414
{
1515
}
1616

17-
/// <summary>
18-
/// Gets the singleton instance of the Assert functionality.
19-
/// </summary>
20-
/// <remarks>
21-
/// Users can use this to plug-in custom assertions through C# extension methods.
22-
/// For instance, the signature of a custom assertion provider could be "public static void IsOfType&lt;T&gt;(this Assert assert, object obj)"
23-
/// Users could then use a syntax similar to the default assertions which in this case is "Assert.Instance.IsOfType&lt;Dog&gt;(animal);"
24-
/// More documentation is at "https://github.com/Microsoft/testfx/docs/README.md".
25-
/// </remarks>
26-
public static Assert Instance { get; } = new Assert();
27-
2817
/// <summary>
2918
/// Gets the singleton instance of the Assert functionality.
3019
/// </summary>
@@ -34,12 +23,7 @@ private Assert()
3423
/// Users could then use a syntax similar to the default assertions which in this case is "Assert.That.IsOfType&lt;Dog&gt;(animal);"
3524
/// More documentation is at "https://github.com/Microsoft/testfx/docs/README.md".
3625
/// </remarks>
37-
#if NET6_0_OR_GREATER
38-
[Obsolete(FrameworkConstants.ThatPropertyObsoleteMessage, DiagnosticId = "MSTESTOBS")]
39-
#else
40-
[Obsolete(FrameworkConstants.ThatPropertyObsoleteMessage)]
41-
#endif
42-
public static Assert That => Instance;
26+
public static Assert That { get; } = new();
4327

4428
/// <summary>
4529
/// Replaces null characters ('\0') with "\\0".

src/TestFramework/TestFramework/Assertions/CollectionAssert.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ private CollectionAssert()
1616
{
1717
}
1818

19-
/// <summary>
20-
/// Gets the singleton instance of the CollectionAssert functionality.
21-
/// </summary>
22-
/// <remarks>
23-
/// Users can use this to plug-in custom assertions through C# extension methods.
24-
/// For instance, the signature of a custom assertion provider could be "public static void AreEqualUnordered(this CollectionAssert customAssert, ICollection expected, ICollection actual)"
25-
/// Users could then use a syntax similar to the default assertions which in this case is "CollectionAssert.Instance.AreEqualUnordered(list1, list2);"
26-
/// More documentation is at "https://github.com/Microsoft/testfx/docs/README.md".
27-
/// </remarks>
28-
public static CollectionAssert Instance { get; } = new CollectionAssert();
29-
3019
/// <summary>
3120
/// Gets the singleton instance of the CollectionAssert functionality.
3221
/// </summary>
@@ -36,12 +25,7 @@ private CollectionAssert()
3625
/// Users could then use a syntax similar to the default assertions which in this case is "CollectionAssert.That.AreEqualUnordered(list1, list2);"
3726
/// More documentation is at "https://github.com/Microsoft/testfx/docs/README.md".
3827
/// </remarks>
39-
#if NET6_0_OR_GREATER
40-
[Obsolete(FrameworkConstants.ThatPropertyObsoleteMessage, DiagnosticId = "MSTESTOBS")]
41-
#else
42-
[Obsolete(FrameworkConstants.ThatPropertyObsoleteMessage)]
43-
#endif
44-
public static CollectionAssert That => Instance;
28+
public static CollectionAssert That { get; } = new();
4529

4630
#endregion
4731

src/TestFramework/TestFramework/Assertions/StringAssert.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ private StringAssert()
1616
{
1717
}
1818

19-
/// <summary>
20-
/// Gets the singleton instance of the StringAssert functionality.
21-
/// </summary>
22-
/// <remarks>
23-
/// Users can use this to plug-in custom assertions through C# extension methods.
24-
/// For instance, the signature of a custom assertion provider could be "public static void ContainsWords(this StringAssert customAssert, string value, ICollection substrings)"
25-
/// Users could then use a syntax similar to the default assertions which in this case is "StringAssert.Instance.ContainsWords(value, substrings);"
26-
/// More documentation is at "https://github.com/Microsoft/testfx/docs/README.md".
27-
/// </remarks>
28-
public static StringAssert Instance { get; } = new StringAssert();
29-
3019
/// <summary>
3120
/// Gets the singleton instance of the StringAssert functionality.
3221
/// </summary>
@@ -36,12 +25,7 @@ private StringAssert()
3625
/// Users could then use a syntax similar to the default assertions which in this case is "StringAssert.That.ContainsWords(value, substrings);"
3726
/// More documentation is at "https://github.com/Microsoft/testfx/docs/README.md".
3827
/// </remarks>
39-
#if NET6_0_OR_GREATER
40-
[Obsolete(FrameworkConstants.ThatPropertyObsoleteMessage, DiagnosticId = "MSTESTOBS")]
41-
#else
42-
[Obsolete(FrameworkConstants.ThatPropertyObsoleteMessage)]
43-
#endif
44-
public static StringAssert That => Instance;
28+
public static StringAssert That { get; } = new();
4529

4630
#endregion
4731

src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.ReferenceEquals
5353
*REMOVED*abstract Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute.IgnoreMessage.get -> string?
5454
virtual Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute.IgnoreMessage.get -> string?
5555
virtual Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute.IgnoreMessage.set -> void
56+
*REMOVED*static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Instance.get -> Microsoft.VisualStudio.TestTools.UnitTesting.Assert!
57+
*REMOVED*static Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert.Instance.get -> Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert!
58+
*REMOVED*static Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.Instance.get -> Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert!

test/IntegrationTests/TestAssets/FxExtensibilityTestProject/AssertExTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ namespace FxExtensibilityTestProject;
1111
public class AssertExTest
1212
{
1313
[TestMethod]
14-
public void BasicAssertExtensionTest() => Assert.Instance.IsOfType<ArgumentException>(new ArgumentOutOfRangeException());
14+
public void BasicAssertExtensionTest() => Assert.That.IsOfType<ArgumentException>(new ArgumentOutOfRangeException());
1515

1616
[TestMethod]
1717
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
18-
public void BasicFailingAssertExtensionTest() => Assert.Instance.IsOfType<FormatException>(new ArgumentNullException());
18+
public void BasicFailingAssertExtensionTest() => Assert.That.IsOfType<FormatException>(new ArgumentNullException());
1919

2020
[TestMethod]
21-
public void ChainedAssertExtensionTest() => Assert.Instance.Is().Divisor(120, 5);
21+
public void ChainedAssertExtensionTest() => Assert.That.Is().Divisor(120, 5);
2222

2323
[TestMethod]
2424
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
25-
public void ChainedFailingAssertExtensionTest() => Assert.Instance.Is().Positive(-10);
25+
public void ChainedFailingAssertExtensionTest() => Assert.That.Is().Positive(-10);
2626
}

test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests;
66
public partial class AssertTests
77
{
88
#region Instance tests
9-
public void InstanceShouldReturnAnInstanceOfAssert() => Verify(Assert.Instance is not null);
9+
public void InstanceShouldReturnAnInstanceOfAssert() => Verify(Assert.That is not null);
1010

11-
public void InstanceShouldCacheAssertInstance() => Verify(ReferenceEquals(Assert.Instance, Assert.Instance));
11+
public void InstanceShouldCacheAssertInstance() => Verify(ReferenceEquals(Assert.That, Assert.That));
1212
#endregion
1313

1414
#region ReplaceNullChars tests

test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.Assertions
99

1010
public class CollectionAssertTests : TestContainer
1111
{
12-
public void InstanceShouldReturnAnInstanceOfCollectionAssert() => Verify(CollectionAssert.Instance is not null);
12+
public void InstanceShouldReturnAnInstanceOfCollectionAssert() => Verify(CollectionAssert.That is not null);
1313

14-
public void InstanceShouldCacheCollectionAssertInstance() => Verify(CollectionAssert.Instance == CollectionAssert.Instance);
14+
public void InstanceShouldCacheCollectionAssertInstance() => Verify(CollectionAssert.That == CollectionAssert.That);
1515

1616
public void CollectionAssertContainsNullabilityPostConditions()
1717
{

test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.Assertions
77

88
public class StringAssertTests : TestContainer
99
{
10-
public void InstanceShouldReturnAnInstanceOfStringAssert() => Verify(StringAssert.Instance is not null);
10+
public void InstanceShouldReturnAnInstanceOfStringAssert() => Verify(StringAssert.That is not null);
1111

12-
public void InstanceShouldCacheStringAssertInstance() => Verify(StringAssert.Instance == StringAssert.Instance);
12+
public void InstanceShouldCacheStringAssertInstance() => Verify(StringAssert.That == StringAssert.That);
1313

1414
public void StringAssertContains()
1515
{

0 commit comments

Comments
 (0)