This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 20f03a04028a187f0c99b80cb88dedb29af6c3b4 Author: Shad Storhaug <[email protected]> AuthorDate: Tue Jun 30 12:47:52 2020 +0700 Lucene.Net.TestFramework: Added additional overloads of Assert.Throws to supply messages --- .../Support/TestFramework/Assert.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Lucene.Net.TestFramework.NUnit/Support/TestFramework/Assert.cs b/src/Lucene.Net.TestFramework.NUnit/Support/TestFramework/Assert.cs index 9e01972..08ed9cb 100644 --- a/src/Lucene.Net.TestFramework.NUnit/Support/TestFramework/Assert.cs +++ b/src/Lucene.Net.TestFramework.NUnit/Support/TestFramework/Assert.cs @@ -848,6 +848,11 @@ namespace Lucene.Net.TestFramework _NUnit.Assert.Greater(arg1, arg2); } + public static Exception Throws<TException>(Action action, string message, params string[] args) + { + return Throws(typeof(TException), action, message, args); + } + public static Exception Throws<TException>(Action action) { return Throws(typeof(TException), action); @@ -858,6 +863,11 @@ namespace Lucene.Net.TestFramework return _NUnit.Assert.Throws(expectedExceptionType, () => action()); } + public static Exception Throws(Type expectedExceptionType, Action action, string message, params string[] args) + { + return _NUnit.Assert.Throws(expectedExceptionType, () => action(), message, args); + } + public static Exception ThrowsFileAlreadyExistsException(string filePath, Action action) { var messagePrefix = $"Expected: IOException indicating file not found\nBut was:"; @@ -888,7 +898,6 @@ namespace Lucene.Net.TestFramework public static Exception ThrowsAnyOf(IEnumerable<Type> expectedExceptionTypes, Action action) { - var messagePrefix = $"Expected one of: {Collections.ToString(expectedExceptionTypes.Select(ex => ex.FullName).ToArray())}\nBut was:"; Exception exception = null; try { @@ -903,7 +912,7 @@ namespace Lucene.Net.TestFramework return ex; // Success } string exString = exception == null ? "<null>" : exception.GetType().FullName; - throw new _NUnit.AssertionException($"{messagePrefix} {exString}"); + throw new _NUnit.AssertionException($"Expected one of: {Collections.ToString(expectedExceptionTypes.Select(ex => ex.FullName).ToArray())}\nBut was: {exString}"); } } }
