diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index a92affb6..a4cf9e24 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -791,10 +791,12 @@ third line", jsonTextReader.Value); [Test] public void NullTextReader() { - ExceptionAssert.Throws( - @"Value cannot be null. -Parameter name: reader", - () => { new JsonTextReader(null); }); + ExceptionAssert.Throws ( + () => { new JsonTextReader (null); }, + new string[] { + "Value cannot be null." + Environment.NewLine + "Parameter name: reader", + "Argument cannot be null." + Environment.NewLine + "Parameter name: reader" // Mono + }); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/ImmutableCollectionsTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/ImmutableCollectionsTests.cs index de83bd17..588cb515 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/ImmutableCollectionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/ImmutableCollectionsTests.cs @@ -141,8 +141,12 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void SerializeDefaultArray() { - ExceptionAssert.Throws("Object reference not set to an instance of an object.", () => - JsonConvert.SerializeObject(default(ImmutableArray), Formatting.Indented)); + ExceptionAssert.Throws( + () => JsonConvert.SerializeObject(default(ImmutableArray), Formatting.Indented), + new [] { + "Object reference not set to an instance of an object.", + "Object reference not set to an instance of an object" // mono + }); } #endregion diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 68c52478..f9365179 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -2975,8 +2975,11 @@ Path '', line 1, position 1.", string json = @"[]"; ExceptionAssert.Throws( - @"Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.", - () => { JsonConvert.DeserializeObject(json); }); + () => { JsonConvert.DeserializeObject(json); }, + new [] { + "Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.", + "Cannot cast from source type to destination type." // mono + }); } [Test] @@ -6304,18 +6307,22 @@ To fix this error either change the environment to be fully trusted, change the public void DeserializeDoubleFromNullString() { ExceptionAssert.Throws( - @"Value cannot be null. -Parameter name: value", - () => { JsonConvert.DeserializeObject(null); }); + () => { JsonConvert.DeserializeObject(null); }, + new [] { + "Value cannot be null." + Environment.NewLine + "Parameter name: value", + "Argument cannot be null." + Environment.NewLine + "Parameter name: value" // mono + }); } [Test] public void DeserializeFromNullString() { ExceptionAssert.Throws( - @"Value cannot be null. -Parameter name: value", - () => { JsonConvert.DeserializeObject(null); }); + () => { JsonConvert.DeserializeObject(null); }, + new [] { + "Value cannot be null." + Environment.NewLine + "Parameter name: value", + "Argument cannot be null." + Environment.NewLine + "Parameter name: value" // mono + }); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs b/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs index 9c5a651c..e5a520ec 100644 --- a/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs +++ b/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs @@ -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(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); + } + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs index 7db83186..9775c32c 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs @@ -107,13 +107,15 @@ namespace Newtonsoft.Json.Tests.Utilities [Test] public void DefaultConstructor_Abstract() { - ExceptionAssert.Throws("Cannot create an abstract class.", - () => - { + ExceptionAssert.Throws( + () => { Func create = ExpressionReflectionDelegateFactory.Instance.CreateDefaultConstructor(typeof(Type)); create(); - }); + }, new [] { + "Cannot create an abstract class.", + "Cannot create an abstract class 'System.Type'." // mono + }); } [Test] @@ -277,24 +279,26 @@ namespace Newtonsoft.Json.Tests.Utilities [Test] public void CreateGetWithBadObjectTarget() { - ExceptionAssert.Throws("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.", - () => - { - Person p = new Person(); - p.Name = "Hi"; + ExceptionAssert.Throws( + () => { + Person p = new Person(); + p.Name = "Hi"; - Func setter = ExpressionReflectionDelegateFactory.Instance.CreateGet(typeof(Movie).GetProperty("Name")); + Func setter = ExpressionReflectionDelegateFactory.Instance.CreateGet(typeof(Movie).GetProperty("Name")); - setter(p); - }); + setter(p); + }, + new [] { + "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.", + "Cannot cast from source type to destination type." // mono + }); } [Test] public void CreateSetWithBadObjectTarget() { - ExceptionAssert.Throws("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.", - () => - { + ExceptionAssert.Throws( + () => { Person p = new Person(); Movie m = new Movie(); @@ -307,21 +311,28 @@ namespace Newtonsoft.Json.Tests.Utilities setter(p, "Hi"); Assert.AreEqual(p.Name, "Hi"); - }); + }, + new [] { + "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.", + "Cannot cast from source type to destination type." // mono + + }); } [Test] public void CreateSetWithBadObjectValue() { - ExceptionAssert.Throws("Unable to cast object of type 'System.Version' to type 'System.String'.", - () => - { + ExceptionAssert.Throws( + () => { Movie m = new Movie(); Action setter = ExpressionReflectionDelegateFactory.Instance.CreateSet(typeof(Movie).GetProperty("Name")); setter(m, new Version("1.1.1.1")); - }); + }, new [] { + "Unable to cast object of type 'System.Version' to type 'System.String'.", + "Cannot cast from source type to destination type." //mono + }); } [Test]