From 2e97d67240b0d7e3e57af3ee2a96a9297932fdb5 Mon Sep 17 00:00:00 2001
From: Adam Friedman <tintoy@tintoy.io>
Date: Fri, 29 Sep 2017 21:11:44 +1000
Subject: [PATCH] Start migrating tests to .NET Core.

dotnet/docfx#1963
---
 ...DocAsCode.Build.JavaScriptReference.csproj |  4 --
 .../Microsoft.DocAsCode.Build.Common.csproj   |  4 --
 ...rosoft.DocAsCode.Build.SchemaDriven.csproj |  5 --
 .../Parsers/TripleSlashCommentModel.cs        |  7 ++-
 src/Shared/base.netcoreapp.props              | 58 +++++++++++++++++++
 ...rosoft.DocAsCode.Build.Engine.Tests.csproj |  3 +-
 .../Microsoft.DocAsCode.Tests.Common.csproj   |  2 +-
 test/Shared/test.base.netcoreapp.props        | 21 +++++++
 test/Shared/test.base.netstandard.props       | 21 +++++++
 test/Shared/test.base.props                   |  6 +-
 10 files changed, 112 insertions(+), 19 deletions(-)
 create mode 100644 src/Shared/base.netcoreapp.props
 create mode 100644 test/Shared/test.base.netcoreapp.props
 create mode 100644 test/Shared/test.base.netstandard.props

diff --git a/plugins/Microsoft.DocAsCode.Build.JavaScriptReference/Microsoft.DocAsCode.Build.JavaScriptReference.csproj b/plugins/Microsoft.DocAsCode.Build.JavaScriptReference/Microsoft.DocAsCode.Build.JavaScriptReference.csproj
index 18f1a2af694..e24f5250708 100644
--- a/plugins/Microsoft.DocAsCode.Build.JavaScriptReference/Microsoft.DocAsCode.Build.JavaScriptReference.csproj
+++ b/plugins/Microsoft.DocAsCode.Build.JavaScriptReference/Microsoft.DocAsCode.Build.JavaScriptReference.csproj
@@ -11,10 +11,6 @@
     <PackageReference Include="AutoMapper" Version="5.2.0" />
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'net46' OR '$(TargetFramework)' == 'net452'">
-    <Reference Include="System.Web" />
-  </ItemGroup>
-
   <ItemGroup>
     <ProjectReference Include="..\..\src\Microsoft.DocAsCode.Build.Common\Microsoft.DocAsCode.Build.Common.csproj" />
     <ProjectReference Include="..\..\src\Microsoft.DocAsCode.Common\Microsoft.DocAsCode.Common.csproj" />
diff --git a/src/Microsoft.DocAsCode.Build.Common/Microsoft.DocAsCode.Build.Common.csproj b/src/Microsoft.DocAsCode.Build.Common/Microsoft.DocAsCode.Build.Common.csproj
index a69fc79220a..902fde039c0 100644
--- a/src/Microsoft.DocAsCode.Build.Common/Microsoft.DocAsCode.Build.Common.csproj
+++ b/src/Microsoft.DocAsCode.Build.Common/Microsoft.DocAsCode.Build.Common.csproj
@@ -14,8 +14,4 @@
     <PackageReference Include="Microsoft.Composition" Version="1.0.31" />
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'net46' OR '$(TargetFramework)' == 'net452'">
-    <Reference Include="System.Web" />
-  </ItemGroup>
-
 </Project>
diff --git a/src/Microsoft.DocAsCode.Build.SchemaDriven/Microsoft.DocAsCode.Build.SchemaDriven.csproj b/src/Microsoft.DocAsCode.Build.SchemaDriven/Microsoft.DocAsCode.Build.SchemaDriven.csproj
index 09f9e8b9169..621ac1e33be 100644
--- a/src/Microsoft.DocAsCode.Build.SchemaDriven/Microsoft.DocAsCode.Build.SchemaDriven.csproj
+++ b/src/Microsoft.DocAsCode.Build.SchemaDriven/Microsoft.DocAsCode.Build.SchemaDriven.csproj
@@ -16,11 +16,6 @@
     <PackageReference Include="Newtonsoft.Json.Schema" Version="2.0.10" />
   </ItemGroup>
 
-  <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="Microsoft.CSharp" />
-  </ItemGroup>
-
   <ItemGroup>
     <Folder Include="schemas\v1.0\" />
   </ItemGroup>
diff --git a/src/Microsoft.DocAsCode.Metadata.ManagedReference/Parsers/TripleSlashCommentModel.cs b/src/Microsoft.DocAsCode.Metadata.ManagedReference/Parsers/TripleSlashCommentModel.cs
index 34798be74d2..ef5aa548e86 100644
--- a/src/Microsoft.DocAsCode.Metadata.ManagedReference/Parsers/TripleSlashCommentModel.cs
+++ b/src/Microsoft.DocAsCode.Metadata.ManagedReference/Parsers/TripleSlashCommentModel.cs
@@ -459,7 +459,12 @@ private void ResolveCrefLink(XNode node, string nodeSelector, Action<string, str
                         // When see and seealso are top level nodes in triple slash comments, do not convert it into xref node
                         if (item.Parent?.Parent != null)
                         {
-                            var replacement = XElement.Parse($"<xref href=\"{HttpUtility.UrlEncode(id)}\" data-throw-if-not-resolved=\"false\"></xref>");
+                            // <xref href="id" data-throw-if-not-resolved="false"></xref>
+                            XElement replacement = new XElement("xref",
+                                new XAttribute("href", id),
+                                new XAttribute("data-throw-if-not-resolved", "false"),
+                                new XText(String.Empty)
+                            );
                             item.ReplaceWith(replacement);
                         }
 
diff --git a/src/Shared/base.netcoreapp.props b/src/Shared/base.netcoreapp.props
new file mode 100644
index 00000000000..c04f84830d1
--- /dev/null
+++ b/src/Shared/base.netcoreapp.props
@@ -0,0 +1,58 @@
+<Project>
+  <PropertyGroup>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
+    <AssetTargetFallback>net461</AssetTargetFallback>
+
+    <!-- Note: by convention assembly should be named after the root namespace -->
+    <AssemblyName Condition=" '$(AssemblyName)' == '' ">$(MSBuildProjectName)</AssemblyName>
+    <AssemblyTitle Condition=" '$(AssemblyTitle)' == '' ">$(MSBuildProjectName)</AssemblyTitle>
+    <Product Condition=" '$(Product)' == '' ">$(MSBuildProjectName)</Product>
+    <PackageId Condition=" '$(PackageId)' == '' ">$(MSBuildProjectName)</PackageId>
+    <Company Condition=" '$(Company)' == '' ">Microsoft</Company>
+    <Copyright Condition=" '$(Copyright)' == '' ">Copyright © Microsoft docfx 2015-2017</Copyright>
+
+    <PackageProjectUrl Condition=" '$(PackageProjectUrl)' == '' ">https://github.com/dotnet/docfx</PackageProjectUrl>
+    <PackageLicenseUrl Condition=" '$(PackageLicenseUrl)' == '' ">https://github.com/dotnet/docfx/blob/dev/LICENSE</PackageLicenseUrl>
+
+    <VersionCSFile Condition="'$(VersionCSFile)' == ''">$(MSBuildThisFileDirectory)..\..\TEMP\version.cs</VersionCSFile>
+    <VersionFileExists Condition="Exists($(VersionCSFile))" >true</VersionFileExists>
+
+    <GenerateAssemblyVersionAttribute Condition=" '$(VersionFileExists)' == 'true' ">false</GenerateAssemblyVersionAttribute>
+    <GenerateAssemblyFileVersionAttribute Condition=" '$(VersionFileExists)' == 'true' ">false</GenerateAssemblyFileVersionAttribute>
+    <GenerateAssemblyInformationalVersionAttribute Condition=" '$(VersionFileExists)' == 'true' ">false</GenerateAssemblyInformationalVersionAttribute>
+
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <RootNamespace Condition=" '$(RootNamespace)' == '' ">$(AssemblyName)</RootNamespace>
+    <DebugSymbols>true</DebugSymbols>
+    <ErrorReport>prompt</ErrorReport>
+
+    <!-- Note: unless explicitly specified, we will generate DLL -->
+    <Prefer32Bit>false</Prefer32Bit>
+    <RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
+
+    <!-- Note: get rid of vshost.exe since we don't gain much benefits -->
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <WarningLevel>4</WarningLevel>
+
+  </PropertyGroup>
+
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <DefineConstants>TRACE</DefineConstants>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Condition="Exists($(VersionCSFile))" Include="$(VersionCSFile)" />
+  </ItemGroup>
+
+  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp.0' ">
+    <!-- Common references -->
+  </ItemGroup>
+</Project>
diff --git a/test/Microsoft.DocAsCode.Build.Engine.Tests/Microsoft.DocAsCode.Build.Engine.Tests.csproj b/test/Microsoft.DocAsCode.Build.Engine.Tests/Microsoft.DocAsCode.Build.Engine.Tests.csproj
index c69e68d7b03..38503cd313e 100644
--- a/test/Microsoft.DocAsCode.Build.Engine.Tests/Microsoft.DocAsCode.Build.Engine.Tests.csproj
+++ b/test/Microsoft.DocAsCode.Build.Engine.Tests/Microsoft.DocAsCode.Build.Engine.Tests.csproj
@@ -1,5 +1,5 @@
 <Project Sdk="Microsoft.NET.Sdk">
-  <Import Project="..\Shared\test.base.props" />
+  <Import Project="..\Shared\test.base.netcoreapp.props" />
   <ItemGroup>
     <Compile Remove="TestData\snippets\dataflowdegreeofparallelism.cs" />
   </ItemGroup>
@@ -30,6 +30,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="HtmlAgilityPack" Version="1.5.5" />
     <PackageReference Include="System.Net.Http" Version="4.3.2" />
   </ItemGroup>
 
diff --git a/test/Microsoft.DocAsCode.Tests.Common/Microsoft.DocAsCode.Tests.Common.csproj b/test/Microsoft.DocAsCode.Tests.Common/Microsoft.DocAsCode.Tests.Common.csproj
index c2d2b18d8c1..f6a12fee992 100644
--- a/test/Microsoft.DocAsCode.Tests.Common/Microsoft.DocAsCode.Tests.Common.csproj
+++ b/test/Microsoft.DocAsCode.Tests.Common/Microsoft.DocAsCode.Tests.Common.csproj
@@ -1,5 +1,5 @@
 <Project Sdk="Microsoft.NET.Sdk">
-  <Import Project="..\Shared\test.base.props" />
+  <Import Project="..\Shared\test.base.netstandard.props" />
 
   <ItemGroup>
     <ProjectReference Include="..\..\src\Microsoft.DocAsCode.Common\Microsoft.DocAsCode.Common.csproj" />
diff --git a/test/Shared/test.base.netcoreapp.props b/test/Shared/test.base.netcoreapp.props
new file mode 100644
index 00000000000..24073b15c33
--- /dev/null
+++ b/test/Shared/test.base.netcoreapp.props
@@ -0,0 +1,21 @@
+<Project>
+
+  <PropertyGroup>
+    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
+  </PropertyGroup>
+
+  <Import Project="../../src/Shared/base.netcoreapp.props" />
+
+  <PropertyGroup>
+
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
+    <PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
+  </ItemGroup>
+
+</Project>
diff --git a/test/Shared/test.base.netstandard.props b/test/Shared/test.base.netstandard.props
new file mode 100644
index 00000000000..dbc62465582
--- /dev/null
+++ b/test/Shared/test.base.netstandard.props
@@ -0,0 +1,21 @@
+<Project>
+
+  <PropertyGroup>
+    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
+  </PropertyGroup>
+
+  <Import Project="../../src/Shared/base.netstandard.props" />
+
+  <PropertyGroup>
+
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
+    <PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
+  </ItemGroup>
+
+</Project>
diff --git a/test/Shared/test.base.props b/test/Shared/test.base.props
index f96ca9136c8..a1a452896c4 100644
--- a/test/Shared/test.base.props
+++ b/test/Shared/test.base.props
@@ -9,9 +9,9 @@
   <Import Project="../../src/Shared/base.props" />
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
-    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
-    <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
+    <PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
   </ItemGroup>
 
 </Project>