2
// Copyright (c) 2007 James Newton-King
4
// Permission is hereby granted, free of charge, to any person
5
// obtaining a copy of this software and associated documentation
6
// files (the "Software"), to deal in the Software without
7
// restriction, including without limitation the rights to use,
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following
13
// The above copyright notice and this permission notice shall be
14
// included in all copies or substantial portions of the Software.
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
// OTHER DEALINGS IN THE SOFTWARE.
27
using System.Collections.Generic;
28
using System.Globalization;
31
using Newtonsoft.Json.Serialization;
32
using Newtonsoft.Json.Utilities.LinqBridge;
35
using System.Threading;
37
using NUnit.Framework;
39
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
40
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
41
using TestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
43
using Newtonsoft.Json.Utilities;
44
using System.Collections;
46
using Newtonsoft.Json.Utilities.LinqBridge;
51
namespace Newtonsoft.Json.Tests
54
public abstract class TestFixtureBase
56
protected string GetOffset(DateTime d, DateFormatHandling dateFormatHandling)
58
StringWriter sw = new StringWriter();
59
JsonConvert.WriteDateTimeOffset(sw, DateTime.SpecifyKind(d, DateTimeKind.Local).GetUtcOffset(), dateFormatHandling);
67
protected void TestSetup()
69
//CultureInfo turkey = CultureInfo.CreateSpecificCulture("tr");
70
//Thread.CurrentThread.CurrentCulture = turkey;
71
//Thread.CurrentThread.CurrentUICulture = turkey;
74
protected void WriteEscapedJson(string json)
76
Console.WriteLine(EscapeJson(json));
79
protected string EscapeJson(string json)
81
return @"@""" + json.Replace(@"""", @"""""") + @"""";
87
public static class Console
89
public static void WriteLine(params object[] args)
95
public static class CustomAssert
97
public static void IsInstanceOfType(Type t, object instance)
100
Assert.IsInstanceOfType(t, instance);
102
if (!instance.GetType().IsAssignableFrom(t))
103
throw new Exception("Blah");
107
public static void Contains(IList collection, object value)
110
Assert.Contains(value, collection);
112
if (!collection.Cast<object>().Any(i => i.Equals(value)))
113
throw new Exception("Value not found in collection.");
118
public static class ExceptionAssert
120
public static void Throws<TException>(string message, Action action)
121
where TException : Exception
127
Assert.Fail("Exception of type {0} expected; got none exception", typeof(TException).Name);
129
catch (TException ex)
132
Assert.AreEqual(message, ex.Message, "Unexpected exception message." + Environment.NewLine + "Expected: " + message + Environment.NewLine + "Got: " + ex.Message);
136
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);