diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs index a756360999..6ba9ac9be8 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs @@ -615,22 +615,6 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.Equal(firstAssemblyBytes, secondAssemblyBytes); } - [Fact] - [InitializeTestProject("SimpleMvc21")] - public async Task Building_NETCoreApp21TargetingProject() - { - TargetFramework = "netcoreapp2.1"; - - // Build - var result = await DotnetMSBuild("Build"); - - Assert.BuildPassed(result); - Assert.FileExists(result, OutputPath, "SimpleMvc21.dll"); - Assert.FileExists(result, OutputPath, "SimpleMvc21.pdb"); - Assert.FileExists(result, OutputPath, "SimpleMvc21.Views.dll"); - Assert.FileExists(result, OutputPath, "SimpleMvc21.Views.pdb"); - } - [Fact] [InitializeTestProject("SimpleMvc21")] public async Task Building_WorksWhenMultipleRazorConfigurationsArePresent() diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs new file mode 100644 index 0000000000..1da9401aba --- /dev/null +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + public class BuildIntegrationTest21 : MSBuildIntegrationTestBase, IClassFixture + { + public BuildIntegrationTest21(LegacyBuildServerTestFixture buildServer) + : base(buildServer) + { + } + + [Fact] + [InitializeTestProject("SimpleMvc21")] + public async Task Building_NETCoreApp21TargetingProject() + { + TargetFramework = "netcoreapp2.1"; + + // Build + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + Assert.FileExists(result, OutputPath, "SimpleMvc21.dll"); + Assert.FileExists(result, OutputPath, "SimpleMvc21.pdb"); + Assert.FileExists(result, OutputPath, "SimpleMvc21.Views.dll"); + Assert.FileExists(result, OutputPath, "SimpleMvc21.Views.pdb"); + } + } +} diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs new file mode 100644 index 0000000000..e3e0b890b4 --- /dev/null +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + public class BuildIntegrationTest22 : MSBuildIntegrationTestBase, IClassFixture + { + public BuildIntegrationTest22(LegacyBuildServerTestFixture buildServer) + : base(buildServer) + { + } + + [Fact] + [InitializeTestProject("SimpleMvc22")] + public async Task Building_NETCoreApp22TargetingProject() + { + TargetFramework = "netcoreapp2.2"; + + // Build + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + Assert.FileExists(result, OutputPath, "SimpleMvc22.dll"); + Assert.FileExists(result, OutputPath, "SimpleMvc22.pdb"); + Assert.FileExists(result, OutputPath, "SimpleMvc22.Views.dll"); + Assert.FileExists(result, OutputPath, "SimpleMvc22.Views.pdb"); + } + } +} diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixture.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixture.cs index 5c1a17e5c7..52c242cc31 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixture.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixture.cs @@ -2,60 +2,27 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; -using System.Threading; using Microsoft.AspNetCore.Razor.Tools; -using Microsoft.CodeAnalysis; -using Moq; namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { - public class BuildServerTestFixture : IDisposable + /// + /// A test fixture that initializes a server as part of it's ctor. + /// Note that this fixture will always initialize a server of the current version since it + /// invokes the ServerConnection API from the referenced rzc. + /// + public class BuildServerTestFixture : BuildServerTestFixtureBase, IDisposable { - private static readonly TimeSpan _defaultShutdownTimeout = TimeSpan.FromSeconds(60); - public BuildServerTestFixture() : this(Guid.NewGuid().ToString()) { } internal BuildServerTestFixture(string pipeName) + : base(pipeName) { - PipeName = pipeName; - - if (!ServerConnection.TryCreateServerCore(Environment.CurrentDirectory, PipeName, out var processId)) + if (!ServerConnection.TryCreateServerCore(Environment.CurrentDirectory, pipeName, out _)) { - throw new InvalidOperationException($"Failed to start the build server at pipe {PipeName}."); - } - - ProcessId = processId; - } - - public string PipeName { get; } - - public int? ProcessId { get; } - - public void Dispose() - { - // Shutdown the build server. - using (var cts = new CancellationTokenSource(_defaultShutdownTimeout)) - { - var writer = new StringWriter(); - - cts.Token.Register(() => - { - var output = writer.ToString(); - throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.{Environment.NewLine}Output: {output}."); - }); - - var application = new Application(cts.Token, Mock.Of(), Mock.Of(), (path, properties) => Mock.Of(), writer, writer); - - var exitCode = application.Execute("shutdown", "-w", "-p", PipeName); - if (exitCode != 0) - { - var output = writer.ToString(); - throw new InvalidOperationException( - $"Build server at pipe {PipeName} failed to shutdown with exit code {exitCode}. Output: {output}"); - } + throw new InvalidOperationException($"Failed to start the build server at pipe {pipeName}."); } } } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixtureBase.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixtureBase.cs new file mode 100644 index 0000000000..5275d96e89 --- /dev/null +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildServerTestFixtureBase.cs @@ -0,0 +1,66 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; +using Microsoft.AspNetCore.Razor.Tools; +using Microsoft.CodeAnalysis; +using Moq; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + public abstract class BuildServerTestFixtureBase : IDisposable + { + private static readonly TimeSpan _defaultShutdownTimeout = TimeSpan.FromSeconds(60); + + + protected BuildServerTestFixtureBase(string pipeName) + { + PipeName = pipeName; + } + + public string PipeName { get; } + + public void Dispose() + { + // Shutdown the build server. + using (var cts = new CancellationTokenSource(_defaultShutdownTimeout)) + { + var writer = new StringWriter(); + + cts.Token.Register(() => + { + var output = writer.ToString(); + throw new TimeoutException($"Shutting down the build server at pipe {PipeName} took longer than expected.{Environment.NewLine}Output: {output}."); + }); + + var application = new Application(cts.Token, Mock.Of(), Mock.Of(), (path, properties) => Mock.Of(), writer, writer); + + var args = new List + { + "shutdown", + "-p", + PipeName, + }; + + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + // Workaround for https://github.com/dotnet/corefx/issues/31713. On Linux, the server shuts down but hangs around as defunct process + // We'll send a shutdown request but not wait for it. + args.Add("-w"); + } + + var exitCode = application.Execute(args.ToArray()); + if (exitCode != 0) + { + var output = writer.ToString(); + throw new InvalidOperationException( + $"Build server at pipe {PipeName} failed to shutdown with exit code {exitCode}. Output: {output}"); + } + } + } + } +} diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/LegacyBuildServerTestFixture.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/LegacyBuildServerTestFixture.cs new file mode 100644 index 0000000000..e1da868fea --- /dev/null +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/LegacyBuildServerTestFixture.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + /// + /// A fixture that relies on the build task to spin up the build server. + /// + public class LegacyBuildServerTestFixture : BuildServerTestFixtureBase + { + public LegacyBuildServerTestFixture() + : base(Guid.NewGuid().ToString()) + { + } + } +} diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildIntegrationTestBase.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildIntegrationTestBase.cs index 07ffd2aa9d..a1a9a1b3a8 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildIntegrationTestBase.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/MSBuildIntegrationTestBase.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests private static readonly AsyncLocal _project = new AsyncLocal(); private static readonly AsyncLocal _projectTfm = new AsyncLocal(); - protected MSBuildIntegrationTestBase(BuildServerTestFixture buildServer) + protected MSBuildIntegrationTestBase(BuildServerTestFixtureBase buildServer) { BuildServer = buildServer; } @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests set => _projectTfm.Value = value; } - protected BuildServerTestFixture BuildServer { get; set; } + protected BuildServerTestFixtureBase BuildServer { get; set; } internal Task DotnetMSBuild( string target, diff --git a/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj b/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj index f299f64e13..271eb90067 100644 --- a/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj +++ b/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj @@ -2,6 +2,7 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + true @@ -16,6 +17,7 @@ + diff --git a/src/Razor/test/testassets/LargeProject/LargeProject.csproj b/src/Razor/test/testassets/LargeProject/LargeProject.csproj index 69cada3019..e2cdd3ae0f 100644 --- a/src/Razor/test/testassets/LargeProject/LargeProject.csproj +++ b/src/Razor/test/testassets/LargeProject/LargeProject.csproj @@ -2,6 +2,7 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + true @@ -13,6 +14,10 @@ false + + + + diff --git a/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj b/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj index b9fd86c876..c50aefcff5 100644 --- a/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj +++ b/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj @@ -2,6 +2,7 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + true @@ -13,6 +14,10 @@ false + + + + diff --git a/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj b/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj index 276589868f..160e4d5686 100644 --- a/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj +++ b/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj @@ -2,6 +2,7 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + true @@ -13,6 +14,10 @@ false + + + + diff --git a/src/Razor/test/testassets/SimpleMvc22/Models/ErrorViewModel.cs b/src/Razor/test/testassets/SimpleMvc22/Models/ErrorViewModel.cs new file mode 100644 index 0000000000..b4aa044914 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Models/ErrorViewModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace SimpleMvc.Models +{ + public class ErrorViewModel + { + public string RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } +} \ No newline at end of file diff --git a/src/Razor/test/testassets/SimpleMvc22/Program.cs b/src/Razor/test/testassets/SimpleMvc22/Program.cs new file mode 100644 index 0000000000..25883d6b8b --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Program.cs @@ -0,0 +1,13 @@ + +namespace SimpleMvc +{ + public class Program + { + public static void Main(string[] args) + { + // Just make sure we have a reference to the MVC 2.2 + var t = typeof(Microsoft.AspNetCore.Mvc.IActionResult); + System.Console.WriteLine(t.FullName); + } + } +} diff --git a/src/Razor/test/testassets/SimpleMvc22/SimpleMvc22.csproj b/src/Razor/test/testassets/SimpleMvc22/SimpleMvc22.csproj new file mode 100644 index 0000000000..d21c831710 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/SimpleMvc22.csproj @@ -0,0 +1,26 @@ + + + + + $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + + + + netcoreapp2.2 + + + + + + + false + + + + + + + + diff --git a/src/Razor/test/testassets/SimpleMvc22/Views/Home/About.cshtml b/src/Razor/test/testassets/SimpleMvc22/Views/Home/About.cshtml new file mode 100644 index 0000000000..3674e37a86 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Views/Home/About.cshtml @@ -0,0 +1,7 @@ +@{ + ViewData["Title"] = "About"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Use this area to provide additional information.

diff --git a/src/Razor/test/testassets/SimpleMvc22/Views/Home/Index.cshtml b/src/Razor/test/testassets/SimpleMvc22/Views/Home/Index.cshtml new file mode 100644 index 0000000000..00afab6a0c --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Views/Home/Index.cshtml @@ -0,0 +1,108 @@ +@{ + ViewData["Title"] = "Home Page"; +} + + + + diff --git a/src/Razor/test/testassets/SimpleMvc22/Views/Shared/_Layout.cshtml b/src/Razor/test/testassets/SimpleMvc22/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..1a9473e464 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Views/Shared/_Layout.cshtml @@ -0,0 +1,71 @@ + + + + + + @ViewData["Title"] - SimpleMvc + + + + + + + + + + + + +
+ @RenderBody() +
+
+

© 2017 - SimpleMvc

+
+
+ + + + + + + + + + + + + @RenderSection("Scripts", required: false) + + diff --git a/src/Razor/test/testassets/SimpleMvc22/Views/Shared/_ValidationScriptsPartial.cshtml b/src/Razor/test/testassets/SimpleMvc22/Views/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000000..a699aafa97 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Views/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/src/Razor/test/testassets/SimpleMvc22/Views/_ViewImports.cshtml b/src/Razor/test/testassets/SimpleMvc22/Views/_ViewImports.cshtml new file mode 100644 index 0000000000..477d4ba603 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Views/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using SimpleMvc +@using SimpleMvc.Models +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@namespace SimpleMvc21 diff --git a/src/Razor/test/testassets/SimpleMvc22/Views/_ViewStart.cshtml b/src/Razor/test/testassets/SimpleMvc22/Views/_ViewStart.cshtml new file mode 100644 index 0000000000..a5f10045db --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj b/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj index c32a88baa1..c972b84e4b 100644 --- a/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj +++ b/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj @@ -2,6 +2,7 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + true @@ -18,6 +19,10 @@
+ + + + diff --git a/src/Razor/test/testassets/SimplePages/SimplePages.csproj b/src/Razor/test/testassets/SimplePages/SimplePages.csproj index 362406340c..afc2b469d0 100644 --- a/src/Razor/test/testassets/SimplePages/SimplePages.csproj +++ b/src/Razor/test/testassets/SimplePages/SimplePages.csproj @@ -2,6 +2,7 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + true @@ -13,6 +14,10 @@ false + + + +