Skip to content

Commit fa81d5f

Browse files
committed
Test coverage for .NetStandard polyfills
1 parent 47d84ca commit fa81d5f

File tree

8 files changed

+233
-1
lines changed

8 files changed

+233
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("ReadableExpressions.UnitTests.Polyfills")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("afcbb04d-9bf9-45c7-949e-95c67c9e4680")]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>afcbb04d-9bf9-45c7-949e-95c67c9e4680</ProjectGuid>
10+
<RootNamespace>AgileObjects.ReadableExpressions.UnitTests.Polyfills</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
19+
</Project>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
namespace AgileObjects.ReadableExpressions.UnitTests.Polyfills
2+
{
3+
using System.Linq;
4+
using System.Reflection;
5+
using Extensions;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
[TestClass]
9+
public class WhenCheckingTypeData
10+
{
11+
[TestMethod]
12+
public void ShouldFlagAParamsArray()
13+
{
14+
var paramsParameter = typeof(TestHelper)
15+
.GetMethod("DoParamsStuff")
16+
.GetParameters()
17+
.First();
18+
19+
20+
Assert.IsTrue(paramsParameter.IsParamsArray());
21+
}
22+
23+
[TestMethod]
24+
public void ShouldFlagANonParamsArray()
25+
{
26+
var paramsParameter = typeof(TestHelper)
27+
.GetMethod("DoNonParamsStuff")
28+
.GetParameters()
29+
.First();
30+
31+
32+
Assert.IsFalse(paramsParameter.IsParamsArray());
33+
}
34+
35+
[TestMethod]
36+
public void ShouldFindATypeAttribute()
37+
{
38+
Assert.IsTrue(typeof(WhenCheckingTypeData).HasAttribute<TestClassAttribute>());
39+
}
40+
41+
[TestMethod]
42+
public void ShouldNotFindATypeAttribute()
43+
{
44+
Assert.IsFalse(typeof(TestHelper).HasAttribute<TestClassAttribute>());
45+
}
46+
47+
[TestMethod]
48+
public void ShouldFindANonPublicInstanceMethod()
49+
{
50+
var method = typeof(TestHelper).GetNonPublicInstanceMethods().FirstOrDefault();
51+
52+
Assert.IsNotNull(method);
53+
Assert.AreEqual("NonPublicMethod", method.Name);
54+
}
55+
56+
[TestMethod]
57+
public void ShouldFlagAnAnonymousType()
58+
{
59+
var anon = new { Value = "Value!" };
60+
61+
Assert.IsTrue(anon.GetType().IsAnonymous());
62+
}
63+
64+
[TestMethod]
65+
public void ShouldFlagANonAnonymousType()
66+
{
67+
Assert.IsFalse(typeof(IOrderedEnumerable<int>).IsAnonymous());
68+
}
69+
70+
private class TestHelper
71+
{
72+
// ReSharper disable once UnusedMember.Local
73+
// ReSharper disable once UnusedParameter.Local
74+
public void DoParamsStuff(params int[] ints)
75+
{
76+
}
77+
78+
// ReSharper disable once UnusedMember.Local
79+
// ReSharper disable once UnusedParameter.Local
80+
public void DoNonParamsStuff(int[] ints)
81+
{
82+
83+
}
84+
85+
// ReSharper disable once UnusedMember.Local
86+
internal void NonPublicMethod()
87+
{
88+
}
89+
}
90+
}
91+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace AgileObjects.ReadableExpressions.UnitTests.Polyfills
2+
{
3+
using System;
4+
using System.Data;
5+
using System.Reflection;
6+
using Extensions;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
9+
[TestClass]
10+
public class WhenRetrievingTypeCodes
11+
{
12+
[TestMethod]
13+
public void ShouldReturnEmpty()
14+
{
15+
var typeCode = default(Type).GetTypeCode();
16+
17+
Assert.AreEqual(NetStandardTypeCode.Empty, typeCode);
18+
}
19+
20+
[TestMethod]
21+
public void ShouldReturnDbNull()
22+
{
23+
var typeCode = typeof(DBNull).GetTypeCode();
24+
25+
Assert.AreEqual(NetStandardTypeCode.DBNull, typeCode);
26+
}
27+
28+
[TestMethod]
29+
public void ShouldReturnBoolean()
30+
{
31+
var typeCode = typeof(bool).GetTypeCode();
32+
33+
Assert.AreEqual(NetStandardTypeCode.Boolean, typeCode);
34+
}
35+
36+
[TestMethod]
37+
public void ShouldReturnString()
38+
{
39+
var typeCode = typeof(string).GetTypeCode();
40+
41+
Assert.AreEqual(NetStandardTypeCode.String, typeCode);
42+
}
43+
44+
[TestMethod]
45+
public void ShouldReturnUnderlyingTypeForAnEnum()
46+
{
47+
var typeCode = typeof(BindingFlags).GetTypeCode();
48+
49+
Assert.AreEqual(NetStandardTypeCode.Int32, typeCode);
50+
}
51+
52+
[TestMethod]
53+
public void ShouldFallbackToObject()
54+
{
55+
var typeCode = typeof(IDataReader).GetTypeCode();
56+
57+
Assert.AreEqual(NetStandardTypeCode.Object, typeCode);
58+
}
59+
}
60+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": "1.7.0-*",
3+
"buildOptions": {
4+
"warningsAsErrors": true,
5+
"outputName": "AgileObjects.ReadableExpressions.UnitTests.Polyfills"
6+
},
7+
"testRunner": "mstest",
8+
"frameworks": {
9+
"netcoreapp1.0": {
10+
"imports": [
11+
"dnxcore50",
12+
"portable-net45+win8"
13+
],
14+
"dependencies": {
15+
"Microsoft.NETCore.App": {
16+
"version": "1.0.1",
17+
"type": "platform"
18+
},
19+
"dotnet-test-mstest": "1.1.1-preview",
20+
"MSTest.TestFramework": "1.0.4-preview",
21+
"System.Data.Common": "4.1.0",
22+
"System.Reflection.TypeExtensions": "4.1.0",
23+
"ReadableExpressions": {
24+
"target": "project"
25+
}
26+
},
27+
"buildOptions": {
28+
"define": [ "NET_STANDARD" ]
29+
}
30+
}
31+
}
32+
}

ReadableExpressions.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{884A1D4E-7B9C-4411-A1E5-50B30F243FB1}"
99
ProjectSection(SolutionItems) = preProject
1010
CommonAssemblyInfo.cs = CommonAssemblyInfo.cs
11+
global.json = global.json
1112
NuGetPack.bat = NuGetPack.bat
1213
README.md = README.md
1314
VersionInfo.cs = VersionInfo.cs
@@ -33,6 +34,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ReadableExpressions", "Read
3334
EndProject
3435
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadableExpressions.Net40", "ReadableExpressions.Net40\ReadableExpressions.Net40.csproj", "{7A33DA5B-5DEE-42CB-A354-A77766B635BA}"
3536
EndProject
37+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ReadableExpressions.UnitTests.Polyfills", "ReadableExpressions.UnitTests.Polyfills\ReadableExpressions.UnitTests.Polyfills.xproj", "{AFCBB04D-9BF9-45C7-949E-95C67C9E4680}"
38+
EndProject
3639
Global
3740
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3841
Debug|Any CPU = Debug|Any CPU
@@ -72,6 +75,10 @@ Global
7275
{7A33DA5B-5DEE-42CB-A354-A77766B635BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
7376
{7A33DA5B-5DEE-42CB-A354-A77766B635BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
7477
{7A33DA5B-5DEE-42CB-A354-A77766B635BA}.Release|Any CPU.Build.0 = Release|Any CPU
78+
{AFCBB04D-9BF9-45C7-949E-95C67C9E4680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
79+
{AFCBB04D-9BF9-45C7-949E-95C67C9E4680}.Debug|Any CPU.Build.0 = Debug|Any CPU
80+
{AFCBB04D-9BF9-45C7-949E-95C67C9E4680}.Release|Any CPU.ActiveCfg = Release|Any CPU
81+
{AFCBB04D-9BF9-45C7-949E-95C67C9E4680}.Release|Any CPU.Build.0 = Release|Any CPU
7582
EndGlobalSection
7683
GlobalSection(SolutionProperties) = preSolution
7784
HideSolutionNode = FALSE

ReadableExpressions/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
[assembly: AssemblyTitle("AgileObjects.ReadableExpressions")]
55
[assembly: AssemblyDescription("Provides an extension method to produce a readable string version of an expression tree.")]
66

7-
[assembly: InternalsVisibleTo("AgileObjects.AgileMapper")]
7+
[assembly: InternalsVisibleTo("AgileObjects.AgileMapper")]
8+
[assembly: InternalsVisibleTo("AgileObjects.ReadableExpressions.UnitTests.Polyfills")]

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"projects": [ "ReadableExpressions" ]
3+
}

0 commit comments

Comments
 (0)