Skip to content

Commit f6f7499

Browse files
committed
JsonString`1单元测试
1 parent 65b5c42 commit f6f7499

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

WebApiClient.Test/JsonStringTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Xunit;
2+
3+
namespace WebApiClient.Test
4+
{
5+
public class JsonStringTest
6+
{
7+
[Fact]
8+
public void Test_Tag_Object()
9+
{
10+
var formatter = WebApiClient.Defaults.JsonFormatter.Instance;
11+
var b = new JsonString<B>(new B());
12+
var json1 = formatter.Serialize(b, null);
13+
var json2 = formatter.Serialize(b.Value, null);
14+
var json3 = formatter.Serialize(json2, null);
15+
Assert.Equal(json1, json3);
16+
17+
var b2 = formatter.Deserialize(json3, typeof(JsonString<B>)) as JsonString<B>;
18+
Assert.Equal("name", b2.Value.Name);
19+
20+
21+
var a = new A();
22+
var aJson = formatter.Serialize(a, null);
23+
var a2 = formatter.Deserialize(aJson, typeof(A)) as A;
24+
25+
Assert.Equal(a.Age, a2.Age);
26+
Assert.Equal(a.B.Value.Name, a2.B.Value.Name);
27+
}
28+
29+
class A
30+
{
31+
public int Age { get; set; } = 10;
32+
33+
public JsonString<B> B { get; set; } = new B();
34+
}
35+
36+
class B
37+
{
38+
public string Name { get; set; } = "name";
39+
}
40+
}
41+
}

WebApiClient/Attributes/ParameterAttributes/BsonContentAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected sealed override void SetHttpContent(ApiActionContext context, ApiParam
5454
/// <returns></returns>
5555
protected virtual JsonSerializerSettings CreateSerializerSettings(FormatOptions options)
5656
{
57-
var setting= options.ToSerializerSettings(FormatScope.BsonFormat);
57+
var setting = options.ToSerializerSettings(FormatScope.BsonFormat);
5858
setting.Converters.Add(JsonStringConverter.Instance);
5959
return setting;
6060
}

WebApiClient/Defaults/AnnotationsContractResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
105105
property.NullValueHandling = NullValueHandling.Ignore;
106106
}
107107

108-
if (property.Ignored == false)
108+
if (annotations.IgnoreSerialized == true)
109109
{
110-
property.Ignored = annotations.IgnoreSerialized;
110+
property.Ignored = true;
111111
}
112112
return property;
113113
}

0 commit comments

Comments
 (0)