Skip to content

Commit

Permalink
-Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed May 8, 2013
1 parent f4d5ace commit 32f326e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 94 deletions.
29 changes: 18 additions & 11 deletions Src/Newtonsoft.Json.Tests/JsonConvertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]
Expand Down
83 changes: 0 additions & 83 deletions Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//}
}
}

0 comments on commit 32f326e

Please sign in to comment.