From fb7fb9c4e615b1022dab6c863b5dcf1d9388b272 Mon Sep 17 00:00:00 2001 From: Lyubomir Rusev Date: Fri, 9 Mar 2018 15:50:26 +0200 Subject: [PATCH] Extend Just Mock assert wrapper to handle XUnit Assertions. --- Telerik.JustMock.Tests/Assert.cs | 48 ++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Telerik.JustMock.Tests/Assert.cs b/Telerik.JustMock.Tests/Assert.cs index ba08573..83bd880 100644 --- a/Telerik.JustMock.Tests/Assert.cs +++ b/Telerik.JustMock.Tests/Assert.cs @@ -21,12 +21,15 @@ using System; #if NUNIT using FrameworkAssert = NUnit.Framework.Assert; #elif XUNIT +using FrameworkAssert = Xunit.Assert; #elif PORTABLE using FrameworkAssert = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Assert; #else using FrameworkAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; #endif + + namespace Telerik.JustMock.Tests { /// @@ -63,51 +66,90 @@ namespace Telerik.JustMock.Tests #endif catch (Exception ex) { +#if XUNIT + FrameworkAssert.True(false,String.Format("Wrong exception type thrown. Expected {0}, got {1}.", typeof(T), ex.GetType())); +#else FrameworkAssert.Fail(String.Format("Wrong exception type thrown. Expected {0}, got {1}.", typeof(T), ex.GetType())); +#endif } - +#if XUNIT + FrameworkAssert.True(false, String.Format("No Expected {0} was thrown", typeof(T).FullName)); +#else FrameworkAssert.Fail(String.Format("No Expected {0} was thrown", typeof(T).FullName)); +#endif throw new Exception(); } - + public static void NotNull(object value) { +#if XUNIT + FrameworkAssert.NotNull(value); +#else FrameworkAssert.IsNotNull(value); +#endif } public static void Null(object value) { +#if XUNIT + FrameworkAssert.Null(value); +#else FrameworkAssert.IsNull(value); +#endif } public static void Equal(T expected, T actual) { +#if XUNIT + FrameworkAssert.Equal(expected, actual); +#else FrameworkAssert.AreEqual(expected, actual); +#endif } public static void NotEqual(T notExpected, T actual) { +#if XUNIT + FrameworkAssert.NotEqual(notExpected, actual); +#else FrameworkAssert.AreNotEqual(notExpected, actual); +#endif } public static void True(bool condition) { +#if XUNIT + FrameworkAssert.True(condition); +#else FrameworkAssert.IsTrue(condition); +#endif } public static void False(bool condition) { +#if XUNIT + FrameworkAssert.False(condition); +#else FrameworkAssert.IsFalse(condition); +#endif } public static void Same(object expected, object actual) { +#if XUNIT + FrameworkAssert.Same(expected, actual); +#else FrameworkAssert.AreSame(expected, actual); +#endif } public static void NotSame(object expected, object actual) { +#if XUNIT + FrameworkAssert.NotSame(expected, actual); +#else FrameworkAssert.AreNotSame(expected, actual); +#endif } } -} +} \ No newline at end of file