// 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.IO; using System.Threading.Tasks; using Microsoft.DotNet.PlatformAbstractions; using Xunit; namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { public class BuildIntegrationTest : MSBuildIntegrationTestBase { [Fact] [InitializeTestProject("SimpleMvc")] public async Task Build_SimpleMvc_CanBuildSuccessfully() { var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true"); Assert.BuildPassed(result); Assert.FileExists(result, OutputPath, "SimpleMvc.dll"); Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.dll"); if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin) { // GetFullPath on OSX doesn't work well in travis. We end up computing a different path than will // end up in the MSBuild logs. Assert.BuildOutputContainsLine(result, $"SimpleMvc -> {Path.Combine(Path.GetFullPath(Project.DirectoryPath), OutputPath, "SimpleMvc.PrecompiledViews.dll")}"); } } [Fact] [InitializeTestProject("SimpleMvc")] public async Task Build_ErrorInGeneratedCode_ReportsMSBuildError() { // Introducing a C# semantic error ReplaceContent("@{ var foo = \"\".Substring(\"bleh\"); }", "Views", "Home", "Index.cshtml"); var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true"); Assert.BuildFailed(result); // Verifying that the error correctly gets mapped to the original source Assert.BuildError(result, "CS1503", location: Path.Combine("Views", "Home", "Index.cshtml") + "(1,27)"); // Compilation failed without creating the views assembly Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.dll"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.dll"); } [Fact] [InitializeTestProject("SimplePages")] public async Task Build_Works_WhenFilesAtDifferentPathsHaveSameNamespaceHierarchy() { var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true"); Assert.BuildPassed(result); Assert.FileExists(result, IntermediateOutputPath, "SimplePages.dll"); Assert.FileExists(result, IntermediateOutputPath, "SimplePages.PrecompiledViews.dll"); } } }