diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.Emptiness.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.Emptiness.cs index 7c31dde4..b4415cc5 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.Emptiness.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.Emptiness.cs @@ -18,10 +18,8 @@ public static partial class AssertExtensions /// /// The instance to extend. /// The value to be tested. - public static void IsEmpty(this Assert assert, string? value) - { - assert.IsEmpty(value, Strings.IsEmptyStringFailMsg); - } + [Obsolete("Use StringAssert.That.IsEmpty", error: true)] + public static void IsEmpty(this Assert assert, string? value) => StringAssert.That.IsEmpty(value); /// /// Asserts that a string is empty. @@ -31,10 +29,8 @@ public static void IsEmpty(this Assert assert, string? value) /// /// A message to display. This message can be seen in the unit test results. /// - public static void IsEmpty(this Assert assert, string? value, string message) - { - assert.IsEmpty(value, message, value?.Length!); - } + [Obsolete("Use StringAssert.That.IsEmpty", error: true)] + public static void IsEmpty(this Assert assert, string? value, string message) => StringAssert.That.IsEmpty(value, message); /// /// Asserts that a string is empty. @@ -47,28 +43,16 @@ public static void IsEmpty(this Assert assert, string? value, string message) /// /// An array of parameters to use when formatting . /// - public static void IsEmpty(this Assert assert, string? value, string message, params object[] parameters) - { - if (value == null) - { - Helpers.HandleFail("Assert.IsEmpty", Strings.IsEmptyStringFailOnNullMsg); - } - - if (value!.Length != 0) - { - Helpers.HandleFail("Assert.IsEmpty", message, parameters); - } - } + [Obsolete("Use StringAssert.That.IsEmpty", error: true)] + public static void IsEmpty(this Assert assert, string? value, string message, params object?[] parameters) => StringAssert.That.IsEmpty(value, message, parameters); /// /// Asserts that a string is not empty. /// /// The instance to extend. /// The value to be tested. - public static void IsNotEmpty(this Assert assert, string? value) - { - assert.IsNotEmpty(value, Strings.IsNotEmptyStringFailMsg); - } + [Obsolete("Use StringAssert.That.IsNotEmpty", error: true)] + public static void IsNotEmpty(this Assert assert, string? value) => StringAssert.That.IsNotEmpty(value); /// /// Asserts that a string is not empty. @@ -78,10 +62,8 @@ public static void IsNotEmpty(this Assert assert, string? value) /// /// A message to display. This message can be seen in the unit test results. /// - public static void IsNotEmpty(this Assert assert, string? value, string message) - { - assert.IsNotEmpty(value, message, Array.Empty()); - } + [Obsolete("Use StringAssert.That.IsNotEmpty", error: true)] + public static void IsNotEmpty(this Assert assert, string? value, string message) => StringAssert.That.IsNotEmpty(value, message); /// /// Asserts that a string is not empty. @@ -94,17 +76,7 @@ public static void IsNotEmpty(this Assert assert, string? value, string message) /// /// An array of parameters to use when formatting . /// - public static void IsNotEmpty(this Assert assert, string? value, string message, params object[] parameters) - { - if (value == null) - { - Helpers.HandleFail("Assert.IsNotEmpty", Strings.IsNotEmptyStringFailOnNullMsg); - } - - if (value?.Length == 0) - { - Helpers.HandleFail("Assert.IsNotEmpty", message, parameters); - } - } + [Obsolete("Use StringAssert.That.IsNotEmpty", error: true)] + public static void IsNotEmpty(this Assert assert, string? value, string message, params object?[] parameters) => StringAssert.That.IsNotEmpty(value, message, parameters); } } diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.Equality.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.Equality.cs index 5ef0dc96..170765aa 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.Equality.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.Equality.cs @@ -19,10 +19,8 @@ public static partial class AssertExtensions /// The instance to extend. /// The expected string. /// The actual string. - public static void AreEqualIgnoringCase(this Assert assert, string expected, string actual) - { - assert.AreEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure); - } + [Obsolete("Use StringAssert.That.AreEqualIgnoringCase", error: true)] + public static void AreEqualIgnoringCase(this Assert assert, string expected, string actual) => StringAssert.That.AreEqualIgnoringCase(expected, actual); /// /// Asserts that two strings are equal, without regard to case. @@ -33,10 +31,8 @@ public static void AreEqualIgnoringCase(this Assert assert, string expected, str /// /// A message to display. This message can be seen in the unit test results. /// - public static void AreEqualIgnoringCase(this Assert assert, string expected, string actual, string message) - { - assert.AreEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure, expected, actual); - } + [Obsolete("Use StringAssert.That.AreEqualIgnoringCase", error: true)] + public static void AreEqualIgnoringCase(this Assert assert, string expected, string actual, string message) => StringAssert.That.AreEqualIgnoringCase(expected, actual, message); /// /// Asserts that two strings are equal, without regard to case. @@ -50,13 +46,8 @@ public static void AreEqualIgnoringCase(this Assert assert, string expected, str /// /// An array of parameters to use when formatting . /// - public static void AreEqualIgnoringCase(this Assert assert, string expected, string actual, string message, params object[] parameters) - { - if (String.Compare(expected, actual, StringComparison.CurrentCultureIgnoreCase) != 0) - { - Helpers.HandleFail("Assert.AreEqualIgnoringCase", message, parameters); - } - } + [Obsolete("Use StringAssert.That.AreEqualIgnoringCase", error: true)] + public static void AreEqualIgnoringCase(this Assert assert, string expected, string actual, string message, params object[] parameters) => StringAssert.That.AreEqualIgnoringCase(expected, actual, message, parameters); /// /// Asserts that two strings are not equal, without regard to case. @@ -64,10 +55,8 @@ public static void AreEqualIgnoringCase(this Assert assert, string expected, str /// The instance to extend. /// The expected string. /// The actual string. - public static void AreNotEqualIgnoringCase(this Assert assert, string expected, string actual) - { - assert.AreNotEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure); - } + [Obsolete("Use StringAssert.That.AreNotEqualIgnoringCase", error: true)] + public static void AreNotEqualIgnoringCase(this Assert assert, string expected, string actual) => StringAssert.That.AreNotEqualIgnoringCase(expected, actual); /// /// Asserts that two strings are not equal, without regard to case. @@ -78,10 +67,8 @@ public static void AreNotEqualIgnoringCase(this Assert assert, string expected, /// /// A message to display. This message can be seen in the unit test results. /// - public static void AreNotEqualIgnoringCase(this Assert assert, string expected, string actual, string message) - { - assert.AreNotEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure, expected, actual); - } + [Obsolete("Use StringAssert.That.AreNotEqualIgnoringCase", error: true)] + public static void AreNotEqualIgnoringCase(this Assert assert, string expected, string actual, string message) => StringAssert.That.AreNotEqualIgnoringCase(expected, actual, message); /// /// Asserts that two strings are not equal, without regard to case. @@ -95,13 +82,7 @@ public static void AreNotEqualIgnoringCase(this Assert assert, string expected, /// /// An array of parameters to use when formatting . /// - public static void AreNotEqualIgnoringCase(this Assert assert, string expected, string actual, string message, params object[] parameters) - { - if (String.Compare(expected, actual, StringComparison.CurrentCultureIgnoreCase) == 0) - { - Helpers.HandleFail("Assert.AreEqualIgnoringCase", message, parameters); - } - } - + [Obsolete("Use StringAssert.That.AreNotEqualIgnoringCase", error: true)] + public static void AreNotEqualIgnoringCase(this Assert assert, string expected, string actual, string message, params object[] parameters) => StringAssert.That.AreNotEqualIgnoringCase(expected, actual, message, parameters); } } diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.Exceptions.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.Exceptions.cs index 559d194b..498ae0ea 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.Exceptions.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.Exceptions.cs @@ -60,8 +60,7 @@ public static void DoesNotThrowException(this Assert assert, Action action, stri /// /// An array of parameters to use when formatting . /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] - public static void DoesNotThrowException(this Assert assert, Action action, string message, params object[] parameters) + public static void DoesNotThrowException(this Assert assert, Action action, string message, params object?[] parameters) { if (action == null) { @@ -79,9 +78,7 @@ public static void DoesNotThrowException(this Assert assert, Action action, stri } catch (Exception ex) { - Helpers.HandleFail("Assert.DoesNotThrowException", message, parameters, ex.GetType().Name, - ex.Message, - ex.StackTrace); + Helpers.HandleFail("Assert.DoesNotThrowException", message, parameters, ex.GetType().Name, ex.Message, ex.StackTrace); } } } diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreater.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreater.cs index 79ff6576..8174aea7 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreater.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreater.cs @@ -52,7 +52,7 @@ public static void IsGreater(this Assert assert, byte expected, byte actual, str /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, byte expected, byte actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, byte expected, byte actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -99,7 +99,7 @@ public static void IsGreater(this Assert assert, sbyte expected, sbyte actual, s /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, sbyte expected, sbyte actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, sbyte expected, sbyte actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -147,7 +147,7 @@ public static void IsGreater(this Assert assert, char expected, char actual, str /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, char expected, char actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, char expected, char actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -194,7 +194,7 @@ public static void IsGreater(this Assert assert, decimal expected, decimal actua /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, decimal expected, decimal actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, decimal expected, decimal actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -241,7 +241,7 @@ public static void IsGreater(this Assert assert, double expected, double actual, /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, double expected, double actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, double expected, double actual, string message, params object?[] parameters) { if (Double.IsNaN(expected) || Double.IsNaN(actual) || expected <= actual) { @@ -288,7 +288,7 @@ public static void IsGreater(this Assert assert, float expected, float actual, s /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, float expected, float actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, float expected, float actual, string message, params object?[] parameters) { if (Single.IsNaN(expected) || Single.IsNaN(actual) || expected <= actual) { @@ -335,7 +335,7 @@ public static void IsGreater(this Assert assert, int expected, int actual, strin /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, int expected, int actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, int expected, int actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -382,7 +382,7 @@ public static void IsGreater(this Assert assert, uint expected, uint actual, str /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, uint expected, uint actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, uint expected, uint actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -429,7 +429,7 @@ public static void IsGreater(this Assert assert, long expected, long actual, str /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, long expected, long actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, long expected, long actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -477,7 +477,7 @@ public static void IsGreater(this Assert assert, ulong expected, ulong actual, s /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, ulong expected, ulong actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, ulong expected, ulong actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -524,7 +524,7 @@ public static void IsGreater(this Assert assert, short expected, short actual, s /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, short expected, short actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, short expected, short actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -571,7 +571,7 @@ public static void IsGreater(this Assert assert, ushort expected, ushort actual, /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, ushort expected, ushort actual, string message, params object[] parameters) + public static void IsGreater(this Assert assert, ushort expected, ushort actual, string message, params object?[] parameters) { if (expected <= actual) { @@ -622,7 +622,7 @@ public static void IsGreater(this Assert assert, ushort expected, ushort actual, /// /// An array of parameters to use when formatting . /// - public static void IsGreater(this Assert assert, T expected, T actual, string message, params object[] parameters) where T : IComparable + public static void IsGreater(this Assert assert, T expected, T actual, string message, params object?[] parameters) where T : IComparable { if (expected.CompareTo(actual) <= 0) { diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreaterOrEqual.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreaterOrEqual.cs index 2dff8bda..ecf9d85f 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreaterOrEqual.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.IsGreaterOrEqual.cs @@ -52,7 +52,7 @@ public static void IsGreaterOrEqual(this Assert assert, byte expected, byte actu /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, byte expected, byte actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, byte expected, byte actual, string message, params object?[] parameters) { if (expected < actual) { @@ -99,7 +99,7 @@ public static void IsGreaterOrEqual(this Assert assert, sbyte expected, sbyte ac /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, sbyte expected, sbyte actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, sbyte expected, sbyte actual, string message, params object?[] parameters) { if (expected < actual) { @@ -147,7 +147,7 @@ public static void IsGreaterOrEqual(this Assert assert, char expected, char actu /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, char expected, char actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, char expected, char actual, string message, params object?[] parameters) { if (expected < actual) { @@ -194,7 +194,7 @@ public static void IsGreaterOrEqual(this Assert assert, decimal expected, decima /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, decimal expected, decimal actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, decimal expected, decimal actual, string message, params object?[] parameters) { if (expected < actual) { @@ -241,7 +241,7 @@ public static void IsGreaterOrEqual(this Assert assert, double expected, double /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, double expected, double actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, double expected, double actual, string message, params object?[] parameters) { if (Double.IsNaN(expected) || Double.IsNaN(actual) || expected < actual) { @@ -288,7 +288,7 @@ public static void IsGreaterOrEqual(this Assert assert, float expected, float ac /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, float expected, float actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, float expected, float actual, string message, params object?[] parameters) { if (Single.IsNaN(expected) || Single.IsNaN(actual) || expected < actual) { @@ -335,7 +335,7 @@ public static void IsGreaterOrEqual(this Assert assert, int expected, int actual /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, int expected, int actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, int expected, int actual, string message, params object?[] parameters) { if (expected < actual) { @@ -382,7 +382,7 @@ public static void IsGreaterOrEqual(this Assert assert, uint expected, uint actu /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, uint expected, uint actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, uint expected, uint actual, string message, params object?[] parameters) { if (expected < actual) { @@ -429,7 +429,7 @@ public static void IsGreaterOrEqual(this Assert assert, long expected, long actu /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, long expected, long actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, long expected, long actual, string message, params object?[] parameters) { if (expected < actual) { @@ -477,7 +477,7 @@ public static void IsGreaterOrEqual(this Assert assert, ulong expected, ulong ac /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, ulong expected, ulong actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, ulong expected, ulong actual, string message, params object?[] parameters) { if (expected < actual) { @@ -524,7 +524,7 @@ public static void IsGreaterOrEqual(this Assert assert, short expected, short ac /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, short expected, short actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, short expected, short actual, string message, params object?[] parameters) { if (expected < actual) { @@ -571,7 +571,7 @@ public static void IsGreaterOrEqual(this Assert assert, ushort expected, ushort /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, ushort expected, ushort actual, string message, params object[] parameters) + public static void IsGreaterOrEqual(this Assert assert, ushort expected, ushort actual, string message, params object?[] parameters) { if (expected < actual) { @@ -621,7 +621,7 @@ public static void IsGreaterOrEqual(this Assert assert, ushort expected, ushort /// /// An array of parameters to use when formatting . /// - public static void IsGreaterOrEqual(this Assert assert, T expected, T actual, string message, params object[] parameters) where T : IComparable + public static void IsGreaterOrEqual(this Assert assert, T expected, T actual, string message, params object?[] parameters) where T : IComparable { if (expected.CompareTo(actual) < 0) { diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.IsLess.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.IsLess.cs index ae038538..0c3542a2 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.IsLess.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.IsLess.cs @@ -52,7 +52,7 @@ public static void IsLess(this Assert assert, byte expected, byte actual, string /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, byte expected, byte actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, byte expected, byte actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -99,7 +99,7 @@ public static void IsLess(this Assert assert, sbyte expected, sbyte actual, stri /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, sbyte expected, sbyte actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, sbyte expected, sbyte actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -147,7 +147,7 @@ public static void IsLess(this Assert assert, char expected, char actual, string /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, char expected, char actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, char expected, char actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -194,7 +194,7 @@ public static void IsLess(this Assert assert, decimal expected, decimal actual, /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, decimal expected, decimal actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, decimal expected, decimal actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -241,7 +241,7 @@ public static void IsLess(this Assert assert, double expected, double actual, st /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, double expected, double actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, double expected, double actual, string message, params object?[] parameters) { if (Double.IsNaN(expected) || Double.IsNaN(actual) || expected >= actual) { @@ -288,7 +288,7 @@ public static void IsLess(this Assert assert, float expected, float actual, stri /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, float expected, float actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, float expected, float actual, string message, params object?[] parameters) { if (Single.IsNaN(expected) || Single.IsNaN(actual) || expected >= actual) { @@ -335,7 +335,7 @@ public static void IsLess(this Assert assert, int expected, int actual, string m /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, int expected, int actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, int expected, int actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -382,7 +382,7 @@ public static void IsLess(this Assert assert, uint expected, uint actual, string /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, uint expected, uint actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, uint expected, uint actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -429,7 +429,7 @@ public static void IsLess(this Assert assert, long expected, long actual, string /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, long expected, long actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, long expected, long actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -477,7 +477,7 @@ public static void IsLess(this Assert assert, ulong expected, ulong actual, stri /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, ulong expected, ulong actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, ulong expected, ulong actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -524,7 +524,7 @@ public static void IsLess(this Assert assert, short expected, short actual, stri /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, short expected, short actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, short expected, short actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -571,7 +571,7 @@ public static void IsLess(this Assert assert, ushort expected, ushort actual, st /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, ushort expected, ushort actual, string message, params object[] parameters) + public static void IsLess(this Assert assert, ushort expected, ushort actual, string message, params object?[] parameters) { if (expected >= actual) { @@ -621,7 +621,7 @@ public static void IsLess(this Assert assert, ushort expected, ushort actual, st /// /// An array of parameters to use when formatting . /// - public static void IsLess(this Assert assert, T expected, T actual, string message, params object[] parameters) where T : IComparable + public static void IsLess(this Assert assert, T expected, T actual, string message, params object?[] parameters) where T : IComparable { if (expected.CompareTo(actual) >= 0) { diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.IsLessOrEqual.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.IsLessOrEqual.cs index 729fb1a6..6cebd26e 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.IsLessOrEqual.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.IsLessOrEqual.cs @@ -52,7 +52,7 @@ public static void IsLessOrEqual(this Assert assert, byte expected, byte actual, /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, byte expected, byte actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, byte expected, byte actual, string message, params object?[] parameters) { if (expected > actual) { @@ -99,7 +99,7 @@ public static void IsLessOrEqual(this Assert assert, sbyte expected, sbyte actua /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, sbyte expected, sbyte actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, sbyte expected, sbyte actual, string message, params object?[] parameters) { if (expected > actual) { @@ -147,7 +147,7 @@ public static void IsLessOrEqual(this Assert assert, char expected, char actual, /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, char expected, char actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, char expected, char actual, string message, params object?[] parameters) { if (expected > actual) { @@ -194,7 +194,7 @@ public static void IsLessOrEqual(this Assert assert, decimal expected, decimal a /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, decimal expected, decimal actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, decimal expected, decimal actual, string message, params object?[] parameters) { if (expected > actual) { @@ -241,7 +241,7 @@ public static void IsLessOrEqual(this Assert assert, double expected, double act /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, double expected, double actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, double expected, double actual, string message, params object?[] parameters) { if (Double.IsNaN(expected) || Double.IsNaN(actual) || expected > actual) { @@ -288,7 +288,7 @@ public static void IsLessOrEqual(this Assert assert, float expected, float actua /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, float expected, float actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, float expected, float actual, string message, params object?[] parameters) { if (Single.IsNaN(expected) || Single.IsNaN(actual) || expected > actual) { @@ -335,7 +335,7 @@ public static void IsLessOrEqual(this Assert assert, int expected, int actual, s /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, int expected, int actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, int expected, int actual, string message, params object?[] parameters) { if (expected > actual) { @@ -382,7 +382,7 @@ public static void IsLessOrEqual(this Assert assert, uint expected, uint actual, /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, uint expected, uint actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, uint expected, uint actual, string message, params object?[] parameters) { if (expected > actual) { @@ -429,7 +429,7 @@ public static void IsLessOrEqual(this Assert assert, long expected, long actual, /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, long expected, long actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, long expected, long actual, string message, params object?[] parameters) { if (expected > actual) { @@ -477,7 +477,7 @@ public static void IsLessOrEqual(this Assert assert, ulong expected, ulong actua /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, ulong expected, ulong actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, ulong expected, ulong actual, string message, params object?[] parameters) { if (expected > actual) { @@ -524,7 +524,7 @@ public static void IsLessOrEqual(this Assert assert, short expected, short actua /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, short expected, short actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, short expected, short actual, string message, params object?[] parameters) { if (expected > actual) { @@ -571,7 +571,7 @@ public static void IsLessOrEqual(this Assert assert, ushort expected, ushort act /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, ushort expected, ushort actual, string message, params object[] parameters) + public static void IsLessOrEqual(this Assert assert, ushort expected, ushort actual, string message, params object?[] parameters) { if (expected > actual) { @@ -621,7 +621,7 @@ public static void IsLessOrEqual(this Assert assert, ushort expected, ushort act /// /// An array of parameters to use when formatting . /// - public static void IsLessOrEqual(this Assert assert, T expected, T actual, string message, params object[] parameters) where T : IComparable + public static void IsLessOrEqual(this Assert assert, T expected, T actual, string message, params object?[] parameters) where T : IComparable { if (expected.CompareTo(actual) > 0) { diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.IsNaN.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.IsNaN.cs index 4770edf5..9d3442e3 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.IsNaN.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.IsNaN.cs @@ -46,7 +46,7 @@ public static void IsNaN(this Assert assert, double value, string message) /// /// An array of parameters to use when formatting . /// - public static void IsNaN(this Assert assert, double value, string message, params object[] parameters) + public static void IsNaN(this Assert assert, double value, string message, params object?[] parameters) { if (!Double.IsNaN(value)) { @@ -88,7 +88,7 @@ public static void IsNaN(this Assert assert, float value, string message) /// /// An array of parameters to use when formatting . /// - public static void IsNaN(this Assert assert, float value, string message, params object[] parameters) + public static void IsNaN(this Assert assert, float value, string message, params object?[] parameters) { if (!Single.IsNaN(value)) { diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.Truthiness.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.Truthiness.cs index 045c8098..02493bb1 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.Truthiness.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.Truthiness.cs @@ -62,7 +62,7 @@ public static void IsFalse(this Assert assert, bool? condition, string message) /// /// evaluates to . /// - public static void IsFalse(this Assert assert, bool? condition, string message, params object[] parameters) + public static void IsFalse(this Assert assert, bool? condition, string message, params object?[] parameters) { if (!condition.HasValue || condition.Value) { @@ -121,7 +121,7 @@ public static void IsTrue(this Assert assert, bool? condition, string message) /// /// evaluates to . /// - public static void IsTrue(this Assert assert, bool? condition, string message, params object[] parameters) + public static void IsTrue(this Assert assert, bool? condition, string message, params object?[] parameters) { if (!condition.HasValue || !condition.Value) { diff --git a/src/Cadru.UnitTest.Framework/AssertExtensions.Types.cs b/src/Cadru.UnitTest.Framework/AssertExtensions.Types.cs index 1c64a495..c3962abf 100644 --- a/src/Cadru.UnitTest.Framework/AssertExtensions.Types.cs +++ b/src/Cadru.UnitTest.Framework/AssertExtensions.Types.cs @@ -50,12 +50,12 @@ public static void IsType(this Assert assert, object value, string message) /// /// An array of parameters to use when formatting . /// - public static void IsType(this Assert assert, object value, string message, params object[] parameters) + public static void IsType(this Assert assert, object value, string message, params object?[] parameters) { assert.IsType(value, typeof(T), message, parameters); } - internal static void IsType(this Assert assert, object value, Type expectedType, string message, params object[] parameters) + internal static void IsType(this Assert assert, object value, Type expectedType, string message, params object?[] parameters) { if (value?.GetType() != expectedType) { @@ -97,12 +97,12 @@ public static void IsAssignableFrom(this Assert assert, object value, string /// /// An array of parameters to use when formatting . /// - public static void IsAssignableFrom(this Assert assert, object value, string message, params object[] parameters) + public static void IsAssignableFrom(this Assert assert, object value, string message, params object?[] parameters) { assert.IsAssignableFrom(value, typeof(T), message, parameters); } - internal static void IsAssignableFrom(this Assert assert, object value, Type expectedType, string message, params object[] parameters) + internal static void IsAssignableFrom(this Assert assert, object value, Type expectedType, string message, params object?[] parameters) { if (value == null || !value.GetType().IsAssignableFrom(expectedType)) { @@ -145,12 +145,12 @@ public static void IsNotAssignableFrom(this Assert assert, object value, stri /// /// An array of parameters to use when formatting . /// - public static void IsNotAssignableFrom(this Assert assert, object value, string message, params object[] parameters) + public static void IsNotAssignableFrom(this Assert assert, object value, string message, params object?[] parameters) { assert.IsNotAssignableFrom(value, typeof(T), message, parameters); } - internal static void IsNotAssignableFrom(this Assert assert, object value, Type expectedType, string message, params object[] parameters) + internal static void IsNotAssignableFrom(this Assert assert, object value, Type expectedType, string message, params object?[] parameters) { if (value == null || value.GetType().IsAssignableFrom(expectedType)) { diff --git a/src/Cadru.UnitTest.Framework/Cadru.UnitTest.Framework.xml b/src/Cadru.UnitTest.Framework/Cadru.UnitTest.Framework.xml index c1e9c640..4f8e123c 100644 --- a/src/Cadru.UnitTest.Framework/Cadru.UnitTest.Framework.xml +++ b/src/Cadru.UnitTest.Framework/Cadru.UnitTest.Framework.xml @@ -2362,953 +2362,1114 @@ An array of parameters to use when formatting . - + - Contains assertion types that are not provided with the standard MSTest assertions. + Assert that an array, list or other collection is ordered + The instance to extend. + An array, list or other collection implementing IEnumerable + The message to be displayed on failure + Arguments to be used in formatting the message - + - Verifies that the first value is greater than the second value. + Assert that an array, list or other collection is ordered - The type of the values to compare. - The first value, expected to be greater. - The second value, expected to be less. + The instance to extend. + An array, list or other collection implementing IEnumerable - + - Verifies that the first value is greater than the second value. + Assert that an array, list or other collection is ordered - The type of the values to compare. - The first value, expected to be greater. - The second value, expected to be less. - - A message to display. This message can be seen in the unit test results. - + The instance to extend. + An array, list or other collection implementing IEnumerable + A custom comparer to perform the comparisons + The message to be displayed on failure + Arguments to be used in formatting the message - + - Verifies that the first value is greater than the second value. + Assert that an array, list or other collection is ordered - The type of the values to compare. - The first value, expected to be greater. - The second value, expected to be less. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - + The instance to extend. + An array, list or other collection implementing IEnumerable + A custom comparer to perform the comparisons - + - Verifies that the first value is greater than or equal to the second value. + Contains extensions for working with Exceptions in MSTest. - The type of the values to compare. - The first value, expected to be greater. - The second value, expected to be less. - + - Verifies that the first value is greater than or equal to the second value. + Verifies that + is of the specified type. - The type of the values to compare. - The first value, expected to be greater. - The second value, expected to be less. - - A message to display. This message can be seen in the unit test results. + The source exception type. + + The exception whose will be tested. + The expected type of the inner exception. + The original . - + - Verifies that the first value is greater than or equal to the second value. + Verifies that + is of the specified type. - The type of the values to compare. - The first value, expected to be greater. - The second value, expected to be less. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . + The inner exception type. + + The exception whose will be tested. + The original . - + - Verifies that the specified condition is . - The assertion fails if the condition is . + Verifies that the exception contains + the given text. - The condition to verify is . - - evaluates to . - + The exception type. + + The exception whose will be searched. + + The text to search for in the exception . + + One of the values. + + The original . - + - Verifies that the specified condition is . - The assertion fails if the condition is . - Displays a message if the assertion fails. + Verifies that the exception is equal + to the given text. - The condition to verify is . - - A message to display if the assertion fails. This message can be - seen in the unit test results. + The exception type. + + The exception whose will be compared. - - evaluates to . - + The text to compare. + The original . - + - Verifies that the specified condition is . - The assertion fails if the condition is . - Displays a message if the assertion fails, and applies the specified - formatting to it. + Verifies that the exception + property is equal to the + given text. - The condition to verify is . - - A message to display if the assertion fails. This message can be - seen in the unit test results. - - - An array of parameters to use when formatting . + The exception type. + + The exception whose + property will be compared. - - evaluates to . - + The text to compare. + The original . - + - Verifies that the value is . + Options used by the + + method to determine how to compare the exception message. - The value to test. - + - Verifies that the value is . + The exception message should exactly match. - The value to test. - - A message to display. This message can be seen in the unit test results. - - + - Verifies that the value is . + The exception message should contain the given string. - The value to test. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Verifies that the specified condition is . The - assertion fails if the condition is . + The exception message should start with the given string. - The condition to verify is . - - evaluates to . - - + - Verifies that the specified condition is . The - assertion fails if the condition is . - Displays a message if the assertion fails. + The exception message should end with the given string. - The condition to verify is . + + + + Checks the parameter for valid conditions + + + The parameter. + + + The assertion Name. + + + parameter name + - A message to display if the assertion fails. This message can be - seen in the unit test results. + message for the invalid parameter exception + + + The parameters. - - evaluates to . - - + - Verifies that the specified condition is . The - assertion fails if the condition is . - Displays a message if the assertion fails, and applies the specified - formatting to it. + Helper function that creates and throws an AssertionFailedException - The condition to verify is . + + name of the assertion throwing an exception + - A message to display if the assertion fails. This message can be - seen in the unit test results. + message describing conditions for assertion failure - An array of parameters to use when formatting . + The parameters. - - evaluates to . - - + - Verifies that the first value is less than the second value. + Safely converts an object to a string, handling null values and null characters. + Null values are converted to "(null)". Null characters are converted to "\\0". - The type of the values to compare. - The first value, expected to be less. - The second value, expected to be greater. + + The object to convert to a string. + + + The converted string. + - + - Verifies that the first value is less than the second value. + Replaces null characters ('\0') with "\\0". - The type of the values to compare. - The first value, expected to be less. - The second value, expected to be greater. - - A message to display. This message can be seen in the unit test results. + + The string to search. + + The converted string with null characters replaced by "\\0". + + + This is only public and still present to preserve compatibility with the V1 framework. + - + - Verifies that the first value is less than the second value. + A strongly-typed resource class, for looking up localized strings, etc. - The type of the values to compare. - The first value, expected to be less. - The second value, expected to be greater. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Verifies that the first value is less than or equal to the second value. + Returns the cached ResourceManager instance used by this class. - The type of the values to compare. - The first value, expected to be less. - The second value, expected to be greater. - + - Verifies that the first value is less than or equal to the second value. + Overrides the current thread's CurrentUICulture property for all + resource lookups using this strongly typed resource class. - The type of the values to compare. - The first value, expected to be less. - The second value, expected to be greater. - - A message to display. This message can be seen in the unit test results. - - + - Verifies that the first value is less than or equal to the second value. + Looks up a localized string similar to Expected exception of type {0} but no exception was thrown.. - The type of the values to compare. - The first value, expected to be less. - The second value, expected to be greater. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Contains assertion types that are not provided with the standard MSTest assertions. + Looks up a localized string similar to Expected {0} to be assignable from {1}.. - + - Asserts that two strings are equal, without regard to case. + Looks up a localized string similar to Expected &lt;{0}&gt; but actual was &lt;{1}&gt;.. - The expected string. - The actual string. - + - Asserts that two strings are equal, without regard to case. + Looks up a localized string similar to Expected type {0} but actual was {1}.. - The expected string. - The actual string. - - A message to display. This message can be seen in the unit test results. - - + - Asserts that two strings are equal, without regard to case. + Looks up a localized string similar to {0} failed. {1}. - The expected string. - The actual string. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Assert that an array, list or other collection is empty. + Looks up a localized string similar to (null). - The value to be tested. - + - Assert that an array, list or other collection is empty. + Looks up a localized string similar to String '{0}' contains string '{1}'. {2}.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - + - Assert that an array, list or other collection is empty. + Looks up a localized string similar to String '{0}' ends with string '{1}'. {2}.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Asserts that a string is empty. + Looks up a localized string similar to String '{0}' starts with string '{1}'. {2}.. - The value to be tested. - + + + Looks up a localized string similar to An exception of type {1} was thrown but was not expected. {0} + Exception Message: {2} + Stack Trace: {3}. + + + - Asserts that a string is empty. + Looks up a localized string similar to Expected an empty collection.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - + - Asserts that a string is empty. + Looks up a localized string similar to Expected a collection with 1 or more elements.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Assert that an array, list or other collection is not empty. + Looks up a localized string similar to Expected an empty string but actual string had {0} characters.. - The value to be tested. - + - Assert that an array, list or other collection is not empty. + Looks up a localized string similar to Expected an empty string but actual string was (null).. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - + - Assert that an array, list or other collection is not empty. + Looks up a localized string similar to Expected {0} to be greater than {1}.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Asserts that a string is not empty. + Looks up a localized string similar to Expected {0} to be greater than or equal to {1}.. - The value to be tested. - + - Asserts that a string is not empty. + Looks up a localized string similar to Expected {0} to be less than {1}.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - + - Asserts that a string is not empty. + Looks up a localized string similar to Expected {0} to be less than or equal to {1}.. - The value to be tested. - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Contains assertion types that are not provided with the standard MSTest assertions. + Looks up a localized string similar to Expected a string with 1 or more characters but actual was empty.. - + - Verifies that throws an exception when - called and returns it. + Looks up a localized string similar to Expected a string with 1 or more characters but actual was (null).. - The code to test. - The message that will be displayed on failure. - - An array of parameters to use when formatting . - - The thrown by . - + - Verifies that throws an exception when - called and returns it. + Looks up a localized string similar to Expected an ordered collection.. - The code to test. - The message that will be displayed on failure. - The thrown by . - + - Verifies that throws an exception when - called and returns it. + Looks up a localized string similar to The parameter '{0}' is invalid. The value cannot be null. {1}.. - The code to test. - The thrown by . - + + + Looks up a localized string similar to Threw exception {0}, but exception {1} was expected. + Exception Message: {3} + Stack Trace: {4}. + + + - Verifies that throws an exception of a - certain Type or one derived from it when called and returns it. + A collection of helpers to test various conditions within unit tests. + If the condition being tested is not met, an exception is thrown. + + + A collection of helpers to test various conditions within unit tests. + If the condition being tested is not met, an exception is thrown. + + + A collection of helpers to test various conditions within unit tests. + If the condition being tested is not met, an exception is thrown. + + + A collection of helpers to test various conditions within unit tests. + If the condition being tested is not met, an exception is thrown. - The expected exception type. - The code to test. - The message that will be displayed on failure. - - An array of parameters to use when formatting . - - The thrown by . - + - Verifies that throws an exception of a - certain Type or one derived from it when called and returns it. + Asserts that a string is empty. - The expected exception type. - The code to test. - The message that will be displayed on failure. - The thrown by . + The instance to extend. + The value to be tested. - + - Verifies that throws an exception of a - certain Type or one derived from it when called and returns it. + Asserts that a string is empty. - The expected exception type. - The code to test. - The thrown by . + The instance to extend. + The value to be tested. + + A message to display. This message can be seen in the unit test results. + - + - Verifies that throws an exception of a - certain Type or one derived from it when called and returns it. + Asserts that a string is empty. - The expected exception type. - The code to test. - The message that will be displayed on failure. + The instance to extend. + The value to be tested. + + A message to display. This message can be seen in the unit test results. + An array of parameters to use when formatting . - The thrown by . - + - Verifies that throws an exception of a - certain Type or one derived from it when called and returns it. + Asserts that a string is not empty. - The expected exception type. - The code to test. - The message that will be displayed on failure. - The thrown by . + The instance to extend. + The value to be tested. - + - Verifies that throws an exception of a - certain Type or one derived from it when called and returns it. + Asserts that a string is not empty. - The expected exception type. - The code to test. - The thrown by . + The instance to extend. + The value to be tested. + + A message to display. This message can be seen in the unit test results. + - + - Verifies that does not throw an exception. + Asserts that a string is not empty. - The code to test. - The message that will be displayed on failure. + The instance to extend. + The value to be tested. + + A message to display. This message can be seen in the unit test results. + An array of parameters to use when formatting . - + - Verifies that does not throw an exception. + Asserts that two strings are equal, without regard to case. - The code to test. - The message that will be displayed on failure. + The instance to extend. + The expected string. + The actual string. - + - Verifies that does not throw an exception. + Asserts that two strings are equal, without regard to case. - The code to test. + The instance to extend. + The expected string. + The actual string. + + A message to display. This message can be seen in the unit test results. + - + - Verifies that throws an exception when called. + Asserts that two strings are equal, without regard to case. - The code to test. - The message that will be displayed on failure. + The instance to extend. + The expected string. + The actual string. + + A message to display. This message can be seen in the unit test results. + An array of parameters to use when formatting . - The thrown by . - + - Verifies that throws an exception when called. + Asserts that two strings are not equal, without regard to case. - The code to test. - The message that will be displayed on failure. - The thrown by . + The instance to extend. + The expected string. + The actual string. - + - Verifies that throws an exception when called. + Asserts that two strings are not equal, without regard to case. - The code to test. - The thrown by . + The instance to extend. + The expected string. + The actual string. + + A message to display. This message can be seen in the unit test results. + - + - Verifies that throws a particular exception - when called. + Asserts that two strings are not equal, without regard to case. - The exception Type expected. - The code to test. - The message that will be displayed on failure. + The instance to extend. + The expected string. + The actual string. + + A message to display. This message can be seen in the unit test results. + An array of parameters to use when formatting . - The thrown by . - + - Verifies that throws a particular exception - when called. + Tests whether the specified string does not contain the specified substring + and throws an exception if the substring does occur within the + test string. - The exception Type expected. - The code to test. - The message that will be displayed on failure. - The thrown by . + The instance to extend. + + The string that is expected to contain . + + + The string expected to occur within . + + + Thrown if is not found in + . + - + - Verifies that throws a particular exception - when called. + Tests whether the specified string does not contain the specified substring + and throws an exception if the substring does occur within the + test string. - The exception Type expected. - The code to test. - The thrown by . + The instance to extend. + + The string that is expected to contain . + + + The string expected to occur within . + + + The comparison method to compare strings . + + + Thrown if is not found in + . + - + - Verifies that throws a particular exception - when called. + Tests whether the specified string does not contain the specified substring + and throws an exception if the substring does occur within the + test string. - Type of the expected exception. - The code to test. - The message that will be displayed on failure. - - An array of parameters to use when formatting . + The instance to extend. + + The string that is expected to contain . + + + The string expected to occur within . + + + The message to include in the exception when + is not in . The message is shown in + test results. - The thrown by . + + Thrown if is not found in + . + - + - Verifies that throws a particular exception - when called. + Tests whether the specified string does not contain the specified substring + and throws an exception if the substring does occur within the + test string. - Type of the expected exception. - The code to test. - The message that will be displayed on failure. - The thrown by . + The instance to extend. + + The string that is expected to contain . + + + The string expected to occur within . + + + The message to include in the exception when + is not in . The message is shown in + test results. + + + The comparison method to compare strings . + + + Thrown if is not found in + . + - + - Verifies that throws a particular exception - when called. + Tests whether the specified string does not contain the specified substring + and throws an exception if the substring does occur within the + test string. - Type of the expected exception. - The code to test. - The thrown by . + The instance to extend. + + The string that is expected to contain . + + + The string expected to occur within . + + + The message to include in the exception when + is not in . The message is shown in + test results. + + + An array of parameters to use when formatting . + + + Thrown if is not found in + . + - + - Verifies that - is of the specified type. + Tests whether the specified string does not contain the specified substring + and throws an exception if the substring does occur within the + test string. - The source exception type. - - The exception whose will be tested. + The instance to extend. + + The string that is expected to contain . + + + The string expected to occur within . - The expected type of the inner exception. - The original . + + The message to include in the exception when + is not in . The message is shown in + test results. + + + The comparison method to compare strings . + + + An array of parameters to use when formatting . + + + Thrown if is not found in + . + - + - Verifies that - is of the specified type. + Tests whether the specified string begins with the specified substring + and throws an exception if the test string does not start with the + substring. - The inner exception type. - - The exception whose will be tested. + The instance to extend. + + The string that is expected to begin with . - The original . + + The string expected to be a prefix of . + + + Thrown if does not begin with + . + - + - Verifies that the exception contains - the given text. + Tests whether the specified string begins with the specified substring + and throws an exception if the test string does not start with the + substring. - The exception type. - - The exception whose will be searched. + The instance to extend. + + The string that is expected to begin with . - The text to search for in the exception . - - One of the values. + + The string expected to be a prefix of . - The original . + + The comparison method to compare strings . + + + Thrown if does not begin with + . + - + - Verifies that the exception is equal - to the given text. + Tests whether the specified string begins with the specified substring + and throws an exception if the test string does not start with the + substring. - The exception type. - - The exception whose will be compared. + The instance to extend. + + The string that is expected to begin with . - The text to compare. - The original . + + The string expected to be a prefix of . + + + The message to include in the exception when + does not begin with . The message is + shown in test results. + + + Thrown if does not begin with + . + - + - Verifies that the exception - property is equal to the - given text. + Tests whether the specified string begins with the specified substring + and throws an exception if the test string does not start with the + substring. - The exception type. - - The exception whose - property will be compared. + The instance to extend. + + The string that is expected to begin with . - The text to compare. - The original . + + The string expected to be a prefix of . + + + The message to include in the exception when + does not begin with . The message is + shown in test results. + + + An array of parameters to use when formatting . + + + Thrown if does not begin with + . + - + - Options used by the - - method to determine how to compare the exception message. + Tests whether the specified string begins with the specified substring + and throws an exception if the test string does not start with the + substring. + The instance to extend. + + The string that is expected to begin with . + + + The string expected to be a prefix of . + + + The message to include in the exception when + does not begin with . The message is + shown in test results. + + + The comparison method to compare strings . + + + Thrown if does not begin with + . + - + - The exception message should exactly match. + Tests whether the specified string begins with the specified substring + and throws an exception if the test string does not start with the + substring. + The instance to extend. + + The string that is expected to begin with . + + + The string expected to be a prefix of . + + + The message to include in the exception when + does not begin with . The message is + shown in test results. + + + The comparison method to compare strings . + + + An array of parameters to use when formatting . + + + Thrown if does not begin with + . + - + - The exception message should contain the given string. + Tests whether the specified string ends with the specified substring + and throws an exception if the test string does not end with the + substring. + The instance to extend. + + The string that is expected to end with . + + + The string expected to be a suffix of . + + + Thrown if does not end with + . + - + - The exception message should start with the given string. + Tests whether the specified string ends with the specified substring + and throws an exception if the test string does not end with the + substring. + The instance to extend. + + The string that is expected to end with . + + + The string expected to be a suffix of . + + + The comparison method to compare strings . + + + Thrown if does not end with + . + - + - The exception message should end with the given string. + Tests whether the specified string ends with the specified substring + and throws an exception if the test string does not end with the + substring. + The instance to extend. + + The string that is expected to end with . + + + The string expected to be a suffix of . + + + The message to include in the exception when + does not end with . The message is + shown in test results. + + + Thrown if does not end with + . + - + - Helper function that creates and throws an AssertionFailedException + Tests whether the specified string ends with the specified substring + and throws an exception if the test string does not end with the + substring. - - name of the assertion throwing an exception + The instance to extend. + + The string that is expected to end with . + + + The string expected to be a suffix of . - message describing conditions for assertion failure + The message to include in the exception when + does not end with . The message is + shown in test results. - The parameters. + An array of parameters to use when formatting . + + Thrown if does not end with + . + - + - Safely converts an object to a string, handling null values and null characters. - Null values are converted to "(null)". Null characters are converted to "\\0". + Tests whether the specified string ends with the specified substring + and throws an exception if the test string does not end with the + substring. - - The object to convert to a string. + The instance to extend. + + The string that is expected to end with . - - The converted string. - + + The string expected to be a suffix of . + + + The message to include in the exception when + does not end with . The message is + shown in test results. + + + The comparison method to compare strings . + + + Thrown if does not end with + . + - + - Replaces null characters ('\0') with "\\0". + Tests whether the specified string ends with the specified substring + and throws an exception if the test string does not end with the + substring. - - The string to search. + The instance to extend. + + The string that is expected to end with . - - The converted string with null characters replaced by "\\0". - - - This is only public and still present to preserve compatibility with the V1 framework. - + + The string expected to be a suffix of . + + + The message to include in the exception when + does not end with . The message is + shown in test results. + + + The comparison method to compare strings . + + + An array of parameters to use when formatting . + + + Thrown if does not end with + . + - + - A strongly-typed resource class, for looking up localized strings, etc. + Specifies that is allowed as an input even if the + corresponding type disallows it. - + - Returns the cached ResourceManager instance used by this class. + Initializes a new instance of the class. - + - Overrides the current thread's CurrentUICulture property for all - resource lookups using this strongly typed resource class. + Specifies that is disallowed as an input even if the + corresponding type allows it. - + - Looks up a localized string similar to Expected exception of type {0} but no exception was thrown.. + Initializes a new instance of the class. - + - Looks up a localized string similar to Expected {0} to be assignable from {1}.. + Specifies that a method that will never return under any circumstance. - - - Looks up a localized string similar to Expected &lt;{0}&gt; but actual was &lt;{1}&gt;.. - + + + Initializes a new instance of the class. + + - + - Looks up a localized string similar to Expected type {0} but actual was {1}.. + Specifies that the method will not return if the associated + parameter is passed the specified value. - + - Looks up a localized string similar to {0} failed. {1}. + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. - + - Looks up a localized string similar to (null). + Initializes a new instance of the + class with the specified parameter value. + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + - - - Looks up a localized string similar to An exception of type {1} was thrown but was not expected. {0} - Exception Message: {2} - Stack Trace: {3}. - - - + - Looks up a localized string similar to Expected an empty collection.. + Specifies that an output may be even if the + corresponding type disallows it. - + - Looks up a localized string similar to Expected a collection with 1 or more elements.. + Initializes a new instance of the class. - + - Looks up a localized string similar to Expected an empty string but actual string had {0} characters.. + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. - + - Looks up a localized string similar to Expected an empty string but actual string was (null).. + Gets the return value condition. + If the method returns this value, the associated parameter may be . - + - Looks up a localized string similar to Expected {0} to be greater than {1}.. + Initializes the attribute with the specified return value condition. + + The return value condition. + If the method returns this value, the associated parameter may be . + - + - Looks up a localized string similar to Expected {0} to be greater than or equal to {1}.. + Specifies that the method or property will ensure that the listed field and property members have + not- values. - + - Looks up a localized string similar to Expected {0} to be less than {1}.. + Gets field or property member names. - + - Looks up a localized string similar to Expected {0} to be less than or equal to {1}.. + Initializes the attribute with a field or property member. + + The field or property member that is promised to be not-null. + - + - Looks up a localized string similar to Expected a string with 1 or more characters but actual was empty.. + Initializes the attribute with the list of field and property members. + + The list of field and property members that are promised to be not-null. + - + - Looks up a localized string similar to Expected a string with 1 or more characters but actual was (null).. + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. - - - Looks up a localized string similar to Threw exception {0}, but exception {1} was expected. - Exception Message: {3} - Stack Trace: {4}. - - - + - Contains assertion types that are not provided with the standard MSTest assertions. + Gets the return value condition. - + - Asserts that an object may be assigned a value of a given . + Gets field or property member names. - The value to be tested. - The expected . - + - Asserts that an object may be assigned a value of a given . + Initializes the attribute with the specified return value condition and a field or property member. - The value to be tested. - The expected . - - A message to display. This message can be seen in the unit test results. + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. - + - Asserts that an object may be assigned a value of a given . + Initializes the attribute with the specified return value condition and list + of field and property members. - The value to be tested. - The expected . - - A message to display. This message can be seen in the unit test results. + + The return value condition. If the method returns this value, + the associated parameter will not be . - - An array of parameters to use when formatting . + + The list of field and property members that are promised to be not-null. - + - Asserts that an object may not be assigned a value of a given . + Specifies that an output is not even if the + corresponding type allows it. - The value to be tested. - The expected . - + - Asserts that an object may not be assigned a value of a given . + Initializes a new instance of the class. - The value to be tested. - The expected . - - A message to display. This message can be seen in the unit test results. - - + - Asserts that an object may not be assigned a value of a given . + Specifies that the output will be non- if the + named parameter is non-. - The value to be tested. - The expected . - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . - - + - Asserts that an object is of the given . + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. - The expected . - The value to be tested. - + - Asserts that an object is of the given . + Initializes the attribute with the associated parameter name. - The value to be tested. - The expected . + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + - + - Asserts that an object is of the given . + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. - The value to be tested. - The expected . - - A message to display. This message can be seen in the unit test results. - - + - Asserts that an object is of the given . + Gets the return value condition. + If the method returns this value, the associated parameter will not be . - The value to be tested. - The expected . - - A message to display. This message can be seen in the unit test results. - - - An array of parameters to use when formatting . + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . diff --git a/src/Cadru.UnitTest.Framework/CollectionAssertExtensions.cs b/src/Cadru.UnitTest.Framework/CollectionAssertExtensions.cs index a2e887d1..3f1572e0 100644 --- a/src/Cadru.UnitTest.Framework/CollectionAssertExtensions.cs +++ b/src/Cadru.UnitTest.Framework/CollectionAssertExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Linq; using Cadru.UnitTest.Framework.Resources; @@ -14,6 +15,8 @@ namespace Cadru.UnitTest.Framework public static class CollectionAssertExtensions { + private static readonly object?[] Empty = Array.Empty(); + /// /// Assert that an array, list or other collection is empty. /// @@ -48,7 +51,7 @@ public static void IsEmpty(this CollectionAssert assert, IEnumerable collection, /// /// An array of parameters to use when formatting . /// - public static void IsEmpty(this CollectionAssert assert, IEnumerable collection, string message, params object[] parameters) + public static void IsEmpty(this CollectionAssert assert, IEnumerable collection, string message, params object?[] parameters) { if (collection != null && collection.GetEnumerator().MoveNext()) { @@ -90,12 +93,78 @@ public static void IsNotEmpty(this CollectionAssert assert, IEnumerable collecti /// /// An array of parameters to use when formatting . /// - public static void IsNotEmpty(this CollectionAssert assert, IEnumerable collection, string message, params object[] parameters) + public static void IsNotEmpty(this CollectionAssert assert, IEnumerable collection, string message, params object?[] parameters) { if (collection != null && !collection.GetEnumerator().MoveNext()) { Helpers.HandleFail("CollectionAssert.IsNotEmpty", message, parameters); } } + + #region IsOrdered + /// + /// Assert that an array, list or other collection is ordered + /// + /// The instance to extend. + /// An array, list or other collection implementing IEnumerable + /// The message to be displayed on failure + /// Arguments to be used in formatting the message + public static void IsOrdered(this CollectionAssert assert, IEnumerable collection, string message, params object?[] args) + { + assert.IsOrdered(collection, Comparer.Default, message, args); + } + + /// + /// Assert that an array, list or other collection is ordered + /// + /// The instance to extend. + /// An array, list or other collection implementing IEnumerable + public static void IsOrdered(this CollectionAssert assert, IEnumerable collection) + { + assert.IsOrdered(collection, Comparer.Default, String.Empty, Empty); + } + + /// + /// Assert that an array, list or other collection is ordered + /// + /// The instance to extend. + /// An array, list or other collection implementing IEnumerable + /// A custom comparer to perform the comparisons + /// The message to be displayed on failure + /// Arguments to be used in formatting the message + public static void IsOrdered(this CollectionAssert assert, IEnumerable collection, IComparer comparer, string message, params object?[] args) + { + Helpers.CheckParameterNotNull(collection, "CollectionAssert.IsOrdered", "collection", String.Empty); + Helpers.CheckParameterNotNull(comparer, "CollectionAssert.IsOrdered", "comparer", String.Empty); + + var enumerator = collection.GetEnumerator(); + using (enumerator as IDisposable) + { + do + { + var x = enumerator.Current; + if (enumerator.MoveNext()) + { + if (comparer.Compare(x, enumerator.Current) > 0) + { + Helpers.HandleFail("CollectionAssert.IsOrdered", Strings.IsOrderedFail); + break; + } + } + } while (enumerator.MoveNext()); + } + } + + /// + /// Assert that an array, list or other collection is ordered + /// + /// The instance to extend. + /// An array, list or other collection implementing IEnumerable + /// A custom comparer to perform the comparisons + public static void IsOrdered(this CollectionAssert assert, IEnumerable collection, IComparer comparer) + { + assert.IsOrdered(collection, comparer, String.Empty, Empty); + } + #endregion } } diff --git a/src/Cadru.UnitTest.Framework/ConditionAssert.cs b/src/Cadru.UnitTest.Framework/ConditionAssert.cs deleted file mode 100644 index f3fb3f45..00000000 --- a/src/Cadru.UnitTest.Framework/ConditionAssert.cs +++ /dev/null @@ -1,366 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Copyright (C) 2001-2020 Scott Dorman. -// -// -// -// Licensed under the Microsoft Public License (Ms-PL) (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://opensource.org/licenses/Ms-PL.html -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//------------------------------------------------------------------------------ - -using System; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Cadru.UnitTest.Framework -{ - /// - /// Contains assertion types that are not provided with the standard MSTest assertions. - /// - public static class ConditionAssert - { - /// - /// Verifies that the first value is greater than the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be greater. - /// The second value, expected to be less. - [Obsolete("Use Assert.That.IsGreater(T, T).")] - public static void Greater(T arg1, T arg2) where T : IComparable - { - Assert.That.IsGreater(arg1, arg2); - } - - /// - /// Verifies that the first value is greater than the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be greater. - /// The second value, expected to be less. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsGreater(T, T, string).")] - public static void Greater(T arg1, T arg2, string message) where T : IComparable - { - Assert.That.IsGreater(arg1, arg2, message); - } - - /// - /// Verifies that the first value is greater than the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be greater. - /// The second value, expected to be less. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsGreater(T, T, string, object[].")] - public static void Greater(T arg1, T arg2, string message, params object[] parameters) where T : IComparable - { - Assert.That.IsGreater(arg1, arg2, message, parameters); - - } - - /// - /// Verifies that the first value is greater than or equal to the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be greater. - /// The second value, expected to be less. - [Obsolete("Use Assert.That.GreaterOrEqual(T, T)")] - public static void IsGreaterOrEqual(T arg1, T arg2) where T : IComparable - { - Assert.That.IsGreaterOrEqual(arg1, arg2); - } - - /// - /// Verifies that the first value is greater than or equal to the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be greater. - /// The second value, expected to be less. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsGreaterOrEqual(T, T, string)")] - public static void GreaterOrEqual(T arg1, T arg2, string message) where T : IComparable - { - Assert.That.IsGreaterOrEqual(arg1, arg2, message); - } - - /// - /// Verifies that the first value is greater than or equal to the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be greater. - /// The second value, expected to be less. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsGreaterOrEqual(T, T, string, object[])")] - public static void GreaterOrEqual(T arg1, T arg2, string message, params object[] parameters) where T : IComparable - { - Assert.That.IsGreaterOrEqual(arg1, arg2, message, parameters); - } - - /// - /// Verifies that the specified condition is . - /// The assertion fails if the condition is . - /// - /// The condition to verify is . - /// - /// evaluates to . - /// - [Obsolete("Use Assert.That.IsFalse(bool?)")] - public static void IsFalse(bool? condition) - { - Assert.That.IsFalse(condition); - } - - /// - /// Verifies that the specified condition is . - /// The assertion fails if the condition is . - /// Displays a message if the assertion fails. - /// - /// The condition to verify is . - /// - /// A message to display if the assertion fails. This message can be - /// seen in the unit test results. - /// - /// - /// evaluates to . - /// - [Obsolete("Use Assert.That.IsFalse(bool?, string)")] - public static void IsFalse(bool? condition, string message) - { - Assert.That.IsFalse(condition, message); - } - - /// - /// Verifies that the specified condition is . - /// The assertion fails if the condition is . - /// Displays a message if the assertion fails, and applies the specified - /// formatting to it. - /// - /// The condition to verify is . - /// - /// A message to display if the assertion fails. This message can be - /// seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - /// - /// evaluates to . - /// - [Obsolete("Use Assert.That.IsFalse(bool?, string, object[])")] - public static void IsFalse(bool? condition, string message, params object[] parameters) - { - Assert.That.IsFalse(condition, message, parameters); - } - - /// - /// Verifies that the value is . - /// - /// The value to test. - [Obsolete("Use Assert.That.IsNan(double)")] - public static void IsNaN(double value) - { - Assert.That.IsNaN(value); - } - - /// - /// Verifies that the value is . - /// - /// The value to test. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsNan(double, string)")] - public static void IsNaN(double value, string message) - { - Assert.That.IsNaN(value, message); - } - - /// - /// Verifies that the value is . - /// - /// The value to test. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsNan(double, string, object[])")] - public static void IsNaN(double value, string message, params object[] parameters) - { - Assert.That.IsNaN(value, message, parameters); - } - - /// - /// Verifies that the specified condition is . The - /// assertion fails if the condition is . - /// - /// The condition to verify is . - /// - /// evaluates to . - /// - [Obsolete("Use Assert.That.IsTrue(bool?)")] - public static void IsTrue(bool? condition) - { - Assert.That.IsTrue(condition); - } - - /// - /// Verifies that the specified condition is . The - /// assertion fails if the condition is . - /// Displays a message if the assertion fails. - /// - /// The condition to verify is . - /// - /// A message to display if the assertion fails. This message can be - /// seen in the unit test results. - /// - /// - /// evaluates to . - /// - [Obsolete("Use Assert.That.IsTrue(bool?, string)")] - public static void IsTrue(bool? condition, string message) - { - Assert.That.IsTrue(condition, message); - } - - /// - /// Verifies that the specified condition is . The - /// assertion fails if the condition is . - /// Displays a message if the assertion fails, and applies the specified - /// formatting to it. - /// - /// The condition to verify is . - /// - /// A message to display if the assertion fails. This message can be - /// seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - /// - /// evaluates to . - /// - [Obsolete("Use Assert.That.IsTrue(bool?, string, object[])")] - public static void IsTrue(bool? condition, string message, params object[] parameters) - { - Assert.That.IsTrue(condition, message, parameters); - } - - /// - /// Verifies that the first value is less than the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be less. - /// The second value, expected to be greater. - [Obsolete("Use Assert.That.IsLess(T, T).")] - public static void Less(T arg1, T arg2) where T : IComparable - { - Assert.That.IsLess(arg1, arg2); - } - - /// - /// Verifies that the first value is less than the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be less. - /// The second value, expected to be greater. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsLess(T, T, string).")] - public static void Less(T arg1, T arg2, string message) where T : IComparable - { - Assert.That.IsLess(arg1, arg2, message); - } - - /// - /// Verifies that the first value is less than the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be less. - /// The second value, expected to be greater. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsLess(T, T, string, object[]).")] - public static void Less(T arg1, T arg2, string message, params object[] parameters) where T : IComparable - { - Assert.That.IsLess(arg1, arg2, message, parameters); - } - - /// - /// Verifies that the first value is less than or equal to the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be less. - /// The second value, expected to be greater. - [Obsolete("Use Assert.That.IsLessOrEqual(T, T).")] - public static void LessOrEqual(T arg1, T arg2) where T : IComparable - { - Assert.That.IsLessOrEqual(arg1, arg2); - } - - /// - /// Verifies that the first value is less than or equal to the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be less. - /// The second value, expected to be greater. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsLessOrEqual(T, T, string).")] - public static void LessOrEqual(T arg1, T arg2, string message) where T : IComparable - { - Assert.That.IsLessOrEqual(arg1, arg2, message); - } - - /// - /// Verifies that the first value is less than or equal to the second value. - /// - /// The type of the values to compare. - /// The first value, expected to be less. - /// The second value, expected to be greater. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsLessOrEqual(T, T, string, object[]).")] - public static void LessOrEqual(T arg1, T arg2, string message, params object[] parameters) where T : IComparable - { - Assert.That.IsLessOrEqual(arg1, arg2, message, parameters); - } - } -} \ No newline at end of file diff --git a/src/Cadru.UnitTest.Framework/CustomAssert.cs b/src/Cadru.UnitTest.Framework/CustomAssert.cs deleted file mode 100644 index 355f82cb..00000000 --- a/src/Cadru.UnitTest.Framework/CustomAssert.cs +++ /dev/null @@ -1,233 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Copyright (C) 2001-2020 Scott Dorman. -// -// -// -// Licensed under the Microsoft Public License (Ms-PL) (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://opensource.org/licenses/Ms-PL.html -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//------------------------------------------------------------------------------ - -using System; -using System.Collections; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Cadru.UnitTest.Framework -{ - /// - /// Contains assertion types that are not provided with the standard MSTest assertions. - /// - public static class CustomAssert - { - /// - /// Asserts that two strings are equal, without regard to case. - /// - /// The expected string. - /// The actual string. - [Obsolete("Use Assert.That.AreEqualIgnoringCase(string, string).")] - public static void AreEqualIgnoringCase(string expected, string actual) - { - Assert.That.AreEqualIgnoringCase(expected, actual); - } - - /// - /// Asserts that two strings are equal, without regard to case. - /// - /// The expected string. - /// The actual string. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.AreEqualIgnoringCase(string, string, string).")] - public static void AreEqualIgnoringCase(string expected, string actual, string message) - { - Assert.That.AreEqualIgnoringCase(expected, actual, message); - } - - /// - /// Asserts that two strings are equal, without regard to case. - /// - /// The expected string. - /// The actual string. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.AreEqualIgnoringCase(string, string, string, object[]).")] - public static void AreEqualIgnoringCase(string expected, string actual, string message, params object[] parameters) - { - Assert.That.AreEqualIgnoringCase(expected, actual, message, parameters); - } - - /// - /// Assert that an array, list or other collection is empty. - /// - /// The value to be tested. - [Obsolete("Use CollectionAssert.That.IsEmpty(ICollection).")] - public static void IsEmpty(ICollection collection) - { - CollectionAssert.That.IsEmpty(collection); - } - - /// - /// Assert that an array, list or other collection is empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use CollectionAssert.That.IsEmpty(ICollection, string).")] - public static void IsEmpty(ICollection collection, string message) - { - CollectionAssert.That.IsEmpty(collection, message); - } - - /// - /// Assert that an array, list or other collection is empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use CollectionAssert.That.IsEmpty(ICollection, string, object[]).")] - public static void IsEmpty(ICollection collection, string message, params object[] parameters) - { - CollectionAssert.That.IsEmpty(collection, message, parameters); - } - - /// - /// Asserts that a string is empty. - /// - /// The value to be tested. - [Obsolete("Use Assert.That.IsEmpty(string).")] - public static void IsEmpty(string value) - { - Assert.That.IsEmpty(value); - } - - /// - /// Asserts that a string is empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsEmpty(string, string).")] - public static void IsEmpty(string value, string message) - { - Assert.That.IsEmpty(value, message); - } - - /// - /// Asserts that a string is empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsEmpty(string, string, object[]).")] - public static void IsEmpty(string value, string message, params object[] parameters) - { - Assert.That.IsEmpty(value, message, parameters); - } - - /// - /// Assert that an array, list or other collection is not empty. - /// - /// The value to be tested. - [Obsolete("Use CollectionAssert.That.IsNotEmpty(ICollection).")] - public static void IsNotEmpty(ICollection collection) - { - CollectionAssert.That.IsNotEmpty(collection); - } - - /// - /// Assert that an array, list or other collection is not empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use CollectionAssert.That.IsNotEmpty(ICollection, string).")] - public static void IsNotEmpty(ICollection collection, string message) - { - CollectionAssert.That.IsNotEmpty(collection, message); - } - - /// - /// Assert that an array, list or other collection is not empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use CollectionAssert.That.IsNotEmpty(ICollection, string, object[]).")] - public static void IsNotEmpty(ICollection collection, string message, params object[] parameters) - { - CollectionAssert.That.IsNotEmpty(collection, message, parameters); - } - - /// - /// Asserts that a string is not empty. - /// - /// The value to be tested. - [Obsolete("Use Assert.That.IsNotEmpty(string).")] - public static void IsNotEmpty(string value) - { - Assert.That.IsNotEmpty(value); - } - - /// - /// Asserts that a string is not empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsNotEmpty(string, string).")] - public static void IsNotEmpty(string value, string message) - { - Assert.That.IsNotEmpty(value, message); - } - - /// - /// Asserts that a string is not empty. - /// - /// The value to be tested. - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsNotEmpty(string, string, object[]).")] - public static void IsNotEmpty(string value, string message, params object[] parameters) - { - Assert.That.IsNotEmpty(value, message, parameters); - } - } -} \ No newline at end of file diff --git a/src/Cadru.UnitTest.Framework/ExceptionAssert.cs b/src/Cadru.UnitTest.Framework/ExceptionAssert.cs deleted file mode 100644 index 0f7bf63b..00000000 --- a/src/Cadru.UnitTest.Framework/ExceptionAssert.cs +++ /dev/null @@ -1,469 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Copyright (C) 2001-2020 Scott Dorman. -// -// -// -// Licensed under the Microsoft Public License (Ms-PL) (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://opensource.org/licenses/Ms-PL.html -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//------------------------------------------------------------------------------ - -using System; -using System.Diagnostics.CodeAnalysis; - -using Cadru.UnitTest.Framework.Resources; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Cadru.UnitTest.Framework -{ - /// - /// Contains assertion types that are not provided with the standard MSTest assertions. - /// - public static class ExceptionAssert - { - /// - /// Verifies that throws an exception when - /// called and returns it. - /// - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string, object[]).")] - public static Exception Catch(Action code, string message, params object[] parameters) - { - return Catch(typeof(Exception), code, message, parameters); - } - - /// - /// Verifies that throws an exception when - /// called and returns it. - /// - /// The code to test. - /// The message that will be displayed on failure. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string).")] - public static Exception Catch(Action code, string message) - { - return Catch(typeof(Exception), code, message); - } - - /// - /// Verifies that throws an exception when - /// called and returns it. - /// - /// The code to test. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action).")] - public static Exception Catch(Action code) - { - return Catch(typeof(Exception), code); - } - - /// - /// Verifies that throws an exception of a - /// certain Type or one derived from it when called and returns it. - /// - /// The expected exception type. - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - /// The thrown by . - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] - [Obsolete("Use Assert.ThrowsException(Action, string, object[]).")] - public static Exception Catch(Type expectedExceptionType, Action code, string message, params object[] parameters) - { - try - { - code(); - } - catch (Exception ex) - { - Assert.IsInstanceOfType(ex, expectedExceptionType, message, parameters); - return ex; - } - - Assert.Fail(Strings.Assertion_ExceptionNotThrown, expectedExceptionType); - return null!; - } - - /// - /// Verifies that throws an exception of a - /// certain Type or one derived from it when called and returns it. - /// - /// The expected exception type. - /// The code to test. - /// The message that will be displayed on failure. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string")] - public static Exception Catch(Type expectedExceptionType, Action code, string message) - { - return Catch(expectedExceptionType, code, message, Array.Empty()); - } - - /// - /// Verifies that throws an exception of a - /// certain Type or one derived from it when called and returns it. - /// - /// The expected exception type. - /// The code to test. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action).")] - public static Exception Catch(Type expectedExceptionType, Action code) - { - return Catch(expectedExceptionType, code, String.Empty, Array.Empty()); - } - - /// - /// Verifies that throws an exception of a - /// certain Type or one derived from it when called and returns it. - /// - /// The expected exception type. - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string, object[]).")] - public static T Catch(Action code, string message, params object[] parameters) where T : Exception - { - return (T)Catch(typeof(T), code, message, parameters); - } - - /// - /// Verifies that throws an exception of a - /// certain Type or one derived from it when called and returns it. - /// - /// The expected exception type. - /// The code to test. - /// The message that will be displayed on failure. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string).")] - public static T Catch(Action code, string message) where T : Exception - { - return (T)Catch(typeof(T), code, message); - } - - /// - /// Verifies that throws an exception of a - /// certain Type or one derived from it when called and returns it. - /// - /// The expected exception type. - /// The code to test. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action).")] - public static T Catch(Action code) where T : System.Exception - { - return (T)Catch(typeof(T), code); - } - - /// - /// Verifies that does not throw an exception. - /// - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] - [Obsolete("Use Assert.That.DoesNotThrowException(Action, string, object[]).")] - public static void DoesNotThrow(Action code, string message, params object[] parameters) - { - Exception? caughtException = null; - - try - { - code(); - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.IsNull(caughtException, message, parameters); - } - - /// - /// Verifies that does not throw an exception. - /// - /// The code to test. - /// The message that will be displayed on failure. - [Obsolete("Use Assert.That.DoesNotThrowException(Action, string).")] - public static void DoesNotThrow(Action code, string message) - { - DoesNotThrow(code, message, Array.Empty()); - } - - /// - /// Verifies that does not throw an exception. - /// - /// The code to test. - [Obsolete("Use Assert.That.DoesNotThrowException(Action).")] - public static void DoesNotThrow(Action code) - { - DoesNotThrow(code, String.Empty, Array.Empty()); - } - - /// - /// Verifies that throws an exception when called. - /// - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string, object[]).")] - public static Exception Throws(Action code, string message, params object[] parameters) - { - return Throws(typeof(Exception), code, message, parameters); - } - - /// - /// Verifies that throws an exception when called. - /// - /// The code to test. - /// The message that will be displayed on failure. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string).")] - public static Exception Throws(Action code, string message) - { - return Throws(typeof(Exception), code, message); - } - - /// - /// Verifies that throws an exception when called. - /// - /// The code to test. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action).")] - public static Exception Throws(Action code) - { - return Throws(typeof(Exception), code); - } - - /// - /// Verifies that throws a particular exception - /// when called. - /// - /// The exception Type expected. - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - /// The thrown by . - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")] - [Obsolete("Use Assert.ThrowsException(Action, string, object[]).")] - public static Exception Throws(Type expectedExceptionType, Action code, string message, params object[] parameters) - { - try - { - code(); - } - catch (Exception ex) - { - TypeAssert.IsType(ex, expectedExceptionType, message, parameters); - return ex; - } - - Assert.Fail(Strings.Assertion_ExceptionNotThrown, expectedExceptionType); - return null!; - } - - /// - /// Verifies that throws a particular exception - /// when called. - /// - /// The exception Type expected. - /// The code to test. - /// The message that will be displayed on failure. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string).")] - public static Exception Throws(Type expectedExceptionType, Action code, string message) - { - return Throws(expectedExceptionType, code, message, Array.Empty()); - } - - /// - /// Verifies that throws a particular exception - /// when called. - /// - /// The exception Type expected. - /// The code to test. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action).")] - public static Exception Throws(Type expectedExceptionType, Action code) - { - return Throws(expectedExceptionType, code, String.Empty, Array.Empty()); - } - - /// - /// Verifies that throws a particular exception - /// when called. - /// - /// Type of the expected exception. - /// The code to test. - /// The message that will be displayed on failure. - /// - /// An array of parameters to use when formatting . - /// - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string, object[]).")] - public static T Throws(Action code, string message, params object[] parameters) where T : Exception - { - return (T)Throws(typeof(T), code, message, parameters); - } - - /// - /// Verifies that throws a particular exception - /// when called. - /// - /// Type of the expected exception. - /// The code to test. - /// The message that will be displayed on failure. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string).")] - public static T Throws(Action code, string message) where T : Exception - { - return Throws(code, message, Array.Empty()); - } - - /// - /// Verifies that throws a particular exception - /// when called. - /// - /// Type of the expected exception. - /// The code to test. - /// The thrown by . - [Obsolete("Use Assert.ThrowsException(Action, string).")] - public static T Throws(Action code) where T : Exception - { - return Throws(code, String.Empty, Array.Empty()); - } - - /// - /// Verifies that - /// is of the specified type. - /// - /// The source exception type. - /// - /// The exception whose will be tested. - /// - /// The expected type of the inner exception. - /// The original . - public static T WithInnerException(this T exception, Type innerException) where T : Exception - { - Assert.That.IsType(exception.InnerException, innerException, Strings.WrongExceptionThrown, innerException.Name, typeof(T).Name, exception.Message, exception.StackTrace); - return exception; - } - - - /// - /// Verifies that - /// is of the specified type. - /// - /// The inner exception type. - /// - /// The exception whose will be tested. - /// - /// The original . - public static Exception WithInnerException(this Exception exception) - where T : Exception - { - Assert.That.IsType(exception.InnerException, Strings.WrongExceptionThrown, exception.InnerException.GetType().Name, typeof(T).Name, exception.Message, exception.StackTrace); - return exception; - } - - /// - /// Verifies that the exception contains - /// the given text. - /// - /// The exception type. - /// - /// The exception whose will be searched. - /// - /// The text to search for in the exception . - /// - /// One of the values. - /// - /// The original . - public static T WithMessage(this T exception, string message, ExceptionMessageComparison comparison) where T : Exception - { - Assert.IsNotNull(exception); - - switch (comparison) - { - case ExceptionMessageComparison.Exact: - Assert.AreEqual(exception.Message, message); - break; - - case ExceptionMessageComparison.Contains: - Assert.IsTrue(exception.Message.Contains(message)); - break; - - case ExceptionMessageComparison.StartsWith: - Assert.IsTrue(exception.Message.StartsWith(message)); - break; - - case ExceptionMessageComparison.EndsWith: - Assert.IsTrue(exception.Message.EndsWith(message)); - break; - } - - return exception; - } - - /// - /// Verifies that the exception is equal - /// to the given text. - /// - /// The exception type. - /// - /// The exception whose will be compared. - /// - /// The text to compare. - /// The original . - public static T WithMessage(this T exception, string message) where T : Exception - { - return exception.WithMessage(message, ExceptionMessageComparison.Exact); - } - - /// - /// Verifies that the exception - /// property is equal to the - /// given text. - /// - /// The exception type. - /// - /// The exception whose - /// property will be compared. - /// - /// The text to compare. - /// The original . - public static T WithParameter(this T exception, string parameterName) where T : ArgumentException - { - Assert.IsNotNull(exception); - Assert.AreEqual(exception.ParamName, parameterName); - return exception; - } - } -} \ No newline at end of file diff --git a/src/Cadru.UnitTest.Framework/ExceptionExtensions.cs b/src/Cadru.UnitTest.Framework/ExceptionExtensions.cs new file mode 100644 index 00000000..d0479b64 --- /dev/null +++ b/src/Cadru.UnitTest.Framework/ExceptionExtensions.cs @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// Copyright (C) 2001-2020 Scott Dorman. +// +// +// +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//------------------------------------------------------------------------------ + +using System; +using System.Diagnostics.CodeAnalysis; + +using Cadru.UnitTest.Framework.Resources; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Cadru.UnitTest.Framework +{ + /// + /// Contains extensions for working with Exceptions in MSTest. + /// + public static class ExceptionExtensions + { + /// + /// Verifies that + /// is of the specified type. + /// + /// The source exception type. + /// + /// The exception whose will be tested. + /// + /// The expected type of the inner exception. + /// The original . + public static T WithInnerException(this T exception, Type innerException) where T : Exception + { + Assert.IsNotNull(exception.InnerException); + Assert.That.IsType(exception.InnerException!, innerException, Strings.WrongExceptionThrown, innerException.Name, typeof(T).Name, exception.Message, exception.StackTrace); + return exception; + } + + /// + /// Verifies that + /// is of the specified type. + /// + /// The inner exception type. + /// + /// The exception whose will be tested. + /// + /// The original . + public static Exception WithInnerException(this Exception exception) + where T : Exception + { + Assert.IsNotNull(exception.InnerException); + Assert.That.IsType(exception.InnerException!, Strings.WrongExceptionThrown, exception.InnerException!.GetType().Name, typeof(T).Name, exception.Message, exception.StackTrace); + return exception; + } + + /// + /// Verifies that the exception contains + /// the given text. + /// + /// The exception type. + /// + /// The exception whose will be searched. + /// + /// The text to search for in the exception . + /// + /// One of the values. + /// + /// The original . + public static T WithMessage(this T exception, string message, ExceptionMessageComparison comparison) where T : Exception + { + Assert.IsNotNull(exception); + + switch (comparison) + { + case ExceptionMessageComparison.Exact: + Assert.AreEqual(exception.Message, message); + break; + + case ExceptionMessageComparison.Contains: + Assert.IsTrue(exception.Message.Contains(message)); + break; + + case ExceptionMessageComparison.StartsWith: + Assert.IsTrue(exception.Message.StartsWith(message)); + break; + + case ExceptionMessageComparison.EndsWith: + Assert.IsTrue(exception.Message.EndsWith(message)); + break; + } + + return exception; + } + + /// + /// Verifies that the exception is equal + /// to the given text. + /// + /// The exception type. + /// + /// The exception whose will be compared. + /// + /// The text to compare. + /// The original . + public static T WithMessage(this T exception, string message) where T : Exception + { + return exception.WithMessage(message, ExceptionMessageComparison.Exact); + } + + /// + /// Verifies that the exception + /// property is equal to the + /// given text. + /// + /// The exception type. + /// + /// The exception whose + /// property will be compared. + /// + /// The text to compare. + /// The original . + public static T WithParameter(this T exception, string parameterName) where T : ArgumentException + { + Assert.IsNotNull(exception); + Assert.AreEqual(exception.ParamName, parameterName); + return exception; + } + } +} \ No newline at end of file diff --git a/src/Cadru.UnitTest.Framework/ExceptionMessageComparison.cs b/src/Cadru.UnitTest.Framework/ExceptionMessageComparison.cs index 1a991257..989309b7 100644 --- a/src/Cadru.UnitTest.Framework/ExceptionMessageComparison.cs +++ b/src/Cadru.UnitTest.Framework/ExceptionMessageComparison.cs @@ -26,7 +26,7 @@ namespace Cadru.UnitTest.Framework { /// /// Options used by the - /// + /// /// method to determine how to compare the exception message. /// public enum ExceptionMessageComparison diff --git a/src/Cadru.UnitTest.Framework/Helpers.cs b/src/Cadru.UnitTest.Framework/Helpers.cs index 6db3b39e..38e738d8 100644 --- a/src/Cadru.UnitTest.Framework/Helpers.cs +++ b/src/Cadru.UnitTest.Framework/Helpers.cs @@ -1,5 +1,6 @@  using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using Cadru.UnitTest.Framework.Resources; @@ -10,6 +11,34 @@ namespace Cadru.UnitTest.Framework { internal static class Helpers { + /// + /// Checks the parameter for valid conditions + /// + /// + /// The parameter. + /// + /// + /// The assertion Name. + /// + /// + /// parameter name + /// + /// + /// message for the invalid parameter exception + /// + /// + /// The parameters. + /// +#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. + internal static void CheckParameterNotNull([NotNull] object param, string assertionName, string parameterName, string message, params object?[] parameters) + { + if (param == null) + { + HandleFail(assertionName, String.Format(CultureInfo.CurrentCulture, Strings.NullParameterToAssert, parameterName, message), parameters); + } + } +#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + /// /// Helper function that creates and throws an AssertionFailedException /// @@ -22,7 +51,7 @@ internal static class Helpers /// /// The parameters. /// - internal static void HandleFail(string assertionName, string? message, params object[]? parameters) + internal static void HandleFail(string assertionName, string message, params object?[] parameters) { var finalMessage = String.Empty; if (!String.IsNullOrEmpty(message)) @@ -50,7 +79,7 @@ internal static void HandleFail(string assertionName, string? message, params ob /// /// The converted string. /// - internal static string? ReplaceNulls(object? input) + internal static string ReplaceNulls(object input) { // Use the localized "(null)" string for null values. if (input == null) @@ -84,7 +113,7 @@ internal static void HandleFail(string assertionName, string? message, params ob /// /// This is only public and still present to preserve compatibility with the V1 framework. /// - public static string? ReplaceNullChars(string? input) + public static string ReplaceNullChars(string input) { if (String.IsNullOrEmpty(input)) { diff --git a/src/Cadru.UnitTest.Framework/Resources/Strings.Designer.cs b/src/Cadru.UnitTest.Framework/Resources/Strings.Designer.cs index 2168291f..5deee786 100644 --- a/src/Cadru.UnitTest.Framework/Resources/Strings.Designer.cs +++ b/src/Cadru.UnitTest.Framework/Resources/Strings.Designer.cs @@ -114,6 +114,33 @@ internal class Strings { } } + /// + /// Looks up a localized string similar to String '{0}' contains string '{1}'. {2}.. + /// + internal static string DoesNotContainFail { + get { + return ResourceManager.GetString("DoesNotContainFail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to String '{0}' ends with string '{1}'. {2}.. + /// + internal static string DoesNotEndWithFail { + get { + return ResourceManager.GetString("DoesNotEndWithFail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to String '{0}' starts with string '{1}'. {2}.. + /// + internal static string DoesNotStartWithFail { + get { + return ResourceManager.GetString("DoesNotStartWithFail", resourceCulture); + } + } + /// /// Looks up a localized string similar to An exception of type {1} was thrown but was not expected. {0} ///Exception Message: {2} @@ -215,6 +242,24 @@ internal class Strings { } } + /// + /// Looks up a localized string similar to Expected an ordered collection.. + /// + internal static string IsOrderedFail { + get { + return ResourceManager.GetString("IsOrderedFail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The parameter '{0}' is invalid. The value cannot be null. {1}.. + /// + internal static string NullParameterToAssert { + get { + return ResourceManager.GetString("NullParameterToAssert", resourceCulture); + } + } + /// /// Looks up a localized string similar to Threw exception {0}, but exception {1} was expected. ///Exception Message: {3} diff --git a/src/Cadru.UnitTest.Framework/Resources/Strings.resx b/src/Cadru.UnitTest.Framework/Resources/Strings.resx index eb86c025..a2591867 100644 --- a/src/Cadru.UnitTest.Framework/Resources/Strings.resx +++ b/src/Cadru.UnitTest.Framework/Resources/Strings.resx @@ -135,6 +135,15 @@ (null) + + String '{0}' contains string '{1}'. {2}. + + + String '{0}' ends with string '{1}'. {2}. + + + String '{0}' starts with string '{1}'. {2}. + An exception of type {1} was thrown but was not expected. {0} Exception Message: {2} @@ -170,6 +179,12 @@ Stack Trace: {3} Expected a string with 1 or more characters but actual was (null). + + Expected an ordered collection. + + + The parameter '{0}' is invalid. The value cannot be null. {1}. + Threw exception {0}, but exception {1} was expected. Exception Message: {3} diff --git a/src/Cadru.UnitTest.Framework/StringAssertExtensions.Emptiness.cs b/src/Cadru.UnitTest.Framework/StringAssertExtensions.Emptiness.cs new file mode 100644 index 00000000..19cce520 --- /dev/null +++ b/src/Cadru.UnitTest.Framework/StringAssertExtensions.Emptiness.cs @@ -0,0 +1,110 @@ +using System; +using System.Globalization; + +using Cadru.UnitTest.Framework.Resources; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Cadru.UnitTest.Framework +{ + /// + /// A collection of helpers to test various conditions within unit tests. + /// If the condition being tested is not met, an exception is thrown. + /// + public static partial class StringAssertExtensions + { + /// + /// Asserts that a string is empty. + /// + /// The instance to extend. + /// The value to be tested. + public static void IsEmpty(this StringAssert assert, string? value) + { + assert.IsEmpty(value, Strings.IsEmptyStringFailMsg); + } + + /// + /// Asserts that a string is empty. + /// + /// The instance to extend. + /// The value to be tested. + /// + /// A message to display. This message can be seen in the unit test results. + /// + public static void IsEmpty(this StringAssert assert, string? value, string message) + { + assert.IsEmpty(value, message, value?.Length!); + } + + /// + /// Asserts that a string is empty. + /// + /// The instance to extend. + /// The value to be tested. + /// + /// A message to display. This message can be seen in the unit test results. + /// + /// + /// An array of parameters to use when formatting . + /// + public static void IsEmpty(this StringAssert assert, string? value, string message, params object?[] parameters) + { + if (value == null) + { + Helpers.HandleFail("Assert.IsEmpty", Strings.IsEmptyStringFailOnNullMsg); + } + + if (value!.Length != 0) + { + Helpers.HandleFail("Assert.IsEmpty", message, parameters); + } + } + + /// + /// Asserts that a string is not empty. + /// + /// The instance to extend. + /// The value to be tested. + public static void IsNotEmpty(this StringAssert assert, string? value) + { + assert.IsNotEmpty(value, Strings.IsNotEmptyStringFailMsg); + } + + /// + /// Asserts that a string is not empty. + /// + /// The instance to extend. + /// The value to be tested. + /// + /// A message to display. This message can be seen in the unit test results. + /// + public static void IsNotEmpty(this StringAssert assert, string? value, string message) + { + assert.IsNotEmpty(value, message, Array.Empty()); + } + + /// + /// Asserts that a string is not empty. + /// + /// The instance to extend. + /// The value to be tested. + /// + /// A message to display. This message can be seen in the unit test results. + /// + /// + /// An array of parameters to use when formatting . + /// + public static void IsNotEmpty(this StringAssert assert, string? value, string message, params object?[] parameters) + { + if (value == null) + { + Helpers.HandleFail("Assert.IsNotEmpty", Strings.IsNotEmptyStringFailOnNullMsg); + } + + if (value?.Length == 0) + { + Helpers.HandleFail("Assert.IsNotEmpty", message, parameters); + } + } + } +} diff --git a/src/Cadru.UnitTest.Framework/StringAssertExtensions.Equality.cs b/src/Cadru.UnitTest.Framework/StringAssertExtensions.Equality.cs new file mode 100644 index 00000000..bc87fd37 --- /dev/null +++ b/src/Cadru.UnitTest.Framework/StringAssertExtensions.Equality.cs @@ -0,0 +1,106 @@ +using System; + +using Cadru.UnitTest.Framework.Resources; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Cadru.UnitTest.Framework +{ + /// + /// A collection of helpers to test various conditions within unit tests. + /// If the condition being tested is not met, an exception is thrown. + /// + public static partial class StringAssertExtensions + { + /// + /// Asserts that two strings are equal, without regard to case. + /// + /// The instance to extend. + /// The expected string. + /// The actual string. + public static void AreEqualIgnoringCase(this StringAssert assert, string expected, string actual) + { + assert.AreEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure); + } + + /// + /// Asserts that two strings are equal, without regard to case. + /// + /// The instance to extend. + /// The expected string. + /// The actual string. + /// + /// A message to display. This message can be seen in the unit test results. + /// + public static void AreEqualIgnoringCase(this StringAssert assert, string expected, string actual, string message) + { + assert.AreEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure, expected, actual); + } + + /// + /// Asserts that two strings are equal, without regard to case. + /// + /// The instance to extend. + /// The expected string. + /// The actual string. + /// + /// A message to display. This message can be seen in the unit test results. + /// + /// + /// An array of parameters to use when formatting . + /// + public static void AreEqualIgnoringCase(this StringAssert assert, string expected, string actual, string message, params object?[] parameters) + { + if (String.Compare(expected, actual, StringComparison.CurrentCultureIgnoreCase) != 0) + { + Helpers.HandleFail("StringAssert.AreEqualIgnoringCase", message, parameters); + } + } + + /// + /// Asserts that two strings are not equal, without regard to case. + /// + /// The instance to extend. + /// The expected string. + /// The actual string. + public static void AreNotEqualIgnoringCase(this StringAssert assert, string expected, string actual) + { + assert.AreNotEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure); + } + + /// + /// Asserts that two strings are not equal, without regard to case. + /// + /// The instance to extend. + /// The expected string. + /// The actual string. + /// + /// A message to display. This message can be seen in the unit test results. + /// + public static void AreNotEqualIgnoringCase(this StringAssert assert, string expected, string actual, string message) + { + assert.AreNotEqualIgnoringCase(expected, actual, Strings.Assertion_GenericFailure, expected, actual); + } + + /// + /// Asserts that two strings are not equal, without regard to case. + /// + /// The instance to extend. + /// The expected string. + /// The actual string. + /// + /// A message to display. This message can be seen in the unit test results. + /// + /// + /// An array of parameters to use when formatting . + /// + public static void AreNotEqualIgnoringCase(this StringAssert assert, string expected, string actual, string message, params object?[] parameters) + { + if (String.Compare(expected, actual, StringComparison.CurrentCultureIgnoreCase) == 0) + { + Helpers.HandleFail("StringAssert.AreEqualIgnoringCase", message, parameters); + } + } + + } +} diff --git a/src/Cadru.UnitTest.Framework/StringAssertExtensions.Substrings.cs b/src/Cadru.UnitTest.Framework/StringAssertExtensions.Substrings.cs new file mode 100644 index 00000000..571d7c9d --- /dev/null +++ b/src/Cadru.UnitTest.Framework/StringAssertExtensions.Substrings.cs @@ -0,0 +1,517 @@ +using System; +using System.Globalization; + +using Cadru.UnitTest.Framework.Resources; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Cadru.UnitTest.Framework +{ + /// + /// A collection of helpers to test various conditions within unit tests. + /// If the condition being tested is not met, an exception is thrown. + /// + public static partial class StringAssertExtensions + { + /// + /// Tests whether the specified string does not contain the specified substring + /// and throws an exception if the substring does occur within the + /// test string. + /// + /// The instance to extend. + /// + /// The string that is expected to contain . + /// + /// + /// The string expected to occur within . + /// + /// + /// Thrown if is not found in + /// . + /// + public static void DoesNotContain(this StringAssert assert, string value, string substring) + { + assert.DoesNotContain(value, substring, String.Empty, StringComparison.Ordinal); + } + + /// + /// Tests whether the specified string does not contain the specified substring + /// and throws an exception if the substring does occur within the + /// test string. + /// + /// The instance to extend. + /// + /// The string that is expected to contain . + /// + /// + /// The string expected to occur within . + /// + /// + /// The comparison method to compare strings . + /// + /// + /// Thrown if is not found in + /// . + /// + public static void DoesNotContain(this StringAssert assert, string value, string substring, StringComparison comparisonType) + { + assert.DoesNotContain(value, substring, String.Empty, comparisonType); + } + + /// + /// Tests whether the specified string does not contain the specified substring + /// and throws an exception if the substring does occur within the + /// test string. + /// + /// The instance to extend. + /// + /// The string that is expected to contain . + /// + /// + /// The string expected to occur within . + /// + /// + /// The message to include in the exception when + /// is not in . The message is shown in + /// test results. + /// + /// + /// Thrown if is not found in + /// . + /// + public static void DoesNotContain(this StringAssert assert, string value, string substring, string message) + { + assert.DoesNotContain(value, substring, message, StringComparison.Ordinal); + } + + /// + /// Tests whether the specified string does not contain the specified substring + /// and throws an exception if the substring does occur within the + /// test string. + /// + /// The instance to extend. + /// + /// The string that is expected to contain . + /// + /// + /// The string expected to occur within . + /// + /// + /// The message to include in the exception when + /// is not in . The message is shown in + /// test results. + /// + /// + /// The comparison method to compare strings . + /// + /// + /// Thrown if is not found in + /// . + /// + public static void DoesNotContain(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType) + { + assert.DoesNotContain(value, substring, message, comparisonType, Empty); + } + + /// + /// Tests whether the specified string does not contain the specified substring + /// and throws an exception if the substring does occur within the + /// test string. + /// + /// The instance to extend. + /// + /// The string that is expected to contain . + /// + /// + /// The string expected to occur within . + /// + /// + /// The message to include in the exception when + /// is not in . The message is shown in + /// test results. + /// + /// + /// An array of parameters to use when formatting . + /// + /// + /// Thrown if is not found in + /// . + /// + public static void DoesNotContain(this StringAssert assert, string value, string substring, string message, params object?[] parameters) + { + assert.DoesNotContain(value, substring, message, StringComparison.Ordinal, parameters); + } + + /// + /// Tests whether the specified string does not contain the specified substring + /// and throws an exception if the substring does occur within the + /// test string. + /// + /// The instance to extend. + /// + /// The string that is expected to contain . + /// + /// + /// The string expected to occur within . + /// + /// + /// The message to include in the exception when + /// is not in . The message is shown in + /// test results. + /// + /// + /// The comparison method to compare strings . + /// + /// + /// An array of parameters to use when formatting . + /// + /// + /// Thrown if is not found in + /// . + /// + public static void DoesNotContain(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType, params object?[] parameters) + { + Helpers.CheckParameterNotNull(value, "StringAssert.DoesNotContain", "value", String.Empty); + Helpers.CheckParameterNotNull(substring, "StringAssert.DoesNotContain", "substring", String.Empty); + if (value.IndexOf(substring, comparisonType) > 0) + { + var finalMessage = String.Format(CultureInfo.CurrentCulture, Strings.DoesNotContainFail, value, substring, message); + Helpers.HandleFail("StringAssert.DoesNotContain", finalMessage, parameters); + } + } + + /// + /// Tests whether the specified string begins with the specified substring + /// and throws an exception if the test string does not start with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to begin with . + /// + /// + /// The string expected to be a prefix of . + /// + /// + /// Thrown if does not begin with + /// . + /// + public static void DoesNotStartWith(this StringAssert assert, string value, string substring) + { + assert.DoesNotStartWith(value, substring, String.Empty, StringComparison.Ordinal); + } + + /// + /// Tests whether the specified string begins with the specified substring + /// and throws an exception if the test string does not start with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to begin with . + /// + /// + /// The string expected to be a prefix of . + /// + /// + /// The comparison method to compare strings . + /// + /// + /// Thrown if does not begin with + /// . + /// + public static void DoesNotStartWith(this StringAssert assert, string value, string substring, StringComparison comparisonType) + { + assert.DoesNotStartWith(value, substring, String.Empty, comparisonType, Empty); + } + + /// + /// Tests whether the specified string begins with the specified substring + /// and throws an exception if the test string does not start with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to begin with . + /// + /// + /// The string expected to be a prefix of . + /// + /// + /// The message to include in the exception when + /// does not begin with . The message is + /// shown in test results. + /// + /// + /// Thrown if does not begin with + /// . + /// + public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message) + { + assert.DoesNotStartWith(value, substring, message, StringComparison.Ordinal); + } + + /// + /// Tests whether the specified string begins with the specified substring + /// and throws an exception if the test string does not start with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to begin with . + /// + /// + /// The string expected to be a prefix of . + /// + /// + /// The message to include in the exception when + /// does not begin with . The message is + /// shown in test results. + /// + /// + /// An array of parameters to use when formatting . + /// + /// + /// Thrown if does not begin with + /// . + /// + public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message, params object?[] parameters) + { + assert.DoesNotStartWith(value, substring, message, StringComparison.Ordinal, parameters); + } + + /// + /// Tests whether the specified string begins with the specified substring + /// and throws an exception if the test string does not start with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to begin with . + /// + /// + /// The string expected to be a prefix of . + /// + /// + /// The message to include in the exception when + /// does not begin with . The message is + /// shown in test results. + /// + /// + /// The comparison method to compare strings . + /// + /// + /// Thrown if does not begin with + /// . + /// + public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType) + { + assert.DoesNotStartWith(value, substring, message, comparisonType, Empty); + } + + /// + /// Tests whether the specified string begins with the specified substring + /// and throws an exception if the test string does not start with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to begin with . + /// + /// + /// The string expected to be a prefix of . + /// + /// + /// The message to include in the exception when + /// does not begin with . The message is + /// shown in test results. + /// + /// + /// The comparison method to compare strings . + /// + /// + /// An array of parameters to use when formatting . + /// + /// + /// Thrown if does not begin with + /// . + /// + public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType, params object?[] parameters) + { + Helpers.CheckParameterNotNull(value, "StringAssert.DoesNotStartWith", "value", String.Empty); + Helpers.CheckParameterNotNull(substring, "StringAssert.DoesNotStartWith", "substring", String.Empty); + if (value.StartsWith(substring, comparisonType)) + { + var finalMessage = String.Format(CultureInfo.CurrentCulture, Strings.DoesNotStartWithFail, value, substring, message); + Helpers.HandleFail("StringAssert.DoesNotStartWith", finalMessage, parameters); + } + } + + /// + /// Tests whether the specified string ends with the specified substring + /// and throws an exception if the test string does not end with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to end with . + /// + /// + /// The string expected to be a suffix of . + /// + /// + /// Thrown if does not end with + /// . + /// + public static void DoesNotEndWith(this StringAssert assert, string value, string substring) + { + assert.DoesNotEndWith(value, substring, String.Empty, StringComparison.Ordinal); + } + + /// + /// Tests whether the specified string ends with the specified substring + /// and throws an exception if the test string does not end with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to end with . + /// + /// + /// The string expected to be a suffix of . + /// + /// + /// The comparison method to compare strings . + /// + /// + /// Thrown if does not end with + /// . + /// + public static void DoesNotEndWith(this StringAssert assert, string value, string substring, StringComparison comparisonType) + { + assert.DoesNotEndWith(value, substring, String.Empty, comparisonType, Empty); + } + + /// + /// Tests whether the specified string ends with the specified substring + /// and throws an exception if the test string does not end with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to end with . + /// + /// + /// The string expected to be a suffix of . + /// + /// + /// The message to include in the exception when + /// does not end with . The message is + /// shown in test results. + /// + /// + /// Thrown if does not end with + /// . + /// + public static void DoesNotEndWith(this StringAssert assert, string value, string substring, string message) + { + assert.DoesNotEndWith(value, substring, message, StringComparison.Ordinal); + } + + /// + /// Tests whether the specified string ends with the specified substring + /// and throws an exception if the test string does not end with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to end with . + /// + /// + /// The string expected to be a suffix of . + /// + /// + /// The message to include in the exception when + /// does not end with . The message is + /// shown in test results. + /// + /// + /// An array of parameters to use when formatting . + /// + /// + /// Thrown if does not end with + /// . + /// + public static void DoesNotEndWith(this StringAssert assert, string value, string substring, string message, params object?[] parameters) + { + assert.DoesNotEndWith(value, substring, message, StringComparison.Ordinal, parameters); + } + + /// + /// Tests whether the specified string ends with the specified substring + /// and throws an exception if the test string does not end with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to end with . + /// + /// + /// The string expected to be a suffix of . + /// + /// + /// The message to include in the exception when + /// does not end with . The message is + /// shown in test results. + /// + /// + /// The comparison method to compare strings . + /// + /// + /// Thrown if does not end with + /// . + /// + public static void DoesNotEndWith(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType) + { + assert.DoesNotEndWith(value, substring, message, comparisonType, Empty); + } + + /// + /// Tests whether the specified string ends with the specified substring + /// and throws an exception if the test string does not end with the + /// substring. + /// + /// The instance to extend. + /// + /// The string that is expected to end with . + /// + /// + /// The string expected to be a suffix of . + /// + /// + /// The message to include in the exception when + /// does not end with . The message is + /// shown in test results. + /// + /// + /// The comparison method to compare strings . + /// + /// + /// An array of parameters to use when formatting . + /// + /// + /// Thrown if does not end with + /// . + /// + public static void DoesNotEndWith(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType, params object?[] parameters) + { + Helpers.CheckParameterNotNull(value, "StringAssert.DoesNotEndWith", "value", String.Empty); + Helpers.CheckParameterNotNull(substring, "StringAssert.DoesNotEndWith", "substring", String.Empty); + if (value.EndsWith(substring, comparisonType)) + { + var finalMessage = String.Format(CultureInfo.CurrentCulture, Strings.DoesNotEndWithFail, value, substring, message); + Helpers.HandleFail("StringAssert.DoesNotEndWith", finalMessage, parameters); + } + } + } +} diff --git a/src/Cadru.UnitTest.Framework/StringAssertExtensions.cs b/src/Cadru.UnitTest.Framework/StringAssertExtensions.cs new file mode 100644 index 00000000..e381a410 --- /dev/null +++ b/src/Cadru.UnitTest.Framework/StringAssertExtensions.cs @@ -0,0 +1,19 @@ +using System; +using System.Globalization; + +using Cadru.UnitTest.Framework.Resources; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Cadru.UnitTest.Framework +{ + /// + /// A collection of helpers to test various conditions within unit tests. + /// If the condition being tested is not met, an exception is thrown. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "")] + public static partial class StringAssertExtensions + { + private static readonly object[] Empty = Array.Empty(); + } +} diff --git a/src/Cadru.UnitTest.Framework/TypeAssert.cs b/src/Cadru.UnitTest.Framework/TypeAssert.cs deleted file mode 100644 index c8aeca2e..00000000 --- a/src/Cadru.UnitTest.Framework/TypeAssert.cs +++ /dev/null @@ -1,173 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Copyright (C) 2001-2020 Scott Dorman. -// -// -// -// Licensed under the Microsoft Public License (Ms-PL) (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://opensource.org/licenses/Ms-PL.html -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//------------------------------------------------------------------------------ - -using System; - -using Cadru.UnitTest.Framework.Resources; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Cadru.UnitTest.Framework -{ - /// - /// Contains assertion types that are not provided with the standard MSTest assertions. - /// - public static class TypeAssert - { - /// - /// Asserts that an object may be assigned a value of a given . - /// - /// The value to be tested. - /// The expected . - [Obsolete("Use Assert.That.IsAssignableFrom(object).")] - public static void IsAssignableFrom(object value, Type expectedType) - { - Assert.That.IsAssignableFrom(value, expectedType, Strings.Assertion_ExpectedToBeAssignableFrom, value, expectedType); - } - - /// - /// Asserts that an object may be assigned a value of a given . - /// - /// The value to be tested. - /// The expected . - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsAssignableFrom(object, string).")] - public static void IsAssignableFrom(object value, Type expectedType, string message) - { - Assert.That.IsAssignableFrom(value, expectedType, message, value, expectedType); - } - - /// - /// Asserts that an object may be assigned a value of a given . - /// - /// The value to be tested. - /// The expected . - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsAssignableFrom(object, string, object[]).")] - public static void IsAssignableFrom(object value, Type expectedType, string message, params object[] parameters) - { - Assert.That.IsAssignableFrom(value, expectedType, message, parameters); - } - - /// - /// Asserts that an object may not be assigned a value of a given . - /// - /// The value to be tested. - /// The expected . - [Obsolete("Use Assert.That.IsNotAssignableFrom(object).")] - public static void IsNotAssignableFrom(object value, Type expectedType) - { - Assert.That.IsNotAssignableFrom(value, expectedType, Strings.Assertion_ExpectedToBeAssignableFrom, value, expectedType); - } - - /// - /// Asserts that an object may not be assigned a value of a given . - /// - /// The value to be tested. - /// The expected . - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsNotAssignableFrom(object, string).")] - public static void IsNotAssignableFrom(object value, Type expectedType, string message) - { - Assert.That.IsNotAssignableFrom(value, expectedType, message, value, expectedType); - } - - /// - /// Asserts that an object may not be assigned a value of a given . - /// - /// The value to be tested. - /// The expected . - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsNotAssignableFrom(object, string, object[]).")] - public static void IsNotAssignableFrom(object value, Type expectedType, string message, params object[] parameters) - { - Assert.That.IsNotAssignableFrom(value, expectedType, message, parameters); - } - - /// - /// Asserts that an object is of the given . - /// - /// The expected . - /// The value to be tested. - [Obsolete("Use Assert.That.IsType(object).")] - public static void IsType(object value) - { - Assert.That.IsType(value); - } - - /// - /// Asserts that an object is of the given . - /// - /// The value to be tested. - /// The expected . - [Obsolete("Use Assert.That.IsType(object, string).")] - public static void IsType(object value, Type expectedType) - { - Assert.That.IsType(value, expectedType, Strings.Assertion_WrongType, expectedType, value?.GetType()!); - } - - /// - /// Asserts that an object is of the given . - /// - /// The value to be tested. - /// The expected . - /// - /// A message to display. This message can be seen in the unit test results. - /// - [Obsolete("Use Assert.That.IsType(object, string).")] - public static void IsType(object value, Type expectedType, string message) - { - Assert.That.IsType(value, expectedType, message, expectedType, value?.GetType()!); - } - - /// - /// Asserts that an object is of the given . - /// - /// The value to be tested. - /// The expected . - /// - /// A message to display. This message can be seen in the unit test results. - /// - /// - /// An array of parameters to use when formatting . - /// - [Obsolete("Use Assert.That.IsType(object, string, object[]).")] - public static void IsType(object value, Type expectedType, string message, params object[] parameters) - { - Assert.That.IsType(value, expectedType, message, parameters); - } - } -} \ No newline at end of file diff --git a/tests/Cadru.Collections.Tests/NameValuePairTests.cs b/tests/Cadru.Collections.Tests/NameValuePairTests.cs index 7a513c47..4de3c17a 100644 --- a/tests/Cadru.Collections.Tests/NameValuePairTests.cs +++ b/tests/Cadru.Collections.Tests/NameValuePairTests.cs @@ -74,8 +74,6 @@ public void Equals() Assert.IsTrue(nvp.Equals(nvp2)); Assert.IsTrue(nvp.Equals((object)nvp2)); - Assert.IsFalse(nvp == null); - Assert.IsTrue(nvp != null); Assert.IsFalse(nvp.Equals(null)); Assert.IsFalse(nvp.Equals("test")); diff --git a/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs b/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs index 35678a6f..eb4e637a 100644 --- a/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs +++ b/tests/Cadru.Net.Tests/Http/HttpExtensionsTests.cs @@ -42,10 +42,10 @@ public void AsFormattedString() Assert.ThrowsException(() => { request.AsFormattedString(); }); request = new HttpRequestMessage(); - Assert.That.IsNotEmpty(request.AsFormattedString()); + StringAssert.That.IsNotEmpty(request.AsFormattedString()); request.Content = new StringContent("body content"); - Assert.That.IsNotEmpty(request.AsFormattedString()); + StringAssert.That.IsNotEmpty(request.AsFormattedString()); StringAssert.Contains(request.AsFormattedString(), "Body:"); } @@ -80,7 +80,7 @@ public void CreateRequestMessage() Assert.IsNotNull(requestMessage); Assert.IsTrue(requestMessage.Method == HttpMethod.Get); Assert.AreEqual("https://example.com/test?test=testvalue", requestMessage.RequestUri.AbsoluteUri); - Assert.That.IsNotEmpty(requestMessage.RequestUri.Query); + StringAssert.That.IsNotEmpty(requestMessage.RequestUri.Query); } } } \ No newline at end of file diff --git a/tests/Cadru.UnitTest.Framework.Tests/CustomAssertTests.cs b/tests/Cadru.UnitTest.Framework.Tests/CustomAssertTests.cs index 7e253e92..a217882a 100644 --- a/tests/Cadru.UnitTest.Framework.Tests/CustomAssertTests.cs +++ b/tests/Cadru.UnitTest.Framework.Tests/CustomAssertTests.cs @@ -34,21 +34,21 @@ public class CustomAssertTests [TestMethod] public void CaseInsensitiveCompare() { - Assert.That.AreEqualIgnoringCase("name", "NAME"); - Assert.That.AreEqualIgnoringCase("name", "NAME", "test message"); + StringAssert.That.AreEqualIgnoringCase("name", "NAME"); + StringAssert.That.AreEqualIgnoringCase("name", "NAME", "test message"); } [TestMethod, ExpectedException(typeof(AssertFailedException))] public void CaseInsensitiveCompareFails() { - Assert.That.AreEqualIgnoringCase("Name", "NAMES"); - Assert.That.AreEqualIgnoringCase("Name", "NAMES", "test message"); + StringAssert.That.AreEqualIgnoringCase("Name", "NAMES"); + StringAssert.That.AreEqualIgnoringCase("Name", "NAMES", "test message"); } [TestMethod] public void IsEmpty() { - Assert.That.IsEmpty("", "Failed on empty String"); + StringAssert.That.IsEmpty("", "Failed on empty String"); CollectionAssert.That.IsEmpty(Array.Empty(), "Failed on empty Array"); CollectionAssert.That.IsEmpty(new ArrayList(), "Failed on empty ArrayList"); CollectionAssert.That.IsEmpty(new Hashtable(), "Failed on empty Hashtable"); @@ -63,13 +63,13 @@ public void IsEmptyFailsOnNonEmptyArray() [TestMethod, ExpectedException(typeof(AssertFailedException))] public void IsEmptyFailsOnNullString() { - Assert.That.IsEmpty((string)null); + StringAssert.That.IsEmpty((string)null); } [TestMethod, ExpectedException(typeof(AssertFailedException))] public void IsEmptyFailsOnString() { - Assert.That.IsEmpty("Hi!"); + StringAssert.That.IsEmpty("Hi!"); } [TestMethod] @@ -82,7 +82,7 @@ public void IsNotEmpty() { "array", array } }; - Assert.That.IsNotEmpty("Hi!", "Failed on String"); + StringAssert.That.IsNotEmpty("Hi!", "Failed on String"); CollectionAssert.That.IsNotEmpty(array, "Failed on Array"); CollectionAssert.That.IsNotEmpty(list, "Failed on ArrayList"); CollectionAssert.That.IsNotEmpty(hash, "Failed on Hashtable"); @@ -109,7 +109,7 @@ public void IsNotEmptyFailsOnEmptyHashTable() [TestMethod, ExpectedException(typeof(AssertFailedException))] public void IsNotEmptyFailsOnEmptyString() { - Assert.That.IsNotEmpty(""); + StringAssert.That.IsNotEmpty(""); } } } \ No newline at end of file