Skip to content

Commit cdb5e0f

Browse files
committed
Add tests for remaining members marked with ExcludeFromCodeCoverageInternalAttribute
1 parent 34c82db commit cdb5e0f

File tree

7 files changed

+133
-19
lines changed

7 files changed

+133
-19
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonArrayTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace StyleCop.Analyzers.Test.LightJson
77
{
88
using System;
9+
using System.Diagnostics;
10+
using System.Reflection;
911
using global::LightJson;
1012
using Xunit;
1113
using IEnumerable = System.Collections.IEnumerable;
@@ -141,5 +143,22 @@ public void TestEnumerators()
141143
}
142144
}
143145
}
146+
147+
[Fact]
148+
public void TestDebugView()
149+
{
150+
var obj = new JsonArray("a", "b", "c");
151+
var proxyAttribute = obj.GetType().GetCustomAttribute<DebuggerTypeProxyAttribute>();
152+
Assert.NotNull(proxyAttribute);
153+
154+
var proxyType = Type.GetType(proxyAttribute.ProxyTypeName);
155+
Assert.NotNull(proxyType);
156+
157+
var proxy = Activator.CreateInstance(proxyType, obj);
158+
Assert.NotNull(proxy);
159+
160+
var items = proxyType.GetTypeInfo().GetDeclaredProperty("Items").GetValue(proxy);
161+
Assert.IsType<JsonValue[]>(items);
162+
}
144163
}
145164
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonObjectTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace StyleCop.Analyzers.Test.LightJson
77
{
88
using System;
99
using System.Collections.Generic;
10+
using System.Diagnostics;
11+
using System.Reflection;
1012
using global::LightJson;
1113
using Xunit;
1214
using IEnumerable = System.Collections.IEnumerable;
@@ -109,6 +111,35 @@ public void TestRename()
109111
Assert.Same(value, obj["y"].AsString);
110112
}
111113

114+
[Fact]
115+
public void TestDebugView()
116+
{
117+
var obj = new JsonObject
118+
{
119+
["x"] = "string value",
120+
["y"] = new JsonObject(),
121+
["z"] = new JsonArray("a", "b", "c"),
122+
};
123+
var proxyAttribute = obj.GetType().GetCustomAttribute<DebuggerTypeProxyAttribute>();
124+
Assert.NotNull(proxyAttribute);
125+
126+
var proxyType = Type.GetType(proxyAttribute.ProxyTypeName);
127+
Assert.NotNull(proxyType);
128+
129+
var proxy = Activator.CreateInstance(proxyType, obj);
130+
Assert.NotNull(proxy);
131+
132+
var keys = proxyType.GetTypeInfo().GetDeclaredProperty("Keys").GetValue(proxy);
133+
var keysArray = Assert.IsAssignableFrom<Array>(keys);
134+
135+
Assert.NotEmpty(keysArray);
136+
foreach (var key in keysArray)
137+
{
138+
var view = key.GetType().GetTypeInfo().GetDeclaredProperty("View").GetValue(key);
139+
Assert.NotNull(view);
140+
}
141+
}
142+
112143
#pragma warning disable IDE0060 // Remove unused parameter
113144
private static Type StaticType<T>(T value) => typeof(T);
114145
#pragma warning restore IDE0060 // Remove unused parameter

StyleCop.Analyzers/StyleCop.Analyzers.Test/LightJson/JsonValueTests.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace StyleCop.Analyzers.Test.LightJson
77
{
88
using System;
9+
using System.Diagnostics;
10+
using System.Reflection;
911
using global::LightJson;
1012
using global::LightJson.Serialization;
1113
using StyleCop.Analyzers.Test.Helpers;
@@ -351,5 +353,86 @@ public void TestParse()
351353
Assert.ThrowsAny<JsonParseException>(() => JsonValue.Parse(string.Empty));
352354
Assert.ThrowsAny<JsonParseException>(() => JsonValue.Parse("{"));
353355
}
356+
357+
[Fact]
358+
public void TestDebugViewOfObject()
359+
{
360+
var obj = JsonValue.Parse("{}");
361+
var proxyAttribute = obj.GetType().GetCustomAttribute<DebuggerTypeProxyAttribute>();
362+
Assert.NotNull(proxyAttribute);
363+
364+
var proxyType = Type.GetType(proxyAttribute.ProxyTypeName);
365+
Assert.NotNull(proxyType);
366+
367+
var proxy = Activator.CreateInstance(proxyType, obj);
368+
Assert.NotNull(proxy);
369+
370+
var objectView = proxyType.GetTypeInfo().GetDeclaredProperty("ObjectView").GetValue(proxy);
371+
var arrayView = proxyType.GetTypeInfo().GetDeclaredProperty("ArrayView").GetValue(proxy);
372+
var jsonValueType = proxyType.GetTypeInfo().GetDeclaredProperty("Type").GetValue(proxy);
373+
var value = proxyType.GetTypeInfo().GetDeclaredProperty("Value").GetValue(proxy);
374+
375+
Assert.Same(obj.AsJsonObject, objectView);
376+
Assert.Same(obj.AsJsonArray, arrayView);
377+
378+
Assert.IsType<JsonObject>(objectView);
379+
Assert.Null(arrayView);
380+
Assert.Equal(obj.Type, jsonValueType);
381+
Assert.Same(obj.AsJsonObject, value);
382+
}
383+
384+
[Fact]
385+
public void TestDebugViewOfArray()
386+
{
387+
var obj = JsonValue.Parse("[]");
388+
var proxyAttribute = obj.GetType().GetCustomAttribute<DebuggerTypeProxyAttribute>();
389+
Assert.NotNull(proxyAttribute);
390+
391+
var proxyType = Type.GetType(proxyAttribute.ProxyTypeName);
392+
Assert.NotNull(proxyType);
393+
394+
var proxy = Activator.CreateInstance(proxyType, obj);
395+
Assert.NotNull(proxy);
396+
397+
var objectView = proxyType.GetTypeInfo().GetDeclaredProperty("ObjectView").GetValue(proxy);
398+
var arrayView = proxyType.GetTypeInfo().GetDeclaredProperty("ArrayView").GetValue(proxy);
399+
var jsonValueType = proxyType.GetTypeInfo().GetDeclaredProperty("Type").GetValue(proxy);
400+
var value = proxyType.GetTypeInfo().GetDeclaredProperty("Value").GetValue(proxy);
401+
402+
Assert.Same(obj.AsJsonObject, objectView);
403+
Assert.Same(obj.AsJsonArray, arrayView);
404+
405+
Assert.Null(objectView);
406+
Assert.IsType<JsonArray>(arrayView);
407+
Assert.Equal(obj.Type, jsonValueType);
408+
Assert.Same(obj.AsJsonArray, value);
409+
}
410+
411+
[Fact]
412+
public void TestDebugViewOfBoolean()
413+
{
414+
var obj = JsonValue.Parse("true");
415+
var proxyAttribute = obj.GetType().GetCustomAttribute<DebuggerTypeProxyAttribute>();
416+
Assert.NotNull(proxyAttribute);
417+
418+
var proxyType = Type.GetType(proxyAttribute.ProxyTypeName);
419+
Assert.NotNull(proxyType);
420+
421+
var proxy = Activator.CreateInstance(proxyType, obj);
422+
Assert.NotNull(proxy);
423+
424+
var objectView = proxyType.GetTypeInfo().GetDeclaredProperty("ObjectView").GetValue(proxy);
425+
var arrayView = proxyType.GetTypeInfo().GetDeclaredProperty("ArrayView").GetValue(proxy);
426+
var jsonValueType = proxyType.GetTypeInfo().GetDeclaredProperty("Type").GetValue(proxy);
427+
var value = proxyType.GetTypeInfo().GetDeclaredProperty("Value").GetValue(proxy);
428+
429+
Assert.Same(obj.AsJsonObject, objectView);
430+
Assert.Same(obj.AsJsonArray, arrayView);
431+
432+
Assert.Null(objectView);
433+
Assert.Null(arrayView);
434+
Assert.Equal(obj.Type, jsonValueType);
435+
Assert.Equal(obj, value);
436+
}
354437
}
355438
}

StyleCop.Analyzers/StyleCop.Analyzers/ExcludeFromCodeCoverageInternalAttribute.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonArray.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
166166
return this.GetEnumerator();
167167
}
168168

169-
[ExcludeFromCodeCoverageInternal]
170169
private class JsonArrayDebugView
171170
{
172171
private readonly JsonArray jsonArray;

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonObject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
188188
return this.GetEnumerator();
189189
}
190190

191-
[ExcludeFromCodeCoverageInternal]
192191
private class JsonObjectDebugView
193192
{
194193
private readonly JsonObject jsonObject;

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,6 @@ public override int GetHashCode()
846846
}
847847
}
848848

849-
[ExcludeFromCodeCoverageInternal]
850849
private class JsonValueDebugView
851850
{
852851
private readonly JsonValue jsonValue;

0 commit comments

Comments
 (0)