Added Exception.Throws overload to take multiple possible messages to match
This way tests can pass in multiple possible string matches which the runtime may use as a message depending on the given platform (e.g.: MS-Runtime vs Mono)
This commit is contained in:
@@ -193,5 +193,24 @@ namespace Newtonsoft.Json.Tests
|
||||
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Throws<TException>(Action action, params string[] possibleMessages)
|
||||
where TException : Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
|
||||
Assert.Fail("Exception of type {0} expected; got none exception", typeof(TException).Name);
|
||||
}
|
||||
catch (TException ex)
|
||||
{
|
||||
Assert.Contains (ex.Message, possibleMessages, "Unexpected exception message." + Environment.NewLine + "Expected One of: " + string.Join (Environment.NewLine, possibleMessages) + Environment.NewLine + "Got: " + ex.Message + Environment.NewLine + Environment.NewLine + ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user