From 32f326e46a74da960c5d12fa610fbe842eebd25a Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 8 May 2013 20:26:32 +1200 Subject: [PATCH] -Fixed tests --- Src/Newtonsoft.Json.Tests/JsonConvertTest.cs | 29 ++++--- .../Serialization/ContractResolverTests.cs | 83 ------------------- 2 files changed, 18 insertions(+), 94 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index 5216365b5..d5b5f03cc 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -80,13 +80,15 @@ public void DefaultSettings() [Test] public void DefaultSettings_Example() { - JsonConvert.DefaultSettings = () => new JsonSerializerSettings + try + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Formatting = Formatting.Indented, ContractResolver = new CamelCasePropertyNamesContractResolver() }; - Employee e = new Employee + Employee e = new Employee { FirstName = "Eric", LastName = "Example", @@ -95,22 +97,27 @@ public void DefaultSettings_Example() JobTitle = "Web Dude" }; - string json = JsonConvert.SerializeObject(e); - // { - // "firstName": "Eric", - // "lastName": "Example", - // "birthDate": "1980-04-20T00:00:00Z", - // "department": "IT", - // "jobTitle": "Web Dude" - // } + string json = JsonConvert.SerializeObject(e); + // { + // "firstName": "Eric", + // "lastName": "Example", + // "birthDate": "1980-04-20T00:00:00Z", + // "department": "IT", + // "jobTitle": "Web Dude" + // } - Assert.AreEqual(@"{ + Assert.AreEqual(@"{ ""firstName"": ""Eric"", ""lastName"": ""Example"", ""birthDate"": ""1980-04-20T00:00:00Z"", ""department"": ""IT"", ""jobTitle"": ""Web Dude"" }", json); + } + finally + { + JsonConvert.DefaultSettings = null; + } } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs index 22c4ee69a..0ebdeb8a8 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs @@ -258,88 +258,5 @@ public void SerializeCompilerGeneratedMembers() }", includeCompilerGeneratedJson); } #endif - - //public class NullAsStringValueProvider : IValueProvider - //{ - // private readonly ReflectionValueProvider _internalProvider; - - // public NullAsStringValueProvider(MemberInfo memberInfo) - // { - // _internalProvider = new ReflectionValueProvider(memberInfo); - // } - - // public void SetValue(object target, object value) - // { - // _internalProvider.SetValue(target, value); - // } - - // public object GetValue(object target) - // { - // object value = _internalProvider.GetValue(target); - - // if (value == null) - // return string.Empty; - - // return value; - // } - //} - - //public class NullAsStringContractResolver : DefaultContractResolver - //{ - // protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) - // { - // JsonProperty property = base.CreateProperty(member, memberSerialization); - - // //property.ValueProvider = new NullAsStringValueProvider(member); - // //property..Converter = new NullAsStringJsonConverter(); - - // return property; - // } - - // protected override JsonPrimitiveContract CreatePrimitiveContract(Type objectType) - // { - // return base.CreatePrimitiveContract(objectType); - // } - //} - - //public class NullAsStringTestClass - //{ - // public int? Integer { get; set; } - // public DateTime? DateTime { get; set; } - //} - - //public class NullAsStringJsonConverter : JsonConverter - //{ - // public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - // { - // if (value == null) - // writer.WriteValue(string.Empty); - // } - - // public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - // { - // throw new NotImplementedException(); - // } - - // public override bool CanRead - // { - // get { return false; } - // } - - // public override bool CanConvert(Type objectType) - // { - // return ReflectionUtils.IsNullableType(objectType); - // } - //} - - //[Test] - //public void sdfsdf() - //{ - // string json = JsonConvert.SerializeObject( - // new NullAsStringTestClass(), - // new JsonSerializerSettings { ContractResolver = new NullAsStringContractResolver()}); - - // Console.WriteLine(json); - //} } } \ No newline at end of file