Code Coverage Statistics for Source File
Newtonsoft.Json.Tests\Linq\ComponentModel\JPropertyDescriptorTests.cs
Symbol Coverage: 100.00% (22 of 22)
Branch Coverage: 100.00% (6 of 6)
Cyclomatic Complexity Avg: 1.00 Max:1
Code Lines: 22
Symbol Coverage Trend
View:
L | V | Source |
---|---|---|
1 |
#region License |
|
2 |
// Copyright (c) 2007 James Newton-King |
|
3 |
// |
|
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 |
|
11 |
// conditions: |
|
12 |
// |
|
13 |
// The above copyright notice and this permission notice shall be |
|
14 |
// included in all copies or substantial portions of the Software. |
|
15 |
// |
|
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. |
|
24 |
#endregion |
|
25 |
||
26 |
#if !SILVERLIGHT |
|
27 |
using System; |
|
28 |
using System.Collections.Generic; |
|
29 |
using System.Linq; |
|
30 |
using System.Text; |
|
31 |
using NUnit.Framework; |
|
32 |
using Newtonsoft.Json.Linq.ComponentModel; |
|
33 |
using Newtonsoft.Json.Linq; |
|
34 |
||
35 |
namespace Newtonsoft.Json.Tests.Linq.ComponentModel |
|
36 |
{ |
|
37 |
public class JPropertyDescriptorTests : TestFixtureBase |
|
38 |
{ |
|
39 |
[Test] |
|
40 |
public void GetValue() |
|
41 |
{ |
|
42 |
1 |
JObject o = JObject.Parse("{prop1:'12345!',prop2:[1,'two','III']}");
|
43 |
||
44 |
1 |
JPropertyDescriptor prop1 = new JPropertyDescriptor("prop1", typeof(string));
|
45 |
1 |
JPropertyDescriptor prop2 = new JPropertyDescriptor("prop2", typeof(JArray));
|
46 |
||
47 |
1 |
Assert.AreEqual("12345!", ((JValue) prop1.GetValue(o)).Value);
|
48 |
1 |
Assert.AreEqual(o["prop2"], prop2.GetValue(o));
|
49 |
1 |
}
|
50 |
||
51 |
[Test] |
|
52 |
public void SetValue() |
|
53 |
{ |
|
54 |
1 |
JObject o = JObject.Parse("{prop1:'12345!'}");
|
55 |
||
56 |
1 |
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
|
57 |
||
58 |
1 |
propertyDescriptor1.SetValue(o, "54321!");
|
59 |
||
60 |
1 |
Assert.AreEqual("54321!", (string)o["prop1"]);
|
61 |
1 |
}
|
62 |
||
63 |
[Test] |
|
64 |
public void ResetValue() |
|
65 |
{ |
|
66 |
1 |
JObject o = JObject.Parse("{prop1:'12345!'}");
|
67 |
||
68 |
1 |
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
|
69 |
1 |
propertyDescriptor1.ResetValue(o);
|
70 |
||
71 |
1 |
Assert.AreEqual("12345!", (string)o["prop1"]);
|
72 |
1 |
}
|
73 |
||
74 |
[Test] |
|
75 |
public void IsReadOnly() |
|
76 |
{ |
|
77 |
1 |
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
|
78 |
||
79 |
1 |
Assert.AreEqual(false, propertyDescriptor1.IsReadOnly);
|
80 |
1 |
}
|
81 |
||
82 |
[Test] |
|
83 |
public void PropertyType() |
|
84 |
{ |
|
85 |
1 |
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
|
86 |
||
87 |
1 |
Assert.AreEqual(typeof(string), propertyDescriptor1.PropertyType);
|
88 |
1 |
}
|
89 |
} |
|
90 |
} |
|
91 |
#endif |