Skip to content

Commit 1e2a82c

Browse files
authored
Use .NET SDK in two test projects (#371)
- Use .NET SDK in NetCore.Test project - for now, unable to target `netcoreapp2.1` in NetCore.Test project - Microsoft.Net.Http is not compatible - System.Net.Http types have different identities, causing compilation failures - switch to use `dotnet vstest` for any .NET Core assemblies (just one currently) - can use `Xunit` target for all .NET Framework assemblies - make XunitXml.TestLogger available for .NET Core App testing - use above test logger in repo-level testing - integrate w/ tests that use the `Xunit` target - don't import from xunit.msbuild.runner when targeting .NET Core; not needed - add `$(CopyLocalLockFileAssemblies)` to these (now both .NET SDK) test projects - xUnit assemblies were not copied (when they should have been) w/o this - Use .NET SDK in Microsoft.TestCommon - allows reference in .NET SDK test projects - Create general `TestAssembly` target - rename WebStack.xunit.targets -> WebStack.testing.targets - rename `Xunit` target -> `TestAssembly` - move `dotnet vstest` use into new target - handle exit codes more consistently
1 parent c98af89 commit 1e2a82c

File tree

14 files changed

+137
-486
lines changed

14 files changed

+137
-486
lines changed

Runtime.msbuild

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,30 @@
102102
<Target Name="RunTests" DependsOnTargets="CheckSkipStrongNames">
103103
<ItemGroup>
104104
<_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.dll" />
105-
<_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.*.dll" />
106-
<_TestDLLsXunit Include="bin\$(Configuration)\Test\NetCore\*.Test.dll" Condition="'$(BuildPortable)' == 'true'" />
107-
<_XunitProject Include="tools\WebStack.xunit.targets">
108-
<Properties>TestAssembly=%(_TestDLLsXunit.FullPath);XmlPath=$(TestResultsDirectory)%(_TestDLLsXunit.FileName)-XunitResults.xml</Properties>
105+
<_TestDLLsXunit Include="bin\$(Configuration)\test\*\net4*\*.Test.dll"
106+
Condition=" '$(BuildPortable)' == 'true' " />
107+
<_XunitProject Include="tools\WebStack.testing.targets">
108+
<Properties>TestAssembly=%(_TestDLLsXunit.FullPath);
109+
XmlPath=$(TestResultsDirectory)%(_TestDLLsXunit.FileName)-XunitResults.xml</Properties>
110+
</_XunitProject>
111+
112+
<_VSTestDLLs Include="bin\$(Configuration)\test\*\netcoreapp*\*.Test.dll"
113+
Condition=" '$(BuildPortable)' == 'true' "/>
114+
<_XunitProject Include="tools\WebStack.testing.targets"
115+
Condition=" '$(BuildPortable)' == 'true' ">
116+
<Properties>TestAssembly=%(_VSTestDLLs.FullPath);
117+
XmlPath=$(TestResultsDirectory)%(_VSTestDLLs.FileName)-NetCoreApp-XunitResults.xml;
118+
UseVSTest=true</Properties>
109119
</_XunitProject>
110120
</ItemGroup>
111121

112122
<!-- Recreate the test results directory so that print summary doesn't run on old test results. -->
113123
<RemoveDir Directories="$(TestResultsDirectory)" />
114124
<MakeDir Directories="$(TestResultsDirectory)" />
115125

116-
<MSBuild Projects="@(_XunitProject)" BuildInParallel="$(TestInParallel)" Targets="Xunit">
126+
<MSBuild Projects="@(_XunitProject)" BuildInParallel="$(TestInParallel)" Targets="TestAssembly">
117127
<Output TaskParameter="TargetOutputs" ItemName="_ExitCodes" />
118128
</MSBuild>
119-
120-
<!-- Failures in this project will fail build. But, results will not be included in test run summary. -->
121-
<MSBuild
122-
Properties="Configuration=$(Configuration)"
123-
Projects="test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj"
124-
Targets="Test"
125-
Condition="'$(BuildPortable)' == 'true'" />
126129
</Target>
127130

128131
<Target Name="CheckSkipStrongNames" DependsOnTargets="RestoreSkipStrongNames">

RuntimePortable.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A9836F9E-6DB
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{C40883CD-366D-4534-8B58-3EA0D13136DF}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TestCommon", "test\Microsoft.TestCommon\Microsoft.TestCommon.csproj", "{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestCommon", "test\Microsoft.TestCommon\Microsoft.TestCommon.csproj", "{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}"
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetCore", "src\System.Net.Http.Formatting.NetCore\System.Net.Http.Formatting.NetCore.csproj", "{C7060639-719B-4BD2-8A37-2F146B5A0668}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetCore.Test", "test\System.Net.Http.Formatting.NetCore.Test\System.Net.Http.Formatting.NetCore.Test.csproj", "{8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.NetCore.Test", "test\System.Net.Http.Formatting.NetCore.Test\System.Net.Http.Formatting.NetCore.Test.csproj", "{8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}"
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.NetStandard", "src\System.Net.Http.Formatting.NetStandard\System.Net.Http.Formatting.NetStandard.csproj", "{636CA76A-C85C-42E2-B4AA-88046279B3CA}"
1717
EndProject

packages/repositories.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
<repository path="..\src\WebApiHelpPage\packages.config" />
1818
<repository path="..\src\WebApiHelpPage\VB\packages.config" />
1919
<repository path="..\test\Microsoft.AspNet.Facebook.Test\packages.config" />
20-
<repository path="..\test\Microsoft.TestCommon\packages.config" />
2120
<repository path="..\test\Microsoft.Web.Helpers.Test\packages.config" />
2221
<repository path="..\test\Microsoft.Web.Mvc.Test\packages.config" />
2322
<repository path="..\test\Microsoft.Web.WebPages.OAuth.Test\packages.config" />
24-
<repository path="..\test\System.Net.Http.Formatting.NetCore.Test\packages.config" />
2523
<repository path="..\test\System.Net.Http.Formatting.Test\packages.config" />
2624
<repository path="..\test\System.Web.Cors.Test\packages.config" />
2725
<repository path="..\test\System.Web.Helpers.Test\packages.config" />

test/Directory.Build.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<PropertyGroup>
55
<IsPackable>false</IsPackable>
66
<IsTestProject>true</IsTestProject>
7-
<TargetFrameworkVersion Condition="'$(MSBuildProjectName)' != 'System.Net.Http.Formatting.NetStandard.Test'">v4.5.2</TargetFrameworkVersion>
7+
<TargetFrameworkVersion
8+
Condition=" '$(MSBuildProjectName)' != 'Microsoft.TestCommon' AND
9+
'$(MSBuildProjectName)' != 'System.Net.Http.Formatting.NetCore.Test' AND
10+
'$(MSBuildProjectName)' != 'System.Net.Http.Formatting.NetStandard.Test' ">v4.5.2</TargetFrameworkVersion>
811
</PropertyGroup>
912
</Project>

test/Directory.Build.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project>
22
<Import Project="..\Directory.Build.targets" />
3-
<Import Project="..\packages\xunit.runner.msbuild.2.3.1\**\xunit.runner.msbuild.props" />
3+
<Import Project="..\packages\xunit.runner.msbuild.2.3.1\**\xunit.runner.msbuild.props"
4+
Condition="$(IsTestProject) and '$(MSBuildRuntimeType)' != 'Core' and '$(TargetFrameworkIdentifier)' == '.NETFramework'" />
45

56
<Target Name="Test" DependsOnTargets="_TestWithVSTest;_TestWithDotnetTest;_TestWithRunner" />
67

test/Microsoft.TestCommon/ExceptionAssertions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ public static ArgumentOutOfRangeException ThrowsArgumentLessThanOrEqualTo(Action
466466
String.Format(CultureReplacer.DefaultCulture, "Value must be less than or equal to {0}.", maxValue), false, actualValue);
467467
}
468468

469+
#if !NETCOREAPP
469470
/// <summary>
470471
/// Verifies that the code throws an HttpException (or optionally any exception which derives from it).
471472
/// </summary>
@@ -481,6 +482,7 @@ public static HttpException ThrowsHttpException(Action testCode, string exceptio
481482
Equal(httpCode, ex.GetHttpCode());
482483
return ex;
483484
}
485+
#endif
484486

485487
/// <summary>
486488
/// Verifies that the code throws an InvalidEnumArgumentException (or optionally any exception which derives from it).
Lines changed: 17 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,23 @@
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
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Runtime.sln))\tools\WebStack.settings.targets" />
43
<PropertyGroup>
5-
<ProjectGuid>{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}</ProjectGuid>
6-
<OutputType>Library</OutputType>
7-
<AppDesignerFolder>Properties</AppDesignerFolder>
8-
<RootNamespace>Microsoft.TestCommon</RootNamespace>
9-
<AssemblyName>Microsoft.TestCommon</AssemblyName>
10-
<IsTestProject>false</IsTestProject>
4+
<TargetFrameworks>netcoreapp2.1;net452</TargetFrameworks>
115
<OutputPath>..\..\bin\$(Configuration)\Test\</OutputPath>
12-
<CodeSignEnabled>false</CodeSignEnabled>
13-
<EnableGetGitHeadSHA1>false</EnableGetGitHeadSHA1>
14-
<ValidateBuildParamsDisabled>true</ValidateBuildParamsDisabled>
15-
<VersionFileGenerationEnabled>false</VersionFileGenerationEnabled>
6+
<Configurations>$(Configurations);CodeAnalysis</Configurations>
7+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
168
</PropertyGroup>
179
<ItemGroup>
18-
<Reference Include="System" />
19-
<Reference Include="System.Core" />
20-
<Reference Include="System.Data" />
21-
<Reference Include="System.Net.Http" />
22-
<Reference Include="System.Net.Http.WebRequest" />
23-
<Reference Include="System.Runtime.Serialization" />
24-
<Reference Include="System.Web" />
25-
<Reference Include="System.Xml" />
26-
<Reference Include="System.Xml.Linq" />
27-
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
28-
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
29-
<Private>True</Private>
30-
</Reference>
31-
<Reference Include="xunit.assert, Version=2.3.0.3820, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
32-
<HintPath>..\..\packages\xunit.assert.2.3.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
33-
<Private>True</Private>
34-
</Reference>
35-
<Reference Include="xunit.core, Version=2.3.0.3820, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
36-
<HintPath>..\..\packages\xunit.extensibility.core.2.3.0\lib\netstandard1.1\xunit.core.dll</HintPath>
37-
<Private>True</Private>
38-
</Reference>
39-
<Reference Include="xunit.execution.desktop, Version=2.3.0.3820, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
40-
<HintPath>..\..\packages\xunit.extensibility.execution.2.3.0\lib\net452\xunit.execution.desktop.dll</HintPath>
41-
<Private>True</Private>
42-
</Reference>
10+
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
11+
12+
<PackageReference Include="Moq" Version="4.7.142.0" />
13+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
14+
<PackageReference Include="xunit.abstractions" Version="2.0.1" />
15+
<PackageReference Include="xunit.assert" Version="2.3.0" />
16+
<PackageReference Include="xunit.extensibility.core" Version="2.3.0" />
17+
<PackageReference Include="xunit.extensibility.execution" Version="2.3.0" />
18+
19+
<Compile Remove="AppDomainUtils.cs;Microsoft\TestCommon\RuntimeEnvironment.cs;WebUtils.cs"
20+
Condition=" '$(TargetFramework)' == 'netcoreapp2.1' "/>
21+
<Reference Include="System.Web" Condition=" '$(TargetFramework)' == 'net452' " />
4322
</ItemGroup>
44-
<ItemGroup>
45-
<Compile Include="DataAttribute.cs" />
46-
<Compile Include="EnumHelperTestBase.cs" />
47-
<Compile Include="ExceptionUtility.cs" />
48-
<Compile Include="FactDiscoverer.cs" />
49-
<Compile Include="InlineDataAttribute.cs" />
50-
<Compile Include="MatrixTheoryDataSet.cs" />
51-
<Compile Include="Microsoft\TestCommon\DataSets\TestDataHolder.cs" />
52-
<Compile Include="Microsoft\TestCommon\Types\ByteEnum.cs" />
53-
<Compile Include="Microsoft\TestCommon\Types\SByteEnum.cs" />
54-
<Compile Include="Microsoft\TestCommon\Types\ShortEnum.cs" />
55-
<Compile Include="Microsoft\TestCommon\Types\UIntEnum.cs" />
56-
<Compile Include="Microsoft\TestCommon\Types\UShortEnum.cs" />
57-
<Compile Include="Platform.cs" />
58-
<Compile Include="PlatformInfo.cs" />
59-
<Compile Include="PortReserver.cs" />
60-
<Compile Include="PropertyDataAttribute.cs" />
61-
<Compile Include="ReplaceCultureAttribute.cs" />
62-
<Compile Include="RestoreThreadPrincipalAttribute.cs" />
63-
<Compile Include="AppDomainUtils.cs" />
64-
<Compile Include="Assert.cs">
65-
<SubType>Code</SubType>
66-
</Compile>
67-
<Compile Include="CultureReplacer.cs" />
68-
<Compile Include="FactAttribute.cs" />
69-
<Compile Include="SkippedXunitTestCase.cs" />
70-
<Compile Include="TheoryAttribute.cs" />
71-
<Compile Include="DictionaryEqualityComparer.cs" />
72-
<Compile Include="ExceptionAssertions.cs">
73-
<SubType>Code</SubType>
74-
</Compile>
75-
<Compile Include="ForceGCAttribute.cs" />
76-
<Compile Include="MemberHelper.cs" />
77-
<Compile Include="Microsoft\TestCommon\DataSets\RefTypeTestData.cs" />
78-
<Compile Include="Microsoft\TestCommon\DataSets\TestDataVariations.cs" />
79-
<Compile Include="Microsoft\TestCommon\DataSets\ValueTypeTestData.cs" />
80-
<Compile Include="Microsoft\TestCommon\GenericTypeAssert.cs" />
81-
<Compile Include="Microsoft\TestCommon\HttpAssert.cs" />
82-
<Compile Include="Microsoft\TestCommon\MediaTypeAssert.cs" />
83-
<Compile Include="Microsoft\TestCommon\MediaTypeHeaderValueComparer.cs" />
84-
<Compile Include="Microsoft\TestCommon\ParsedMediaTypeHeaderValue.cs" />
85-
<Compile Include="Microsoft\TestCommon\RegexReplacement.cs" />
86-
<Compile Include="Microsoft\TestCommon\RuntimeEnvironment.cs" />
87-
<Compile Include="Microsoft\TestCommon\SerializerAssert.cs" />
88-
<Compile Include="Microsoft\TestCommon\StreamAssert.cs" />
89-
<Compile Include="Microsoft\TestCommon\TaskAssert.cs" />
90-
<Compile Include="Microsoft\TestCommon\DataSets\TestData.cs" />
91-
<Compile Include="Microsoft\TestCommon\TestDataSetAttribute.cs" />
92-
<Compile Include="Microsoft\TestCommon\TimeoutConstant.cs" />
93-
<Compile Include="Microsoft\TestCommon\TypeAssert.cs" />
94-
<Compile Include="Microsoft\TestCommon\Types\FlagsEnum.cs" />
95-
<Compile Include="Microsoft\TestCommon\Types\INameAndIdContainer.cs" />
96-
<Compile Include="Microsoft\TestCommon\Types\ISerializableType.cs" />
97-
<Compile Include="Microsoft\TestCommon\Types\LongEnum.cs" />
98-
<Compile Include="Microsoft\TestCommon\Types\SimpleEnum.cs" />
99-
<Compile Include="Microsoft\TestCommon\DataSets\CommonUnitTestDataSets.cs" />
100-
<Compile Include="Microsoft\TestCommon\XmlAssert.cs" />
101-
<Compile Include="PreAppStartTestHelper.cs" />
102-
<Compile Include="PreserveSyncContextAttribute.cs" />
103-
<Compile Include="ReflectionAssert.cs" />
104-
<Compile Include="TestFile.cs" />
105-
<Compile Include="TestHelper.cs" />
106-
<Compile Include="TheoryDataSet.cs" />
107-
<Compile Include="TheoryDiscoverer.cs" />
108-
<Compile Include="ThreadPoolSyncContext.cs" />
109-
<Compile Include="TraitAttribute.cs" />
110-
<Compile Include="VersionTestHelper.cs" />
111-
<Compile Include="WebUtils.cs" />
112-
</ItemGroup>
113-
<ItemGroup>
114-
<None Include="packages.config" />
115-
<None Include="xunit.runner.json">
116-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
117-
</None>
118-
</ItemGroup>
119-
<ItemGroup>
120-
<Analyzer Include="..\..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
121-
</ItemGroup>
122-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
123-
<ProjectExtensions>
124-
<VisualStudio>
125-
<UserProperties xunit_1runner_1json__JSONSchema="https://xunit.github.io/schema/v2.1-rc1/xunit.runner.schema.json" />
126-
</VisualStudio>
127-
</ProjectExtensions>
128-
</Project>
23+
</Project>

test/Microsoft.TestCommon/packages.config

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

0 commit comments

Comments
 (0)