-Fixed build
This commit is contained in:
@@ -53,142 +53,177 @@ namespace Newtonsoft.Json.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void DefaultSettings()
|
public void DefaultSettings()
|
||||||
{
|
{
|
||||||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
try
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented
|
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
||||||
};
|
{
|
||||||
|
Formatting = Formatting.Indented
|
||||||
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(new { test = new[] { 1, 2, 3 } });
|
string json = JsonConvert.SerializeObject(new { test = new[] { 1, 2, 3 } });
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""test"": [
|
""test"": [
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
]
|
]
|
||||||
}", json);
|
}", json);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
JsonConvert.DefaultSettings = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DefaultSettings_Override()
|
public void DefaultSettings_Override()
|
||||||
{
|
{
|
||||||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
try
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented
|
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
||||||
};
|
{
|
||||||
|
Formatting = Formatting.Indented
|
||||||
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(new { test = new[] { 1, 2, 3 } }, new JsonSerializerSettings
|
string json = JsonConvert.SerializeObject(new { test = new[] { 1, 2, 3 } }, new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Formatting = Formatting.None
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.AreEqual(@"{""test"":[1,2,3]}", json);
|
||||||
|
}
|
||||||
|
finally
|
||||||
{
|
{
|
||||||
Formatting = Formatting.None
|
JsonConvert.DefaultSettings = null;
|
||||||
});
|
}
|
||||||
|
|
||||||
Assert.AreEqual(@"{""test"":[1,2,3]}", json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DefaultSettings_Override_JsonConverterOrder()
|
public void DefaultSettings_Override_JsonConverterOrder()
|
||||||
{
|
{
|
||||||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
try
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
||||||
Converters = { new IsoDateTimeConverter { DateTimeFormat = "yyyy" } }
|
{
|
||||||
};
|
Formatting = Formatting.Indented,
|
||||||
|
Converters = { new IsoDateTimeConverter { DateTimeFormat = "yyyy" } }
|
||||||
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(new[] { new DateTime(2000, 12, 12, 4, 2, 4, DateTimeKind.Utc) }, new JsonSerializerSettings
|
string json = JsonConvert.SerializeObject(new[] { new DateTime(2000, 12, 12, 4, 2, 4, DateTimeKind.Utc) }, new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Formatting = Formatting.None,
|
Formatting = Formatting.None,
|
||||||
Converters =
|
Converters =
|
||||||
{
|
{
|
||||||
// should take precedence
|
// should take precedence
|
||||||
new JavaScriptDateTimeConverter(),
|
new JavaScriptDateTimeConverter(),
|
||||||
new IsoDateTimeConverter { DateTimeFormat = "dd" }
|
new IsoDateTimeConverter { DateTimeFormat = "dd" }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.AreEqual(@"[new Date(976593724000)]", json);
|
Assert.AreEqual(@"[new Date(976593724000)]", json);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
JsonConvert.DefaultSettings = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DefaultSettings_Create()
|
public void DefaultSettings_Create()
|
||||||
{
|
{
|
||||||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
try
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented
|
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
||||||
};
|
{
|
||||||
|
Formatting = Formatting.Indented
|
||||||
|
};
|
||||||
|
|
||||||
IList<int> l = new List<int> { 1, 2, 3 };
|
IList<int> l = new List<int> { 1, 2, 3 };
|
||||||
|
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
JsonSerializer serializer = JsonSerializer.CreateDefault();
|
JsonSerializer serializer = JsonSerializer.CreateDefault();
|
||||||
serializer.Serialize(sw, l);
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
Assert.AreEqual(@"[
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
]", sw.ToString());
|
]", sw.ToString());
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
serializer.Formatting = Formatting.None;
|
serializer.Formatting = Formatting.None;
|
||||||
serializer.Serialize(sw, l);
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
Assert.AreEqual(@"[1,2,3]", sw.ToString());
|
Assert.AreEqual(@"[1,2,3]", sw.ToString());
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
serializer = new JsonSerializer();
|
serializer = new JsonSerializer();
|
||||||
serializer.Serialize(sw, l);
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
Assert.AreEqual(@"[1,2,3]", sw.ToString());
|
Assert.AreEqual(@"[1,2,3]", sw.ToString());
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
serializer = JsonSerializer.Create();
|
serializer = JsonSerializer.Create();
|
||||||
serializer.Serialize(sw, l);
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
Assert.AreEqual(@"[1,2,3]", sw.ToString());
|
Assert.AreEqual(@"[1,2,3]", sw.ToString());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
JsonConvert.DefaultSettings = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DefaultSettings_CreateWithSettings()
|
public void DefaultSettings_CreateWithSettings()
|
||||||
{
|
{
|
||||||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
try
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented
|
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
||||||
};
|
|
||||||
|
|
||||||
IList<int> l = new List<int> { 1, 2, 3 };
|
|
||||||
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
JsonSerializer serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings
|
|
||||||
{
|
{
|
||||||
Converters = { new IntConverter() }
|
Formatting = Formatting.Indented
|
||||||
});
|
};
|
||||||
serializer.Serialize(sw, l);
|
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
IList<int> l = new List<int> { 1, 2, 3 };
|
||||||
|
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
JsonSerializer serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Converters = { new IntConverter() }
|
||||||
|
});
|
||||||
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
|
Assert.AreEqual(@"[
|
||||||
2,
|
2,
|
||||||
4,
|
4,
|
||||||
6
|
6
|
||||||
]", sw.ToString());
|
]", sw.ToString());
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
serializer.Converters.Clear();
|
serializer.Converters.Clear();
|
||||||
serializer.Serialize(sw, l);
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
Assert.AreEqual(@"[
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
]", sw.ToString());
|
]", sw.ToString());
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
serializer = JsonSerializer.Create(new JsonSerializerSettings { Formatting = Formatting.Indented });
|
serializer = JsonSerializer.Create(new JsonSerializerSettings { Formatting = Formatting.Indented });
|
||||||
serializer.Serialize(sw, l);
|
serializer.Serialize(sw, l);
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
Assert.AreEqual(@"[
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
]", sw.ToString());
|
]", sw.ToString());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
JsonConvert.DefaultSettings = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IntConverter : JsonConverter
|
public class IntConverter : JsonConverter
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ using NUnit.Framework;
|
|||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
using TestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
using TestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
||||||
using Setup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitialize;
|
using SetUp = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute;
|
||||||
#endif
|
#endif
|
||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|||||||
Reference in New Issue
Block a user