diff --git a/src/tests/Common/Assert.cs b/src/tests/Common/Assert.cs
new file mode 100644
index 00000000000000..a4ab602f7f9801
--- /dev/null
+++ b/src/tests/Common/Assert.cs
@@ -0,0 +1,238 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+// This file is used to provide some basic Assert functionality for assemblies that directly reference System.Private.CoreLib
+// and not the ref pack.
+
+// Note: Exception messages call ToString instead of Name to avoid MissingMetadataException when just outputting basic info
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Xunit
+{
+ ///
+ /// A collection of helper classes to test various conditions within
+ /// unit tests. If the condition being tested is not met, an exception
+ /// is thrown.
+ ///
+ public static class Assert
+ {
+ ///
+ /// Asserts that the given delegate throws an of type .
+ ///
+ ///
+ /// The delagate of type to execute.
+ ///
+ ///
+ /// A containing additional information for when the assertion fails.
+ ///
+ ///
+ /// The thrown .
+ ///
+ ///
+ /// of type was not thrown.
+ ///
+ public static T Throws(Action action) where T : Exception
+ {
+ Exception exception = RunWithCatch(action);
+
+ if (exception == null)
+ Assert.True(false, $"Expected '{typeof(T)}' to be thrown.");
+
+ if (exception is not T)
+ Assert.True(false, $"Expected '{typeof(T)}' to be thrown, however '{exception.GetType()}' was thrown.");
+
+ return (T)exception;
+ }
+
+ ///
+ /// Tests whether the specified condition is true and throws an exception
+ /// if the condition is false.
+ ///
+ /// The condition the test expects to be true.
+ ///
+ /// The message to include in the exception when
+ /// is false. The message is shown in test results.
+ ///
+ ///
+ /// Thrown if is false.
+ ///
+ public static void True(bool condition, string message = "")
+ {
+ if (!condition)
+ {
+ Assert.HandleFail("Assert.True", message);
+ }
+ }
+
+ ///
+ /// Tests whether the specified condition is false and throws an exception
+ /// if the condition is true.
+ ///
+ /// The condition the test expects to be false.
+ ///
+ /// The message to include in the exception when
+ /// is true. The message is shown in test results.
+ ///
+ ///
+ /// Thrown if is true.
+ ///
+ public static void False(bool condition, string message = "")
+ {
+ if (condition)
+ {
+ Assert.HandleFail("Assert.False", message);
+ }
+ }
+
+ ///
+ /// Tests whether the specified object is null and throws an exception
+ /// if it is not.
+ ///
+ /// The object the test expects to be null.
+ ///
+ /// The message to include in the exception when
+ /// is not null. The message is shown in test results.
+ ///
+ ///
+ /// Thrown if is not null.
+ ///
+ public static void Null(object value)
+ {
+ if (value != null)
+ {
+ Assert.HandleFail("Assert.Null", "");
+ }
+ }
+
+ ///
+ /// Tests whether the specified object is non-null and throws an exception
+ /// if it is null.
+ ///
+ /// The object the test expects not to be null.
+ ///
+ /// The message to include in the exception when
+ /// is null. The message is shown in test results.
+ ///
+ ///
+ /// Thrown if is null.
+ ///
+ public static void NotNull(object value)
+ {
+ if (value == null)
+ {
+ Assert.HandleFail("Assert.NotNull", "");
+ }
+ }
+
+ ///
+ /// Tests whether the expected object is equal to the actual object and
+ /// throws an exception if it is not.
+ ///
+ /// Expected object.
+ /// Actual object.
+ /// Message to display upon failure.
+ public static void Equal(T expected, T actual)
+ {
+ if (!Object.Equals(expected, actual))
+ {
+ Assert.HandleFail("Assert.Equal", "");
+ }
+ }
+
+ ///
+ /// Tests whether the expected object is equal to the actual object and
+ /// throws an exception if it is not.
+ ///
+ /// Expected object.
+ /// Actual object.
+ /// Message to display upon failure.
+ public static void Same(object expected, object actual)
+ {
+ const string EXPECTED_MSG = @"Expected: [{1}]. Actual: [{2}]. {0}";
+
+ if (!Object.ReferenceEquals(expected, actual))
+ {
+ Assert.HandleFail("Assert.Same", "");
+ }
+ }
+
+ ///
+ /// Tests whether the expected object is equal to the actual object and
+ /// throws an exception if it is not.
+ ///
+ /// Expected object.
+ /// Actual object.
+ /// Message to display upon failure.
+ public static void Equal(T expected, T actual, string format, params Object[] args)
+ {
+ Equal(expected, actual);
+ }
+
+ ///
+ /// Tests whether the expected object is equal to the actual object and
+ /// throws an exception if it is not.
+ ///
+ ///
+ /// Expected object that we do not want it to be.
+ /// Actual object.
+ /// Message to display upon failure.
+ public static void NotEqual(T notExpected, T actual)
+ {
+ if (Object.Equals(notExpected, actual))
+ {
+ Assert.HandleFail("Assert.NotEqual", "");
+ }
+ }
+
+ ///
+ /// Helper function that creates and throws an exception.
+ ///
+ /// name of the assertion throwing an exception.
+ /// message describing conditions for assertion failure.
+ /// The parameters.=
+ internal static void HandleFail(string assertionName, string message)
+ {
+ throw new XunitException(assertionName + ": " + message);
+ }
+
+
+ [Obsolete("Did you mean to call Assert.Equal()")]
+ public static new bool Equals(Object o1, Object o2)
+ {
+ Assert.True(false, "Don't call this.");
+ throw new Exception();
+ }
+
+ private static Exception RunWithCatch(Action action)
+ {
+ try
+ {
+ action();
+ return null;
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+ }
+
+ ///
+ /// Exception raised by the Assert on Fail
+ ///
+ public class XunitException : Exception
+ {
+ public XunitException(string message)
+ : base(message)
+ {
+ }
+
+ public XunitException()
+ : base()
+ {
+ }
+ }
+}
diff --git a/src/tests/Common/CoreCLRTestLibrary/AssertExtensions.cs b/src/tests/Common/CoreCLRTestLibrary/AssertExtensions.cs
new file mode 100644
index 00000000000000..c039f5a71814b5
--- /dev/null
+++ b/src/tests/Common/CoreCLRTestLibrary/AssertExtensions.cs
@@ -0,0 +1,176 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+// Note: Exception messages call ToString instead of Name to avoid MissingMetadataException when just outputting basic info
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Xunit
+{
+ public static class AssertExtensions
+ {
+ ///
+ /// Asserts that the given delegate throws an with the given parameter name.
+ ///
+ ///
+ /// The delagate of type to execute.
+ ///
+ ///
+ /// A containing additional information for when the assertion fails.
+ ///
+ ///
+ /// A containing the parameter of name to check, to skip parameter validation.
+ ///
+ ///
+ /// The thrown .
+ ///
+ ///
+ /// of type was not thrown.
+ ///
+ /// -or-
+ ///
+ /// is not equal to .
+ ///
+ public static ArgumentException ThrowsArgumentException(string parameterName, Action action)
+ {
+ return ThrowsArgumentException(parameterName, action);
+ }
+
+ ///
+ /// Asserts that the given delegate throws an of type with the given parameter name.
+ ///
+ ///
+ /// The delagate of type to execute.
+ ///
+ ///
+ /// A containing additional information for when the assertion fails.
+ ///
+ ///
+ /// A containing the parameter of name to check, to skip parameter validation.
+ ///
+ ///
+ /// The thrown .
+ ///
+ ///
+ /// of type was not thrown.
+ ///
+ /// -or-
+ ///
+ /// is not equal to .
+ ///
+ public static T ThrowsArgumentException(string parameterName, Action action)
+ where T : ArgumentException
+ {
+ T exception = Assert.Throws(action);
+
+#if DEBUG
+ // ParamName's not available on ret builds
+ if (parameterName != null)
+ Assert.Equal(parameterName, exception.ParamName);
+#endif
+
+ return exception;
+ }
+
+ ///
+ /// Asserts that the given async delegate throws an of type and
+ /// returns an of type .
+ ///
+ ///
+ /// The delagate of type to execute.
+ ///
+ ///
+ /// A containing additional information for when the assertion fails.
+ ///
+ ///
+ /// Specifies whether should require an exact type match when comparing the expected exception type with the thrown exception. The default is .
+ ///
+ ///
+ /// The thrown inner .
+ ///
+ ///
+ /// of type was not thrown.
+ ///
+ /// -or-
+ ///
+ /// is not of type .
+ ///
+ public static TInner ThrowsWithInnerException(Action action)
+ where T : Exception
+ where TInner : Exception
+ {
+ T outerException = Assert.Throws(action);
+
+ if (outerException.InnerException == null)
+ Assert.True(false, string.Format("Expected '{0}.InnerException' to be '{1}', however it is null.", typeof(T), typeof(TInner)));
+
+ if (outerException.InnerException is not TInner)
+ Assert.True(false, string.Format("Expected '{0}.InnerException', to be '{1}', however, '{2}' is.", typeof(T), typeof(TInner), outerException.InnerException.GetType()));
+
+ return (TInner)outerException.InnerException;
+ }
+
+
+ ///
+ /// Tests whether the two lists are the same length and contain the same objects (using Object.Equals()) in the same order and
+ /// throws an exception if it is not.
+ ///
+ /// Expected list.
+ /// Actual list.
+ /// Message to display upon failure.
+ public static void CollectionEqual(T[] expected, T[] actual)
+ {
+ Assert.Equal(expected.Length, actual.Length);
+
+ for (int i = 0; i < expected.Length; i++)
+ Assert.Equal(expected[i], actual[i]);
+ }
+
+ ///
+ /// Tests whether the two enumerables are the same length and contain the same objects (using Object.Equals()) in the same order and
+ /// throws an exception if it is not.
+ ///
+ /// Expected enumerables.
+ /// Actual enumerables.
+ /// Message to display upon failure.
+ public static void CollectionEqual(IEnumerable expected, IEnumerable actual)
+ {
+ CollectionEqual(CopyToArray(expected), CopyToArray(actual));
+ }
+
+ ///
+ /// Iterates through an IEnumerable to generate an array of elements. The rational for using this instead of
+ /// System.Linq.ToArray is that this will not require a dependency on System.Linq.dll
+ ///
+ private static T[] CopyToArray(IEnumerable source)
+ {
+ T[] items = new T[4];
+ int count = 0;
+
+ if (source == null)
+ return null;
+
+ foreach (var item in source)
+ {
+ if (items.Length == count)
+ {
+ var newItems = new T[checked(count * 2)];
+ Array.Copy(items, 0, newItems, 0, count);
+ items = newItems;
+ }
+
+ items[count] = item;
+ count++;
+ }
+
+ if (items.Length == count)
+ return items;
+
+ var finalItems = new T[count];
+ Array.Copy(items, 0, finalItems, 0, count);
+ return finalItems;
+ }
+ }
+}
diff --git a/src/tests/Common/CoreCLRTestLibrary/Assertion.cs b/src/tests/Common/CoreCLRTestLibrary/Assertion.cs
deleted file mode 100644
index f921ce2983436f..00000000000000
--- a/src/tests/Common/CoreCLRTestLibrary/Assertion.cs
+++ /dev/null
@@ -1,822 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-// Note: Exception messages call ToString instead of Name to avoid MissingMetadataException when just outputting basic info
-
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace TestLibrary
-{
- ///
- /// A collection of helper classes to test various conditions within
- /// unit tests. If the condition being tested is not met, an exception
- /// is thrown.
- ///
- public static class Assert
- {
- ///
- /// Asserts that the given delegate throws an with the given parameter name.
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// A containing the parameter of name to check, to skip parameter validation.
- ///
- ///
- /// The thrown .
- ///
- ///
- /// of type was not thrown.
- ///
- /// -or-
- ///
- /// is not equal to .
- ///
- public static ArgumentNullException ThrowsArgumentNullException(string parameterName, Action action, string message = null)
- {
- return ThrowsArgumentException(parameterName, action, message);
- }
-
- ///
- /// Asserts that the given delegate throws an with the given parameter name.
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// A containing the parameter of name to check, to skip parameter validation.
- ///
- ///
- /// The thrown .
- ///
- ///
- /// of type was not thrown.
- ///
- /// -or-
- ///
- /// is not equal to .
- ///
- public static ArgumentException ThrowsArgumentException(string parameterName, Action action, string message = null)
- {
- return ThrowsArgumentException(parameterName, action, message);
- }
-
- ///
- /// Asserts that the given delegate throws an of type with the given parameter name.
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// A containing the parameter of name to check, to skip parameter validation.
- ///
- ///
- /// The thrown .
- ///
- ///
- /// of type was not thrown.
- ///
- /// -or-
- ///
- /// is not equal to .
- ///
- public static T ThrowsArgumentException(string parameterName, Action action, string message = null)
- where T : ArgumentException
- {
- T exception = Throws(action, message);
-
-#if DEBUG
- // ParamName's not available on ret builds
- if (parameterName != null)
- Assert.AreEqual(parameterName, exception.ParamName, "Expected '{0}.ParamName' to be '{1}'. {2}", typeof(T), parameterName, message);
-#endif
-
- return exception;
- }
-
- ///
- /// Asserts that the given delegate throws an with a base exception of type .
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// The base of the .
- ///
- ///
- /// of was not thrown.
- /// -or-
- ///
- /// is not of type .
- ///
- public static TBase ThrowsAggregateException(Action action, string message = "") where TBase : Exception
- {
- AggregateException exception = Throws(action, message);
-
- Exception baseException = exception.GetBaseException();
- if (baseException == null)
- Assert.Fail("Expected 'AggregateException.GetBaseException()' to be '{0}', however it is null. {1}", typeof(TBase), message);
-
- if (baseException.GetType() != typeof(TBase))
- Assert.Fail("Expected 'AggregateException.GetBaseException()', to be '{0}', however, '{1}' is. {2}", typeof(TBase), baseException.GetType(), message);
-
- return (TBase)baseException;
- }
-
- ///
- /// Asserts that the given delegate throws an of type .
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing format information for when the assertion fails.
- ///
- ///
- /// An of arguments to be formatted.
- ///
- ///
- /// The thrown .
- ///
- ///
- /// of type was not thrown.
- ///
- public static T Throws(Action action, string format, params Object[] args) where T : Exception
- {
- return Throws(action, String.Format(format, args));
- }
-
- ///
- /// Asserts that the given delegate throws an of type .
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// Specifies whether should require an exact type match when comparing the expected exception type with the thrown exception. The default is .
- ///
- ///
- /// The thrown .
- ///
- ///
- /// of type was not thrown.
- ///
- public static T Throws(Action action, string message = "", AssertThrowsOptions options = AssertThrowsOptions.None) where T : Exception
- {
- Exception exception = RunWithCatch(action);
-
- if (exception == null)
- Assert.Fail("Expected '{0}' to be thrown. {1}", typeof(T).ToString(), message);
-
- if (!IsOfExceptionType(exception, options))
- Assert.Fail("Expected '{0}' to be thrown, however '{1}' was thrown. {2}", typeof(T), exception.GetType(), message);
-
- return (T)exception;
- }
-
- ///
- /// Asserts that the given async delegate throws an of type
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// Specifies whether should require an exact type match when comparing the expected exception type with the thrown exception. The default is .
- ///
- ///
- /// The thrown .
- ///
- ///
- /// of type was not thrown.
- ///
- public static async Task ThrowsAsync(Func action, string message = "", AssertThrowsOptions options = AssertThrowsOptions.None) where T : Exception
- {
- Exception exception = await RunWithCatchAsync(action);
-
- if (exception == null)
- Assert.Fail("Expected '{0}' to be thrown. {1}", typeof(T).ToString(), message);
-
- if (!IsOfExceptionType(exception, options))
- Assert.Fail("Expected '{0}' to be thrown, however '{1}' was thrown. {2}", typeof(T), exception.GetType(), message);
-
- return (T)exception;
- }
-
- ///
- /// Asserts that the given async delegate throws an of type and
- /// returns an of type .
- ///
- ///
- /// The delagate of type to execute.
- ///
- ///
- /// A containing additional information for when the assertion fails.
- ///
- ///
- /// Specifies whether should require an exact type match when comparing the expected exception type with the thrown exception. The default is .
- ///
- ///
- /// The thrown inner .
- ///
- ///
- /// of type was not thrown.
- ///
- /// -or-
- ///
- /// is not of type .
- ///
- public static TInner Throws(Action action, string message = "", AssertThrowsOptions options = AssertThrowsOptions.None)
- where T : Exception
- where TInner : Exception
- {
- T outerException = Throws(action, message, options);
-
- if (outerException.InnerException == null)
- Assert.Fail("Expected '{0}.InnerException' to be '{1}', however it is null. {2}", typeof(T), typeof(TInner), message);
-
- if (!IsOfExceptionType(outerException.InnerException, options))
- Assert.Fail("Expected '{0}.InnerException', to be '{1}', however, '{2}' is. {3}", typeof(T), typeof(TInner), outerException.InnerException.GetType(), message);
-
- return (TInner)outerException.InnerException;
- }
-
-
- ///
- /// Tests whether the specified condition is true and throws an exception
- /// if the condition is false.
- ///
- /// The condition the test expects to be true.
- ///
- /// The message to include in the exception when
- /// is false. The message is shown in test results.
- ///
- ///
- /// Thrown if is false.
- ///
- public static void IsTrue(bool condition, string format, params Object[] args)
- {
- if (!condition)
- {
- Assert.HandleFail("Assert.IsTrue", String.Format(format, args));
- }
- }
-
- ///
- /// Tests whether the specified condition is true and throws an exception
- /// if the condition is false.
- ///
- /// The condition the test expects to be true.
- ///
- /// The message to include in the exception when
- /// is false. The message is shown in test results.
- ///
- ///
- /// Thrown if is false.
- ///
- public static void IsTrue(bool condition, string message = "")
- {
- if (!condition)
- {
- Assert.HandleFail("Assert.IsTrue", message);
- }
- }
-
- ///
- /// Tests whether the specified condition is false and throws an exception
- /// if the condition is true.
- ///
- /// The condition the test expects to be false.
- ///
- /// The message to include in the exception when
- /// is true. The message is shown in test results.
- ///
- ///
- /// Thrown if is true.
- ///
- public static void IsFalse(bool condition, string message = "")
- {
- if (condition)
- {
- Assert.HandleFail("Assert.IsFalse", message);
- }
- }
-
- ///
- /// Tests whether the specified condition is false and throws an exception
- /// if the condition is true.
- ///
- /// The condition the test expects to be false.
- ///
- /// The message to include in the exception when
- /// is true. The message is shown in test results.
- ///
- ///
- /// Thrown if is true.
- ///
- public static void IsFalse(bool condition, string format, params Object[] args)
- {
- IsFalse(condition, String.Format(format, args));
- }
-
- ///
- /// Tests whether the specified object is null and throws an exception
- /// if it is not.
- ///
- /// The object the test expects to be null.
- ///
- /// The message to include in the exception when
- /// is not null. The message is shown in test results.
- ///
- ///
- /// Thrown if is not null.
- ///
- public static void IsNull(object value, string message = "")
- {
- if (value != null)
- {
- Assert.HandleFail("Assert.IsNull", message);
- }
- }
-
- ///
- /// Tests whether the specified object is null and throws an exception
- /// if it is not.
- ///
- /// The object the test expects to be null.
- ///
- /// The message to include in the exception when
- /// is not null. The message is shown in test results.
- ///
- ///
- /// Thrown if is not null.
- ///
- public static void IsNull(object value, string format, params Object[] args)
- {
- IsNull(value, String.Format(format, args));
- }
-
- ///
- /// Tests whether the specified object is non-null and throws an exception
- /// if it is null.
- ///
- /// The object the test expects not to be null.
- ///
- /// The message to include in the exception when
- /// is null. The message is shown in test results.
- ///
- ///
- /// Thrown if is null.
- ///
- public static void IsNotNull(object value, string message = "")
- {
- if (value == null)
- {
- Assert.HandleFail("Assert.IsNotNull", message);
- }
- }
-
- ///
- /// Tests whether the expected object is equal to the actual object and
- /// throws an exception if it is not.
- ///
- /// Expected object.
- /// Actual object.
- /// Message to display upon failure.
- public static void AreEqual(T expected, T actual, string message = "")
- {
- const string EXPECTED_MSG = @"Expected: [{1}]. Actual: [{2}]. {0}";
-
- if (!Object.Equals(expected, actual))
- {
- string finalMessage = String.Format(EXPECTED_MSG, message, (object)expected ?? "NULL", (object)actual ?? "NULL");
- Assert.HandleFail("Assert.AreEqual", finalMessage);
- }
- }
-
- ///
- /// Tests whether the expected object is equal to the actual object and
- /// throws an exception if it is not.
- ///
- /// Expected object.
- /// Actual object.
- /// Message to display upon failure.
- public static void AreEqual(T expected, T actual, string format, params Object[] args)
- {
- AreEqual(expected, actual, String.Format(format, args));
- }
-
- ///
- /// Tests whether the expected object is equal to the actual object and
- /// throws an exception if it is not.
- ///
- /// Expected object that we do not want it to be.
- /// Actual object.
- /// Message to display upon failure.
- public static void AreNotEqual(T notExpected, T actual, string message = "")
- {
- if (Object.Equals(notExpected, actual))
- {
- String finalMessage =
- String.Format(@"Expected any value except:[{1}]. Actual:[{2}]. {0}",
- message, notExpected, actual);
-
- Assert.HandleFail("Assert.AreNotEqual", finalMessage);
- }
- }
-
- ///
- /// Tests whether the expected object is equal to the actual object and
- /// throws an exception if it is not.
- ///
- /// Expected object that we do not want it to be.
- /// Actual object.
- /// Message to display upon failure.
- public static void AreNotEqual(T notExpected, T actual, string format, params Object[] args)
- {
- AreNotEqual(notExpected, actual, String.Format(format, args));
- }
-
- ///
- /// Tests whether the two lists are the same length and contain the same objects (using Object.Equals()) in the same order and
- /// throws an exception if it is not.
- ///
- /// Expected list.
- /// Actual list.
- /// Message to display upon failure.
- public static void AreAllEqual(T[] expected, T[] actual, string message = "")
- {
- Assert.AreEqual(expected.Length, actual.Length, message);
-
- for (int i = 0; i < expected.Length; i++)
- Assert.AreEqual(expected[i], actual[i], message);
- }
-
- ///
- /// Tests whether the two lists are the same length and contain the same objects (using Object.Equals()) in the same order and
- /// throws an exception if it is not.
- ///
- /// Expected list.
- /// Actual list.
- /// Message to display upon failure.
- public static void AreAllEqual(T[] expected, T[] actual, string format, params Object[] args)
- {
- AreAllEqual(expected, actual, String.Format(format, args));
- }
-
- ///
- /// Tests whether the two lists are the same length and contain the same objects (using Object.Equals()) (but not necessarily in the same order) and
- /// throws an exception if it is not.
- ///
- /// Expected list.
- /// Actual list.
- /// Message to display upon failure.
- public static void AreAllEqualUnordered(T[] expected, T[] actual)
- {
- Assert.AreEqual(expected.Length, actual.Length);
-
- int count = expected.Length;
- bool[] removedFromActual = new bool[count];
- for (int i = 0; i < count; i++)
- {
- T item1 = expected[i];
- bool foundMatch = false;
- for (int j = 0; j < count; j++)
- {
- if (!removedFromActual[j])
- {
- T item2 = actual[j];
- if ((item1 == null && item2 == null) || (item1 != null && item1.Equals(item2)))
- {
- foundMatch = true;
- removedFromActual[j] = true;
- break;
- }
- }
- }
- if (!foundMatch)
- Assert.HandleFail("Assert.AreAllEqualUnordered", "First array has element not found in second array: " + item1);
- }
- return;
- }
-
- ///
- /// Tests whether the two enumerables are the same length and contain the same objects (using Object.Equals()) in the same order and
- /// throws an exception if it is not.
- ///
- /// Expected enumerables.
- /// Actual enumerables.
- /// Message to display upon failure.
- public static void AreAllEqual(IEnumerable expected, IEnumerable actual, string message = "")
- {
- AreAllEqual(CopyToArray(expected), CopyToArray(actual), message);
- }
-
- ///
- /// Tests whether the two enumerables are the same length and contain the same objects (using Object.Equals()) (but not necessarily
- /// in the same order) and throws an exception if it is not.
- ///
- /// Expected enumerable.
- /// Actual enumerable.
- /// Message to display upon failure.
- public static void AreAllEqualUnordered(IEnumerable expected, IEnumerable actual, string message = "")
- {
- AreAllEqualUnordered(CopyToArray(expected), CopyToArray(actual), message);
- }
-
- ///
- /// Iterates through an IEnumerable to generate an array of elements. The rational for using this instead of
- /// System.Linq.ToArray is that this will not require a dependency on System.Linq.dll
- ///
- private static T[] CopyToArray(IEnumerable source)
- {
- T[] items = new T[4];
- int count = 0;
-
- if (source == null)
- return null;
-
- foreach (var item in source)
- {
- if (items.Length == count)
- {
- var newItems = new T[checked(count * 2)];
- Array.Copy(items, 0, newItems, 0, count);
- items = newItems;
- }
-
- items[count] = item;
- count++;
- }
-
- if (items.Length == count)
- return items;
-
- var finalItems = new T[count];
- Array.Copy(items, 0, finalItems, 0, count);
- return finalItems;
- }
-
-
- ///
- /// 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.
- ///
- ///
- /// The first object to compare. This is the value the test expects.
- ///
- ///
- /// The second object to compare. This is the value produced by the code under test.
- ///
- ///
- /// Thrown if does not refer to the same object
- /// as .
- ///
- static public void AreSame(object expected, object actual)
- {
- Assert.AreSame(expected, actual, string.Empty);
- }
-
- ///
- /// 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.
- ///
- ///
- /// The first object to compare. This is the value the test expects.
- ///
- ///
- /// The second object to compare. This is the value produced by the code under test.
- ///
- ///
- /// The message to include in the exception when
- /// is not the same as . The message is shown
- /// in test results.
- ///
- ///
- /// Thrown if does not refer to the same object
- /// as .
- ///
- static public void AreSame(object expected, object actual, string message)
- {
- if (!Object.ReferenceEquals(expected, actual))
- {
- string finalMessage = message;
-
- ValueType valExpected = expected as ValueType;
- if (valExpected != null)
- {
- ValueType valActual = actual as ValueType;
- if (valActual != null)
- {
- finalMessage = message == null ? String.Empty : message;
- }
- }
-
- Assert.HandleFail("Assert.AreSame", finalMessage);
- }
- }
-
- ///
- /// Tests whether the specified objects refer to different objects and
- /// throws an exception if the two inputs refer to the same object.
- ///
- ///
- /// The first object to compare. This is the value the test expects not
- /// to match .
- ///
- ///
- /// The second object to compare. This is the value produced by the code under test.
- ///
- ///
- /// Thrown if refers to the same object
- /// as .
- ///
- static public void AreNotSame(object notExpected, object actual)
- {
- Assert.AreNotSame(notExpected, actual, string.Empty);
- }
-
- ///
- /// Tests whether the specified objects refer to different objects and
- /// throws an exception if the two inputs refer to the same object.
- ///
- ///
- /// The first object to compare. This is the value the test expects not
- /// to match .
- ///
- ///
- /// The second object to compare. This is the value produced by the code under test.
- ///
- ///
- /// The message to include in the exception when
- /// is the same as . The message is shown in
- /// test results.
- ///
- ///
- /// Thrown if refers to the same object
- /// as .
- ///
- static public void AreNotSame(object notExpected, object actual, string message)
- {
- if (Object.ReferenceEquals(notExpected, actual))
- {
- Assert.HandleFail("Assert.AreNotSame", message);
- }
- }
-
- static public void OfType(object obj)
- {
- if (!(obj is T))
- {
- Assert.HandleFail(
- "Assert.IsOfType",
- $"Expected an object of type [{typeof(T).AssemblyQualifiedName}], got type of type [{obj.GetType().AssemblyQualifiedName}].");
- }
- }
-
- ///
- /// Throws an AssertFailedException.
- ///
- ///
- /// Always thrown.
- ///
- public static void Fail()
- {
- Assert.HandleFail("Assert.Fail", "");
- }
-
- ///
- /// Throws an AssertFailedException.
- ///
- ///
- /// The message to include in the exception. The message is shown in
- /// test results.
- ///
- ///
- /// Always thrown.
- ///
- public static void Fail(string message, params object[] args)
- {
- string exceptionMessage = args.Length == 0 ? message : string.Format(message, args);
- Assert.HandleFail("Assert.Fail", exceptionMessage);
- }
-
- ///
- /// Helper function that creates and throws an exception.
- ///
- /// name of the assertion throwing an exception.
- /// message describing conditions for assertion failure.
- /// The parameters.
- /// TODO: Modify HandleFail to take in parameters
- internal static void HandleFail(string assertionName, string message)
- {
- // change this to use AssertFailedException
- throw new AssertTestException(assertionName + ": " + message);
- }
-
-
- [Obsolete("Did you mean to call Assert.AreEqual()")]
- public static new bool Equals(Object o1, Object o2)
- {
- Assert.Fail("Don\u2019t call this.");
- throw new Exception();
- }
-
- private static bool IsOfExceptionType(Exception thrown, AssertThrowsOptions options)
- {
- if ((options & AssertThrowsOptions.AllowDerived) == AssertThrowsOptions.AllowDerived)
- return thrown is T;
-
- return thrown.GetType() == typeof(T);
- }
-
- private static Exception RunWithCatch(Action action)
- {
- try
- {
- action();
- return null;
- }
- catch (Exception ex)
- {
- return ex;
- }
- }
-
- private static async Task RunWithCatchAsync(Func action)
- {
- try
- {
- await action();
- return null;
- }
- catch (Exception ex)
- {
- return ex;
- }
- }
- }
-
- ///
- /// Exception raised by the Assert on Fail
- ///
- public class AssertTestException : Exception
- {
- public AssertTestException(string message)
- : base(message)
- {
- }
-
- public AssertTestException()
- : base()
- {
- }
- }
-
- public static class ExceptionAssert
- {
- public static void Throws(String message, Action a) where T : Exception
- {
- Assert.Throws(a, message);
- }
- }
-
- ///
- /// Specifies whether should require an exact type match when comparing the expected exception type with the thrown exception.
- ///
- [Flags]
- public enum AssertThrowsOptions
- {
- ///
- /// Specifies that should require an exact type
- /// match when comparing the specified exception type with the throw exception.
- ///
- None = 0,
-
- ///
- /// Specifies that should not require an exact type
- /// match when comparing the specified exception type with the thrown exception.
- ///
- AllowDerived = 1,
- }
-}
diff --git a/src/tests/Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj b/src/tests/Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj
index bcf8a159d45b13..ec3c6699118784 100644
--- a/src/tests/Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj
+++ b/src/tests/Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj
@@ -8,7 +8,7 @@
$(NetCoreAppToolCurrent)
-
+
@@ -17,4 +17,7 @@
+
+
+
diff --git a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs
index bd1eb1be37de73..a7917eb640a84d 100644
--- a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs
+++ b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs
@@ -13,6 +13,7 @@
using System.Security;
using System.Text;
using System.Threading;
+using Xunit;
namespace TestLibrary
{
@@ -205,7 +206,7 @@ internal static uint GetWindowsVersion()
return 0;
}
- Assert.AreEqual(0, Ntdll.RtlGetVersionEx(out Ntdll.RTL_OSVERSIONINFOEX osvi));
+ Assert.Equal(0, Ntdll.RtlGetVersionEx(out Ntdll.RTL_OSVERSIONINFOEX osvi));
return osvi.dwMajorVersion;
}
internal static uint GetWindowsMinorVersion()
@@ -215,7 +216,7 @@ internal static uint GetWindowsMinorVersion()
return 0;
}
- Assert.AreEqual(0, Ntdll.RtlGetVersionEx(out Ntdll.RTL_OSVERSIONINFOEX osvi));
+ Assert.Equal(0, Ntdll.RtlGetVersionEx(out Ntdll.RTL_OSVERSIONINFOEX osvi));
return osvi.dwMinorVersion;
}
internal static uint GetWindowsBuildNumber()
@@ -225,7 +226,7 @@ internal static uint GetWindowsBuildNumber()
return 0;
}
- Assert.AreEqual(0, Ntdll.RtlGetVersionEx(out Ntdll.RTL_OSVERSIONINFOEX osvi));
+ Assert.Equal(0, Ntdll.RtlGetVersionEx(out Ntdll.RTL_OSVERSIONINFOEX osvi));
return osvi.dwBuildNumber;
}
diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets
index 26c8ae6aa3e631..94098734f6fcfd 100644
--- a/src/tests/Directory.Build.targets
+++ b/src/tests/Directory.Build.targets
@@ -231,7 +231,7 @@
-
+ false
diff --git a/src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.cs b/src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.cs
index 03335e402f4ce0..57e26d9df8384a 100644
--- a/src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.cs
+++ b/src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.cs
@@ -5,7 +5,7 @@
using System.Linq;
using System.Threading;
using System.Runtime.InteropServices;
-using TestLibrary;
+using Xunit;
#pragma warning disable CS0612, CS0618
@@ -17,29 +17,29 @@ public static int Main()
{
var boolArray = new bool[] { true, false, true, false, false, true };
SafeArrayNative.XorBoolArray(boolArray, out var xorResult);
- Assert.AreEqual(XorArray(boolArray), xorResult);
+ Assert.Equal(XorArray(boolArray), xorResult);
var decimalArray = new decimal[] { 1.5M, 30.2M, 6432M, 12.5832M };
SafeArrayNative.MeanDecimalArray(decimalArray, out var meanDecimalValue);
- Assert.AreEqual(decimalArray.Average(), meanDecimalValue);
+ Assert.Equal(decimalArray.Average(), meanDecimalValue);
SafeArrayNative.SumCurrencyArray(decimalArray, out var sumCurrencyValue);
- Assert.AreEqual(decimalArray.Sum(), sumCurrencyValue);
+ Assert.Equal(decimalArray.Sum(), sumCurrencyValue);
var strings = new [] {"ABCDE", "12345", "Microsoft"};
var reversedStrings = strings.Select(str => Reverse(str)).ToArray();
var ansiTest = strings.ToArray();
SafeArrayNative.ReverseStringsAnsi(ansiTest);
- Assert.AreAllEqual(reversedStrings, ansiTest);
+ AssertExtensions.CollectionEqual(reversedStrings, ansiTest);
var unicodeTest = strings.ToArray();
SafeArrayNative.ReverseStringsUnicode(unicodeTest);
- Assert.AreAllEqual(reversedStrings, unicodeTest);
+ AssertExtensions.CollectionEqual(reversedStrings, unicodeTest);
var bstrTest = strings.ToArray();
SafeArrayNative.ReverseStringsBSTR(bstrTest);
- Assert.AreAllEqual(reversedStrings, bstrTest);
+ AssertExtensions.CollectionEqual(reversedStrings, bstrTest);
var blittableRecords = new SafeArrayNative.BlittableRecord[]
{
@@ -50,23 +50,23 @@ public static int Main()
new SafeArrayNative.BlittableRecord { a = 9 },
new SafeArrayNative.BlittableRecord { a = 15 },
};
- Assert.AreAllEqual(blittableRecords, SafeArrayNative.CreateSafeArrayOfRecords(blittableRecords));
+ AssertExtensions.CollectionEqual(blittableRecords, SafeArrayNative.CreateSafeArrayOfRecords(blittableRecords));
var nonBlittableRecords = boolArray.Select(b => new SafeArrayNative.NonBlittableRecord{ b = b }).ToArray();
- Assert.AreAllEqual(nonBlittableRecords, SafeArrayNative.CreateSafeArrayOfRecords(nonBlittableRecords));
+ AssertExtensions.CollectionEqual(nonBlittableRecords, SafeArrayNative.CreateSafeArrayOfRecords(nonBlittableRecords));
var objects = new object[] { new object(), new object(), new object() };
SafeArrayNative.VerifyIUnknownArray(objects);
SafeArrayNative.VerifyIDispatchArray(objects);
var variantInts = new object[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
-
+
SafeArrayNative.MeanVariantIntArray(variantInts, out var variantMean);
- Assert.AreEqual(variantInts.OfType().Average(), variantMean);
+ Assert.Equal(variantInts.OfType().Average(), variantMean);
var dates = new DateTime[] { new DateTime(2008, 5, 1), new DateTime(2010, 1, 1) };
SafeArrayNative.DistanceBetweenDates(dates, out var numDays);
- Assert.AreEqual((dates[1] - dates[0]).TotalDays, numDays);
+ Assert.Equal((dates[1] - dates[0]).TotalDays, numDays);
SafeArrayNative.XorBoolArrayInStruct(
new SafeArrayNative.StructWithSafeArray
@@ -75,7 +75,7 @@ public static int Main()
},
out var structXor);
- Assert.AreEqual(XorArray(boolArray), structXor);
+ Assert.Equal(XorArray(boolArray), structXor);
}
catch (Exception e)
{
diff --git a/src/tests/Interop/COM/Activator/Program.cs b/src/tests/Interop/COM/Activator/Program.cs
index 04049e79c2a828..b16802db9c93bd 100644
--- a/src/tests/Interop/COM/Activator/Program.cs
+++ b/src/tests/Interop/COM/Activator/Program.cs
@@ -10,6 +10,7 @@ namespace Activator
using System.Runtime.InteropServices;
using TestLibrary;
+ using Xunit;
using Console = Internal.Console;
@@ -28,8 +29,7 @@ static void InvalidInterfaceRequest()
InterfaceId = notIClassFactory
};
ComActivator.GetClassFactoryForType(cxt);
- },
- "Non-IClassFactory request should fail");
+ });
}
static void NonrootedAssemblyPath(bool builtInComDisabled)
@@ -48,11 +48,11 @@ static void NonrootedAssemblyPath(bool builtInComDisabled)
if (!builtInComDisabled)
{
- Assert.Throws(action, "Non-root assembly path should not be valid");
+ Assert.Throws(action);
}
else
{
- Assert.Throws(action, "Built-in COM has been disabled via a feature switch");
+ Assert.Throws(action);
}
}
@@ -74,13 +74,13 @@ static void ClassNotRegistered(bool builtInComDisabled)
if (!builtInComDisabled)
{
- COMException e = Assert.Throws(action, "Class should not be found");
+ COMException e = Assert.Throws(action);
const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111);
- Assert.AreEqual(CLASS_E_CLASSNOTAVAILABLE, e.HResult, "Unexpected HRESULT");
+ Assert.Equal(CLASS_E_CLASSNOTAVAILABLE, e.HResult);
}
else
{
- Assert.Throws(action, "Built-in COM has been disabled via a feature switch");
+ Assert.Throws(action);
}
}
@@ -119,7 +119,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled)
if (builtInComDisabled)
{
Assert.Throws(
- () => ComActivator.GetClassFactoryForType(cxt), "Built-in COM has been disabled via a feature switch");
+ () => ComActivator.GetClassFactoryForType(cxt));
return;
}
@@ -156,7 +156,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled)
typeCFromAssemblyB = (Type)svr.GetTypeFromC();
}
- Assert.AreNotEqual(typeCFromAssemblyA, typeCFromAssemblyB, "Types should be from different AssemblyLoadContexts");
+ Assert.NotEqual(typeCFromAssemblyA, typeCFromAssemblyB);
}
static void ValidateUserDefinedRegistrationCallbacks()
@@ -208,15 +208,15 @@ static void ValidateUserDefinedRegistrationCallbacks()
Marshal.Release(svrRaw);
var inst = (IValidateRegistrationCallbacks)svr;
- Assert.IsFalse(inst.DidRegister());
- Assert.IsFalse(inst.DidUnregister());
+ Assert.False(inst.DidRegister());
+ Assert.False(inst.DidUnregister());
cxt.InterfaceId = Guid.Empty;
ComActivator.ClassRegistrationScenarioForType(cxt, register: true);
ComActivator.ClassRegistrationScenarioForType(cxt, register: false);
- Assert.IsTrue(inst.DidRegister(), $"User-defined register function should have been called.");
- Assert.IsTrue(inst.DidUnregister(), $"User-defined unregister function should have been called.");
+ Assert.True(inst.DidRegister(), $"User-defined register function should have been called.");
+ Assert.True(inst.DidUnregister(), $"User-defined unregister function should have been called.");
}
}
@@ -258,7 +258,7 @@ static void ValidateUserDefinedRegistrationCallbacks()
exceptionThrown = true;
}
- Assert.IsTrue(exceptionThrown || !inst.DidRegister());
+ Assert.True(exceptionThrown || !inst.DidRegister());
exceptionThrown = false;
try
@@ -270,7 +270,7 @@ static void ValidateUserDefinedRegistrationCallbacks()
exceptionThrown = true;
}
- Assert.IsTrue(exceptionThrown || !inst.DidUnregister());
+ Assert.True(exceptionThrown || !inst.DidUnregister());
}
}
}
diff --git a/src/tests/Interop/COM/ComWrappers/API/Program.cs b/src/tests/Interop/COM/ComWrappers/API/Program.cs
index 98f09ac4d00a70..99a2094c80b912 100644
--- a/src/tests/Interop/COM/ComWrappers/API/Program.cs
+++ b/src/tests/Interop/COM/ComWrappers/API/Program.cs
@@ -10,7 +10,7 @@ namespace ComWrappersTests
using System.Runtime.InteropServices;
using ComWrappersTests.Common;
- using TestLibrary;
+ using Xunit;
class Program
{
@@ -54,7 +54,7 @@ protected override object CreateObject(IntPtr externalComObject, CreateObjectFla
var iid = typeof(ITrackerObject).GUID;
IntPtr iTrackerComObject;
int hr = Marshal.QueryInterface(externalComObject, ref iid, out iTrackerComObject);
- Assert.AreEqual(0, hr);
+ Assert.Equal(0, hr);
return new ITrackerObjectWrapper(iTrackerComObject);
}
@@ -72,9 +72,9 @@ public static void ValidateIUnknownImpls()
ComWrappers.GetIUnknownImpl(out IntPtr fpQueryInterface, out IntPtr fpAddRef, out IntPtr fpRelease);
- Assert.AreNotEqual(fpQueryInterface, IntPtr.Zero);
- Assert.AreNotEqual(fpAddRef, IntPtr.Zero);
- Assert.AreNotEqual(fpRelease, IntPtr.Zero);
+ Assert.NotEqual(fpQueryInterface, IntPtr.Zero);
+ Assert.NotEqual(fpAddRef, IntPtr.Zero);
+ Assert.NotEqual(fpRelease, IntPtr.Zero);
}
}
@@ -100,27 +100,27 @@ static void ValidateComInterfaceCreation()
// Allocate a wrapper for the object
IntPtr comWrapper = wrappers.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
- Assert.AreNotEqual(IntPtr.Zero, comWrapper);
+ Assert.NotEqual(IntPtr.Zero, comWrapper);
// Get a wrapper for an object and verify it is the same one.
IntPtr comWrapperMaybe = wrappers.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
- Assert.AreEqual(comWrapper, comWrapperMaybe);
+ Assert.Equal(comWrapper, comWrapperMaybe);
// Release the wrapper
int count = Marshal.Release(comWrapper);
- Assert.AreEqual(1, count);
+ Assert.Equal(1, count);
count = Marshal.Release(comWrapperMaybe);
- Assert.AreEqual(0, count);
+ Assert.Equal(0, count);
// Create a new wrapper
IntPtr comWrapperNew = wrappers.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
// Once a wrapper is created for a managed object it is always present
- Assert.AreEqual(comWrapperNew, comWrapper);
+ Assert.Equal(comWrapperNew, comWrapper);
// Release the new wrapper
count = Marshal.Release(comWrapperNew);
- Assert.AreEqual(0, count);
+ Assert.Equal(0, count);
}
static void ValidateComInterfaceCreationRoundTrip()
@@ -133,14 +133,14 @@ static void ValidateComInterfaceCreationRoundTrip()
// Allocate a wrapper for the object
IntPtr comWrapper = wrappers.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.None);
- Assert.AreNotEqual(IntPtr.Zero, comWrapper);
+ Assert.NotEqual(IntPtr.Zero, comWrapper);
var testObjUnwrapped = wrappers.GetOrCreateObjectForComInstance(comWrapper, CreateObjectFlags.Unwrap);
- Assert.AreEqual(testObj, testObjUnwrapped);
+ Assert.Equal(testObj, testObjUnwrapped);
// Release the wrapper
int count = Marshal.Release(comWrapper);
- Assert.AreEqual(0, count);
+ Assert.Equal(0, count);
}
static void ValidateFallbackQueryInterface()
@@ -163,17 +163,17 @@ static void ValidateFallbackQueryInterface()
var anyGuid = new Guid("1E42439C-DCB5-4701-ACBD-87FE92E785DE");
testObj.ICustomQueryInterface_GetInterfaceIID = anyGuid;
int hr = Marshal.QueryInterface(comWrapper, ref anyGuid, out result);
- Assert.AreEqual(0, hr);
- Assert.AreEqual(testObj.ICustomQueryInterface_GetInterfaceResult, result);
+ Assert.Equal(0, hr);
+ Assert.Equal(testObj.ICustomQueryInterface_GetInterfaceResult, result);
var anyGuid2 = new Guid("7996D0F9-C8DD-4544-B708-0F75C6FF076F");
hr = Marshal.QueryInterface(comWrapper, ref anyGuid2, out result);
const int E_NOINTERFACE = unchecked((int)0x80004002);
- Assert.AreEqual(E_NOINTERFACE, hr);
- Assert.AreEqual(IntPtr.Zero, result);
+ Assert.Equal(E_NOINTERFACE, hr);
+ Assert.Equal(IntPtr.Zero, result);
int count = Marshal.Release(comWrapper);
- Assert.AreEqual(0, count);
+ Assert.Equal(0, count);
}
static void ValidateCreateObjectCachingScenario()
@@ -187,13 +187,13 @@ static void ValidateCreateObjectCachingScenario()
var trackerObj1 = (ITrackerObjectWrapper)cw.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject);
var trackerObj2 = (ITrackerObjectWrapper)cw.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject);
- Assert.AreEqual(trackerObj1, trackerObj2);
+ Assert.Equal(trackerObj1, trackerObj2);
// Ownership has been transferred to the wrapper.
Marshal.Release(trackerObjRaw);
var trackerObj3 = (ITrackerObjectWrapper)cw.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject | CreateObjectFlags.UniqueInstance);
- Assert.AreNotEqual(trackerObj1, trackerObj3);
+ Assert.NotEqual(trackerObj1, trackerObj3);
}
static void ValidateWrappersInstanceIsolation()
@@ -208,15 +208,15 @@ static void ValidateWrappersInstanceIsolation()
// Allocate a wrapper for the object
IntPtr comWrapper1 = cw1.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
IntPtr comWrapper2 = cw2.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
- Assert.AreNotEqual(comWrapper1, IntPtr.Zero);
- Assert.AreNotEqual(comWrapper2, IntPtr.Zero);
- Assert.AreNotEqual(comWrapper1, comWrapper2);
+ Assert.NotEqual(comWrapper1, IntPtr.Zero);
+ Assert.NotEqual(comWrapper2, IntPtr.Zero);
+ Assert.NotEqual(comWrapper1, comWrapper2);
IntPtr comWrapper3 = cw1.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
IntPtr comWrapper4 = cw2.GetOrCreateComInterfaceForObject(testObj, CreateComInterfaceFlags.TrackerSupport);
- Assert.AreNotEqual(comWrapper3, comWrapper4);
- Assert.AreEqual(comWrapper1, comWrapper3);
- Assert.AreEqual(comWrapper2, comWrapper4);
+ Assert.NotEqual(comWrapper3, comWrapper4);
+ Assert.Equal(comWrapper1, comWrapper3);
+ Assert.Equal(comWrapper2, comWrapper4);
Marshal.Release(comWrapper1);
Marshal.Release(comWrapper2);
@@ -229,13 +229,13 @@ static void ValidateWrappersInstanceIsolation()
// Create objects for the COM instance
var trackerObj1 = (ITrackerObjectWrapper)cw1.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject);
var trackerObj2 = (ITrackerObjectWrapper)cw2.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject);
- Assert.AreNotEqual(trackerObj1, trackerObj2);
+ Assert.NotEqual(trackerObj1, trackerObj2);
var trackerObj3 = (ITrackerObjectWrapper)cw1.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject);
var trackerObj4 = (ITrackerObjectWrapper)cw2.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject);
- Assert.AreNotEqual(trackerObj3, trackerObj4);
- Assert.AreEqual(trackerObj1, trackerObj3);
- Assert.AreEqual(trackerObj2, trackerObj4);
+ Assert.NotEqual(trackerObj3, trackerObj4);
+ Assert.Equal(trackerObj1, trackerObj3);
+ Assert.Equal(trackerObj2, trackerObj4);
Marshal.Release(trackerObjRaw);
}
@@ -253,12 +253,12 @@ static void ValidatePrecreatedExternalWrapper()
var iid = typeof(ITrackerObject).GUID;
IntPtr iTestComObject;
int hr = Marshal.QueryInterface(trackerObjRaw, ref iid, out iTestComObject);
- Assert.AreEqual(0, hr);
+ Assert.Equal(0, hr);
var nativeWrapper = new ITrackerObjectWrapper(iTestComObject);
// Register wrapper, but supply the wrapper.
var nativeWrapper2 = (ITrackerObjectWrapper)cw.GetOrRegisterObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject, nativeWrapper);
- Assert.AreEqual(nativeWrapper, nativeWrapper2);
+ Assert.Equal(nativeWrapper, nativeWrapper2);
// Ownership has been transferred to the wrapper.
Marshal.Release(trackerObjRaw);
@@ -300,12 +300,12 @@ static void ValidateExternalWrapperCacheCleanUp()
// We are using a tracking resurrection WeakReference so we should be able
// to get back the objects as they are all continually re-registering for Finalization.
- Assert.IsTrue(weakRef1.TryGetTarget(out ITrackerObjectWrapper wrapper1));
- Assert.IsTrue(weakRef2.TryGetTarget(out ITrackerObjectWrapper wrapper2));
+ Assert.True(weakRef1.TryGetTarget(out ITrackerObjectWrapper wrapper1));
+ Assert.True(weakRef2.TryGetTarget(out ITrackerObjectWrapper wrapper2));
// Check that the two wrappers aren't equal, meaning we created a new wrapper since
// the first wrapper was removed from the internal cache.
- Assert.AreNotEqual(wrapper1, wrapper2);
+ Assert.NotEqual(wrapper1, wrapper2);
// Let the wrappers Finalize.
wrapper1.ReregisterForFinalize = false;
@@ -317,7 +317,7 @@ static WeakReference CreateAndRegisterWrapper(ComWrappers
var iid = typeof(ITrackerObject).GUID;
IntPtr iTestComObject;
int hr = Marshal.QueryInterface(trackerObjRaw, ref iid, out iTestComObject);
- Assert.AreEqual(0, hr);
+ Assert.Equal(0, hr);
var nativeWrapper = new ITrackerObjectWrapper(iTestComObject);
nativeWrapper = (ITrackerObjectWrapper)cw.GetOrRegisterObjectForComInstance(trackerObjRaw, CreateObjectFlags.None, nativeWrapper);
@@ -375,7 +375,7 @@ public enum FailureMode
case FailureMode.ThrowException:
throw new Exception() { HResult = ExceptionErrorCode };
default:
- Assert.Fail("Invalid failure mode");
+ Assert.True(false, "Invalid failure mode");
throw new Exception("UNREACHABLE");
}
}
@@ -389,7 +389,7 @@ protected override object CreateObject(IntPtr externalComObject, CreateObjectFla
case FailureMode.ThrowException:
throw new Exception() { HResult = ExceptionErrorCode };
default:
- Assert.Fail("Invalid failure mode");
+ Assert.True(false, "Invalid failure mode");
throw new Exception("UNREACHABLE");
}
}
@@ -420,7 +420,7 @@ static void ValidateBadComWrapperImpl()
}
catch (Exception e)
{
- Assert.AreEqual(BadComWrappers.ExceptionErrorCode, e.HResult);
+ Assert.Equal(BadComWrappers.ExceptionErrorCode, e.HResult);
}
IntPtr trackerObjRaw = MockReferenceTrackerRuntime.CreateTrackerObject();
@@ -439,7 +439,7 @@ static void ValidateBadComWrapperImpl()
}
catch (Exception e)
{
- Assert.AreEqual(BadComWrappers.ExceptionErrorCode, e.HResult);
+ Assert.Equal(BadComWrappers.ExceptionErrorCode, e.HResult);
}
Marshal.Release(trackerObjRaw);
@@ -475,11 +475,11 @@ static void ValidateRuntimeTrackerScenario()
Marshal.Release(testWrapper);
}
- Assert.IsTrue(testWrapperIds.Count <= Test.InstanceCount);
+ Assert.True(testWrapperIds.Count <= Test.InstanceCount);
ForceGC();
- Assert.IsTrue(testWrapperIds.Count <= Test.InstanceCount);
+ Assert.True(testWrapperIds.Count <= Test.InstanceCount);
// Remove the managed object ref from the native object.
foreach (int id in testWrapperIds)
@@ -518,7 +518,7 @@ static void ValidateQueryInterfaceAfterManagedObjectCollected()
// The COM reference count should be 0 and indicates to the GC the managed object
// can be collected.
refCount = Marshal.Release(testWrapper);
- Assert.AreEqual(0, refCount);
+ Assert.Equal(0, refCount);
}
ForceGC();
@@ -532,11 +532,11 @@ static void ValidateQueryInterfaceAfterManagedObjectCollected()
int hr = Marshal.QueryInterface(refTrackerTarget, ref iid, out iTestComObject);
const int COR_E_ACCESSING_CCW = unchecked((int)0x80131544);
- Assert.AreEqual(COR_E_ACCESSING_CCW, hr);
+ Assert.Equal(COR_E_ACCESSING_CCW, hr);
// Release the IReferenceTrackerTarget instance.
refCount = MockReferenceTrackerRuntime.TrackerTarget_ReleaseFromReferenceTracker(refTrackerTarget);
- Assert.AreEqual(0, refCount);
+ Assert.Equal(0, refCount);
static IntPtr CreateWrapper(TestComWrappers cw)
{
@@ -582,8 +582,8 @@ static void ValidateAggregationWithComObject()
ForceGC();
// Validate all instances were cleaned up
- Assert.IsFalse(weakRef.TryGetTarget(out _));
- Assert.AreEqual(0, allocTracker.GetCount());
+ Assert.False(weakRef.TryGetTarget(out _));
+ Assert.Equal(0, allocTracker.GetCount());
}
static void ValidateAggregationWithReferenceTrackerObject()
@@ -597,13 +597,13 @@ static void ValidateAggregationWithReferenceTrackerObject()
ForceGC();
// Validate all instances were cleaned up.
- Assert.IsFalse(weakRef.TryGetTarget(out _));
+ Assert.False(weakRef.TryGetTarget(out _));
// Reference counter cleanup requires additional GCs since the Finalizer is used
// to clean up the Reference Tracker runtime references.
ForceGC();
- Assert.AreEqual(0, allocTracker.GetCount());
+ Assert.Equal(0, allocTracker.GetCount());
}
static int Main(string[] doNotUse)
diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs
index 1738dbc08affca..bef5f1317497c4 100644
--- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs
+++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs
@@ -7,6 +7,7 @@ namespace ComWrappersTests.GlobalInstance
using ComWrappersTests.Common;
using TestLibrary;
+ using Xunit;
partial class Program
{
@@ -15,7 +16,7 @@ private static void ValidateNotRegisteredForTrackerSupport()
Console.WriteLine($"Running {nameof(ValidateNotRegisteredForTrackerSupport)}...");
int hr = MockReferenceTrackerRuntime.Trigger_NotifyEndOfReferenceTrackingOnThread();
- Assert.AreNotEqual(GlobalComWrappers.ReleaseObjectsCallAck, hr);
+ Assert.NotEqual(GlobalComWrappers.ReleaseObjectsCallAck, hr);
}
static int Main(string[] doNotUse)
diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs
index dd8ea4f5f3e858..f1f45b29896d70 100644
--- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs
+++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs
@@ -8,6 +8,7 @@ namespace ComWrappersTests.GlobalInstance
using ComWrappersTests.Common;
using TestLibrary;
+ using Xunit;
partial class Program
{
@@ -17,11 +18,11 @@ private static void ValidateNotRegisteredForMarshalling()
var testObj = new Test();
IntPtr comWrapper1 = Marshal.GetIUnknownForObject(testObj);
- Assert.IsNull(GlobalComWrappers.Instance.LastComputeVtablesObject, "ComWrappers instance should not have been called");
+ Assert.Null(GlobalComWrappers.Instance.LastComputeVtablesObject);
IntPtr trackerObjRaw = MockReferenceTrackerRuntime.CreateTrackerObject();
object objWrapper = Marshal.GetObjectForIUnknown(trackerObjRaw);
- Assert.IsFalse(objWrapper is FakeWrapper, $"ComWrappers instance should not have been called");
+ Assert.False(objWrapper is FakeWrapper, $"ComWrappers instance should not have been called");
}
static int Main(string[] doNotUse)
diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.cs
index 38c25329315968..d07a0adc89c67c 100644
--- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.cs
+++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.cs
@@ -10,6 +10,7 @@ namespace ComWrappersTests.GlobalInstance
using ComWrappersTests.Common;
using TestLibrary;
+ using Xunit;
partial class Program
{
@@ -173,7 +174,7 @@ protected override void ReleaseObjects(IEnumerable objects)
{
foreach (object o in objects)
{
- Assert.IsNotNull(o);
+ Assert.NotNull(o);
}
throw new Exception() { HResult = ReleaseObjectsCallAck };
@@ -235,14 +236,14 @@ private static void ValidateRegisterForMarshalling()
() =>
{
ComWrappers.RegisterForMarshalling(wrappers1);
- }, "Should not be able to re-register for global ComWrappers");
+ });
var wrappers2 = new GlobalComWrappers();
Assert.Throws(
() =>
{
ComWrappers.RegisterForMarshalling(wrappers2);
- }, "Should not be able to reset for global ComWrappers");
+ });
}
private static void ValidateRegisterForTrackerSupport()
@@ -255,14 +256,14 @@ private static void ValidateRegisterForTrackerSupport()
() =>
{
ComWrappers.RegisterForTrackerSupport(wrappers1);
- }, "Should not be able to re-register for global ComWrappers");
+ });
var wrappers2 = new GlobalComWrappers();
Assert.Throws(
() =>
{
ComWrappers.RegisterForTrackerSupport(wrappers2);
- }, "Should not be able to reset for global ComWrappers");
+ });
}
private static void ValidateMarshalAPIs(bool validateUseRegistered)
@@ -277,11 +278,11 @@ private static void ValidateMarshalAPIs(bool validateUseRegistered)
var testObj = new Test();
IntPtr comWrapper1 = Marshal.GetIUnknownForObject(testObj);
- Assert.AreNotEqual(IntPtr.Zero, comWrapper1);
- Assert.AreEqual(testObj, registeredWrapper.LastComputeVtablesObject, "Registered ComWrappers instance should have been called");
+ Assert.NotEqual(IntPtr.Zero, comWrapper1);
+ Assert.Equal(testObj, registeredWrapper.LastComputeVtablesObject);
IntPtr comWrapper2 = Marshal.GetIUnknownForObject(testObj);
- Assert.AreEqual(comWrapper1, comWrapper2);
+ Assert.Equal(comWrapper1, comWrapper2);
Marshal.Release(comWrapper1);
Marshal.Release(comWrapper2);
@@ -294,29 +295,29 @@ private static void ValidateMarshalAPIs(bool validateUseRegistered)
{
var dispatchObj = new TestEx(IID_IDISPATCH);
IntPtr dispatchWrapper = Marshal.GetIDispatchForObject(dispatchObj);
- Assert.AreNotEqual(IntPtr.Zero, dispatchWrapper);
- Assert.AreEqual(dispatchObj, registeredWrapper.LastComputeVtablesObject, "Registered ComWrappers instance should have been called");
+ Assert.NotEqual(IntPtr.Zero, dispatchWrapper);
+ Assert.Equal(dispatchObj, registeredWrapper.LastComputeVtablesObject);
Console.WriteLine($" -- Validate Marshal.GetIDispatchForObject != Marshal.GetIUnknownForObject...");
IntPtr unknownWrapper = Marshal.GetIUnknownForObject(dispatchObj);
- Assert.AreNotEqual(IntPtr.Zero, unknownWrapper);
- Assert.AreNotEqual(unknownWrapper, dispatchWrapper);
+ Assert.NotEqual(IntPtr.Zero, unknownWrapper);
+ Assert.NotEqual(unknownWrapper, dispatchWrapper);
}
Console.WriteLine($" -- Validate Marshal.GetObjectForIUnknown...");
IntPtr trackerObjRaw = MockReferenceTrackerRuntime.CreateTrackerObject();
object objWrapper1 = Marshal.GetObjectForIUnknown(trackerObjRaw);
- Assert.AreEqual(validateUseRegistered, objWrapper1 is FakeWrapper, $"GetObjectForIUnknown should{(validateUseRegistered ? string.Empty : "not")} have returned {nameof(FakeWrapper)} instance");
+ Assert.Equal(validateUseRegistered, objWrapper1 is FakeWrapper);
object objWrapper2 = Marshal.GetObjectForIUnknown(trackerObjRaw);
- Assert.AreEqual(objWrapper1, objWrapper2);
+ Assert.Equal(objWrapper1, objWrapper2);
Console.WriteLine($" -- Validate Marshal.GetUniqueObjectForIUnknown...");
object objWrapper3 = Marshal.GetUniqueObjectForIUnknown(trackerObjRaw);
- Assert.AreEqual(validateUseRegistered, objWrapper3 is FakeWrapper, $"GetObjectForIUnknown should{(validateUseRegistered ? string.Empty : "not")} have returned {nameof(FakeWrapper)} instance");
+ Assert.Equal(validateUseRegistered, objWrapper3 is FakeWrapper);
- Assert.AreNotEqual(objWrapper1, objWrapper3);
+ Assert.NotEqual(objWrapper1, objWrapper3);
Marshal.Release(trackerObjRaw);
}
@@ -331,7 +332,7 @@ private static void ValidatePInvokes(bool validateUseRegistered)
Console.WriteLine($" -- Validate MarshalAs IUnknown...");
ValidateInterfaceMarshaler