Skip to content

Commit e69a2e5

Browse files
authored
Merge pull request #34 from PowerAssert/DotNetCorePort
Dot net core port
2 parents 4cf7c77 + d83d1ad commit e69a2e5

File tree

10 files changed

+123
-118
lines changed

10 files changed

+123
-118
lines changed

PowerAssert.sln

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerAssert", "PowerAssert\PowerAssert.csproj", "{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}"
57
EndProject
68
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerAssertTests", "PowerAssertTests\PowerAssertTests.csproj", "{665FDD28-99EF-4038-9469-1B27F778BF1D}"
@@ -13,22 +15,32 @@ EndProject
1315
Global
1416
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1517
Debug|Any CPU = Debug|Any CPU
18+
Debug-Core|Any CPU = Debug-Core|Any CPU
1619
NuPackRelease|Any CPU = NuPackRelease|Any CPU
1720
Release|Any CPU = Release|Any CPU
21+
Release-Core|Any CPU = Release-Core|Any CPU
1822
EndGlobalSection
1923
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2024
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2125
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.NuPackRelease|Any CPU.ActiveCfg = NuPackRelease|Any CPU
23-
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.NuPackRelease|Any CPU.Build.0 = NuPackRelease|Any CPU
26+
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Debug-Core|Any CPU.ActiveCfg = Debug-Core|Any CPU
27+
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Debug-Core|Any CPU.Build.0 = Debug-Core|Any CPU
28+
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.NuPackRelease|Any CPU.ActiveCfg = Release|Any CPU
29+
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.NuPackRelease|Any CPU.Build.0 = Release|Any CPU
2430
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
2531
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Release-Core|Any CPU.ActiveCfg = Release-Core|Any CPU
33+
{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}.Release-Core|Any CPU.Build.0 = Release-Core|Any CPU
2634
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2735
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Debug-Core|Any CPU.ActiveCfg = Debug-Core|Any CPU
37+
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Debug-Core|Any CPU.Build.0 = Debug-Core|Any CPU
2838
{665FDD28-99EF-4038-9469-1B27F778BF1D}.NuPackRelease|Any CPU.ActiveCfg = Release|Any CPU
2939
{665FDD28-99EF-4038-9469-1B27F778BF1D}.NuPackRelease|Any CPU.Build.0 = Release|Any CPU
3040
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
3141
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Release-Core|Any CPU.ActiveCfg = Release-Core|Any CPU
43+
{665FDD28-99EF-4038-9469-1B27F778BF1D}.Release-Core|Any CPU.Build.0 = Release-Core|Any CPU
3244
EndGlobalSection
3345
GlobalSection(SolutionProperties) = preSolution
3446
HideSolutionNode = FALSE

PowerAssert/Hints/EnumComparisonShowValuesHint.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Linq;
33
using System.Linq.Expressions;
4+
#if NETCOREAPP1_1
5+
using System.Reflection;
6+
#endif
47
using PowerAssert.Infrastructure;
58

69
namespace PowerAssert.Hints
@@ -57,7 +60,11 @@ Tuple<string, string> Check(ExpressionParser parser, Expression x, Expression y)
5760

5861
if (unE != null && unE.NodeType == ExpressionType.Convert)
5962
{
63+
#if NETCOREAPP1_1
64+
if (unE.Operand.Type.GetTypeInfo().IsEnum)
65+
#else
6066
if (unE.Operand.Type.IsEnum)
67+
#endif
6168
{
6269
return Tuple.Create(Parse(parser, unE.Operand.Type, x), Parse(parser, unE.Operand.Type, y));
6370
}

PowerAssert/Hints/HintUtils.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ static string CheckCharactersAt(string left, string right, int index, StringComp
7676
return string.Format(", right string contains control character '{0}' at index {1}", PrintableChar(rightC), index);
7777
}
7878

79-
if (char.GetUnicodeCategory(leftC) == UnicodeCategory.Format)
79+
if (CharUnicodeInfo.GetUnicodeCategory(leftC) == UnicodeCategory.Format)
8080
{
8181
return string.Format(", left string contains format character '{0}' at index {1}", PrintableChar(leftC), index);
8282
}
8383

84-
if (char.GetUnicodeCategory(rightC) == UnicodeCategory.Format)
84+
if (CharUnicodeInfo.GetUnicodeCategory(rightC) == UnicodeCategory.Format)
8585
{
8686
return string.Format(", right string contains format character '{0}' at index {1}", PrintableChar(rightC), index);
8787
}

PowerAssert/Hints/StringEqualsHint.cs

+2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ static StringComparer GetComparerFromComparison(StringComparison comparison)
2020
return StringComparer.CurrentCulture;
2121
case StringComparison.CurrentCultureIgnoreCase:
2222
return StringComparer.CurrentCultureIgnoreCase;
23+
#if NET40
2324
case StringComparison.InvariantCulture:
2425
return StringComparer.InvariantCulture;
2526
case StringComparison.InvariantCultureIgnoreCase:
2627
return StringComparer.InvariantCultureIgnoreCase;
28+
#endif
2729
case StringComparison.Ordinal:
2830
return StringComparer.Ordinal;
2931
case StringComparison.OrdinalIgnoreCase:

PowerAssert/Infrastructure/ExpressionParser.cs

+12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ namespace PowerAssert.Infrastructure
1616
{
1717
class ExpressionParser
1818
{
19+
#if NETCOREAPP1_1
20+
static Assembly MyAssembly = typeof(ExpressionParser).GetTypeInfo().Assembly;
21+
#else
1922
static Assembly MyAssembly = typeof(ExpressionParser).Assembly;
23+
#endif
2024

2125
public Expression RootExpression { get; private set; }
2226
public Type TestClass { get; private set; }
@@ -40,9 +44,13 @@ public ExpressionParser(Expression expression, ParameterExpression[] parameters
4044

4145
static Type GetTestClass()
4246
{
47+
#if NETCOREAPP1_1
48+
return null;
49+
#else
4350
var st = new StackTrace(1, false);
4451
return st.GetFrames().Select(f => f.GetMethod().DeclaringType)
4552
.FirstOrDefault(t => t != null && t.Assembly != MyAssembly);
53+
#endif
4654
}
4755

4856
public Node Parse()
@@ -167,7 +175,11 @@ Node ParseExpression(NewArrayExpression e)
167175

168176
internal static string NameOfType(Type t)
169177
{
178+
#if NETCOREAPP1_1
179+
if (t.GetTypeInfo().IsGenericType)
180+
#else
170181
if (t.IsGenericType)
182+
#endif
171183
{
172184
var typeArgs = t.GetGenericArguments().Select(NameOfType).ToList();
173185
var name = IsAnonymousType(t) ? "$Anonymous" : t.Name.Split('`')[0];

PowerAssert/Infrastructure/Nodes/Node.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Collections;
33
using System.Linq;
4+
#if NETCOREAPP1_1
5+
using System.Reflection;
6+
#endif
47

58
namespace PowerAssert.Infrastructure.Nodes
69
{
@@ -20,7 +23,11 @@ public override bool Equals(object obj)
2023
return false;
2124
}
2225

26+
#if NETCOREAPP1_1
27+
var allPropertiesMatch = from info in GetType().GetTypeInfo().GetProperties()
28+
#else
2329
var allPropertiesMatch = from info in GetType().GetProperties()
30+
#endif
2431
let mine = info.GetValue(this, null)
2532
let theirs = info.GetValue(obj, null)
2633
select ObjectsOrEnumerablesEqual(mine, theirs);

PowerAssert/Infrastructure/ObjectFormatter.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ internal static string FormatObject(object value)
3636
}
3737

3838
var type = value.GetType();
39-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof (KeyValuePair<,>))
39+
#if NETCOREAPP1_1
40+
var isGenericType = new Func<Type, bool>(t => t.GetTypeInfo().IsGenericType);
41+
#else
42+
var isGenericType = new Func<Type, bool>(t => t.IsGenericType);
43+
#endif
44+
if (isGenericType(type) && type.GetGenericTypeDefinition() == typeof (KeyValuePair<,>))
4045
{
4146
var k = type.GetProperty("Key").GetValue(value, null);
4247
var v = type.GetProperty("Value").GetValue(value, null);
4348
return String.Format("{{{0}:{1}}}", FormatObject(k), FormatObject(v));
4449
}
4550
if (type.GetInterfaces()
46-
.Where(i => i.IsGenericType)
51+
.Where(isGenericType)
4752
.Any(i => i.GetGenericTypeDefinition() == typeof(IGrouping<,>)))
4853
{
4954
var k = type.GetProperty("Key").GetValue(value, null);
@@ -57,7 +62,13 @@ internal static string FormatObject(object value)
5762
{
5863
var del = (Delegate) value;
5964

60-
return String.Format("delegate {0}, type: {2} ({1})", ExpressionParser.NameOfType(del.GetType()), String.Join(", ", del.Method.GetParameters().Select(x => ExpressionParser.NameOfType(x.ParameterType))), ExpressionParser.NameOfType(del.Method.ReturnType));
65+
#if NETCOREAPP1_1
66+
var method = RuntimeReflectionExtensions.GetMethodInfo(del);
67+
#else
68+
var method = del.Method;
69+
#endif
70+
71+
return String.Format("delegate {0}, type: {2} ({1})", ExpressionParser.NameOfType(del.GetType()), String.Join(", ", method.GetParameters().Select(x => ExpressionParser.NameOfType(x.ParameterType))), ExpressionParser.NameOfType(method.ReturnType));
6172
}
6273
if (value is IEnumerable)
6374
{

PowerAssert/MultipleAssertions/Error.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ namespace PowerAssert.MultipleAssertions
77
{
88
public class Error
99
{
10+
#if NETCOREAPP1_1
11+
static Assembly MyAssembly = typeof(Error).GetTypeInfo().Assembly;
12+
#else
1013
static Assembly MyAssembly = typeof(Error).Assembly;
14+
#endif
1115

1216
internal static readonly string Crlf = Environment.NewLine;
1317

@@ -17,24 +21,25 @@ public class Error
1721
public Error(string message)
1822
{
1923
Message = message;
24+
25+
#if NET40
2026
var stackFrames = from f in new StackTrace(1, true).GetFrames()
2127
let m = f.GetMethod()
2228
where m != null
2329
let t = m.DeclaringType
24-
where t.Assembly != MyAssembly
25-
select f;
30+
where t.Assembly != MyAssembly
31+
select f;
2632
var frame = stackFrames.FirstOrDefault();
2733
if (frame != null)
2834
{
2935
var method = frame.GetMethod();
3036
var typeName = method.DeclaringType == null ? "" : method.DeclaringType.Name;
3137
Location = string.Format("in {0}.{1} at {2}:{3}", typeName, method.Name, frame.GetFileName(), frame.GetFileLineNumber());
38+
return;
3239
}
33-
else
34-
{
35-
Location = "(Unknown location)";
36-
}
40+
#endif
3741

42+
Location = "(Unknown location)";
3843
}
3944

4045

PowerAssert/PowerAssert.csproj

+35-104
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,51 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>{7E9D2DB4-78FE-41BD-9566-15F68D42E4D9}</ProjectGuid>
9-
<OutputType>Library</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>PowerAssert</RootNamespace>
12-
<AssemblyName>PowerAssert</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14-
<FileAlignment>512</FileAlignment>
15-
<TargetFrameworkProfile />
3+
<TargetFrameworks>netcoreapp1.1;net40</TargetFrameworks>
4+
<PackageId>PowerAssert</PackageId>
5+
<Authors>Rob Fonseca-Ensor, David Alpert, George Pollard, Anders Holmström, Josh Robb, Alex Henderson and Peter Goodman</Authors>
6+
<Description>When you make a unit test assertion with PowerAssert, your assertion messages become much more useful.</Description>
7+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
8+
<PackageLicenseUrl>https://github.com/PowerAssert/PowerAssert.Net/blob/master/LICENSE.txt</PackageLicenseUrl>
9+
<PackageProjectUrl>https://github.com/PowerAssert/PowerAssert.Net</PackageProjectUrl>
10+
<PackageTags>NUnit xUnit.NET mstest expression-tree</PackageTags>
1611
</PropertyGroup>
17-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18-
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
20-
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
22-
<DefineConstants>DEBUG;TRACE</DefineConstants>
23-
<ErrorReport>prompt</ErrorReport>
24-
<WarningLevel>4</WarningLevel>
25-
<Prefer32Bit>false</Prefer32Bit>
26-
</PropertyGroup>
27-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28-
<DebugType>pdbonly</DebugType>
29-
<Optimize>true</Optimize>
30-
<OutputPath>bin\Release\</OutputPath>
31-
<DefineConstants>TRACE</DefineConstants>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
<Prefer32Bit>false</Prefer32Bit>
12+
13+
<PropertyGroup>
14+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
3515
</PropertyGroup>
36-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NuPackRelease|AnyCPU'">
37-
<OutputPath>release\lib\</OutputPath>
38-
<DefineConstants>TRACE</DefineConstants>
39-
<Optimize>true</Optimize>
40-
<DebugType>none</DebugType>
41-
<PlatformTarget>AnyCPU</PlatformTarget>
42-
<CodeAnalysisLogFile>bin\Release\PowerAssert.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
43-
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
44-
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
45-
<ErrorReport>prompt</ErrorReport>
46-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
47-
<CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
48-
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
49-
<CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
50-
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
51-
<Prefer32Bit>false</Prefer32Bit>
16+
17+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug-Core|netcoreapp1.1|AnyCPU'" />
18+
19+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release-Core|netcoreapp1.1|AnyCPU'" />
20+
21+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net40|AnyCPU'">
22+
<DebugType>full</DebugType>
23+
<DebugSymbols>True</DebugSymbols>
5224
</PropertyGroup>
53-
<ItemGroup>
25+
26+
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
5427
<Reference Include="Microsoft.CSharp" />
5528
<Reference Include="System" />
5629
<Reference Include="System.Core" />
5730
</ItemGroup>
31+
5832
<ItemGroup>
59-
<Compile Include="Annotations.cs" />
60-
<Compile Include="Hints\BrokenEqualityHint.cs" />
61-
<Compile Include="Hints\EnumComparisonShowValuesHint.cs" />
62-
<Compile Include="Hints\TimeSpanTotalMistakesHint.cs" />
63-
<Compile Include="Hints\EnumerableEqualsHint.cs" />
64-
<Compile Include="Hints\DelegateShouldHaveBeenInvokedEqualsHint.cs" />
65-
<Compile Include="Hints\EnumerableOperatorEqualsHint.cs" />
66-
<Compile Include="Hints\FloatEqualityHint.cs" />
67-
<Compile Include="Hints\HintUtils.cs" />
68-
<Compile Include="Hints\IHint.cs" />
69-
<Compile Include="Hints\MethodEqualsInsteadOfOperatorEqualsHint.cs" />
70-
<Compile Include="Hints\MultiHint.cs" />
71-
<Compile Include="Hints\OperatorEqualsHintBase.cs" />
72-
<Compile Include="Hints\SequenceEqualHint.cs" />
73-
<Compile Include="Hints\StringEqualsHint.cs" />
74-
<Compile Include="Hints\StringOperatorEqualsHint.cs" />
75-
<Compile Include="Infrastructure\ExpressionParser.cs" />
76-
<Compile Include="Infrastructure\Nodes\InvocationNode.cs" />
77-
<Compile Include="Infrastructure\NodeFormatter.cs" />
78-
<Compile Include="Infrastructure\Nodes\ArrayIndexNode.cs" />
79-
<Compile Include="Infrastructure\Nodes\BinaryNode.cs" />
80-
<Compile Include="Infrastructure\Nodes\ConditionalNode.cs" />
81-
<Compile Include="Infrastructure\Nodes\ConstantNode.cs" />
82-
<Compile Include="Infrastructure\Nodes\MemberAccessNode.cs" />
83-
<Compile Include="Infrastructure\Nodes\MethodCallNode.cs" />
84-
<Compile Include="Infrastructure\Nodes\NewArrayNode.cs" />
85-
<Compile Include="Infrastructure\Nodes\NewObjectNode.cs" />
86-
<Compile Include="Infrastructure\Nodes\Node.cs" />
87-
<Compile Include="Infrastructure\Nodes\UnaryNode.cs" />
88-
<Compile Include="Infrastructure\ObjectFormatter.cs" />
89-
<Compile Include="Infrastructure\ReplacementVisitor.cs" />
90-
<Compile Include="Infrastructure\Util.Generated.cs">
91-
<AutoGen>True</AutoGen>
92-
<DesignTime>True</DesignTime>
93-
<DependentUpon>Util.tt</DependentUpon>
94-
</Compile>
95-
<Compile Include="MultipleAssertions\Error.cs" />
96-
<Compile Include="MultipleAssertions\PolyAssert.cs" />
97-
<Compile Include="MultipleAssertions\PolyAssertException.cs" />
98-
<Compile Include="PAssert.cs" />
99-
<Compile Include="Properties\AssemblyInfo.cs" />
100-
</ItemGroup>
101-
<ItemGroup>
102-
<None Include="Infrastructure\Util.tt">
33+
<None Update="Infrastructure\Util.tt">
10334
<Generator>TextTemplatingFileGenerator</Generator>
10435
<LastGenOutput>Util.Generated.cs</LastGenOutput>
10536
</None>
106-
<None Include="powerassert.nuspec" />
10737
</ItemGroup>
38+
39+
<ItemGroup>
40+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
41+
</ItemGroup>
42+
10843
<ItemGroup>
109-
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
44+
<Compile Update="Infrastructure\Util.Generated.cs">
45+
<DesignTime>True</DesignTime>
46+
<AutoGen>True</AutoGen>
47+
<DependentUpon>Util.tt</DependentUpon>
48+
</Compile>
11049
</ItemGroup>
111-
<ItemGroup />
112-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
113-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
114-
Other similar extension points exist, see Microsoft.Common.targets.
115-
<Target Name="BeforeBuild">
116-
</Target>
117-
<Target Name="AfterBuild">
118-
</Target>
119-
-->
50+
12051
</Project>

0 commit comments

Comments
 (0)