Cleanup tests to perform fewer deployments (#154)

* Cleanup tests to perform fewer deployments
This commit is contained in:
Pranav K 2017-06-22 13:12:24 -07:00 committed by GitHub
parent 8d095d3af6
commit cd91ab986c
45 changed files with 1504 additions and 754 deletions

View File

@ -1,45 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class ApplicationConsumingPrecompiledViews
: IClassFixture<ApplicationConsumingPrecompiledViews.ApplicationConsumingPrecompiledViewsFixture>
{
public ApplicationConsumingPrecompiledViews(ApplicationConsumingPrecompiledViewsFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork(RuntimeFlavor flavor)
{
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync("Manage/Home", Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt", response);
}
}
public class ApplicationConsumingPrecompiledViewsFixture : ApplicationTestFixture
{
public ApplicationConsumingPrecompiledViewsFixture()
: base("ApplicationUsingPrecompiledViewClassLibrary")
{
}
}
}
}

View File

@ -0,0 +1,42 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationConsumingPrecompiledViews_CoreCLR
: LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<ApplicationUsingPrecompiledViewClassLibrary.Startup>>
{
public ApplicationConsumingPrecompiledViews_CoreCLR(
CoreCLRApplicationTestFixture<ApplicationUsingPrecompiledViewClassLibrary.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork()
{
// Arrange
using (StartLog(out var loggerFactory))
{
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Manage/Home",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt", response);
}
}
}
}

View File

@ -0,0 +1,45 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationConsumingPrecompiledViews_Desktop
: LoggedTest, IClassFixture<DesktopApplicationTestFixture<ApplicationUsingPrecompiledViewClassLibrary.Startup>>
{
public ApplicationConsumingPrecompiledViews_Desktop(
DesktopApplicationTestFixture<ApplicationUsingPrecompiledViewClassLibrary.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Manage/Home",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationConsumingPrecompiledViews.Manage.Home.Index.txt", response);
}
}
}
}

View File

@ -1,66 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class ApplicationUsingRelativePathsTest :
IClassFixture<ApplicationUsingRelativePathsTest.ApplicationUsingRelativePathsTestFixture>
{
public ApplicationUsingRelativePathsTest(ApplicationUsingRelativePathsTestFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForViewsUsingRelativePath(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.Index.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.About.txt", response);
}
}
public class ApplicationUsingRelativePathsTestFixture : ApplicationTestFixture
{
public ApplicationUsingRelativePathsTestFixture()
: base("ApplicationUsingRelativePaths")
{
}
}
}
}

View File

@ -0,0 +1,60 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationUsingRelativePathsTest_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<ApplicationUsingRelativePaths.Startup>>
{
public ApplicationUsingRelativePathsTest_CoreCLR(
CoreCLRApplicationTestFixture<ApplicationUsingRelativePaths.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_WorksForViewsUsingRelativePath()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.Index.txt", response);
}
}
[Fact]
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.About.txt", response);
}
}
}
}

View File

@ -0,0 +1,63 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationUsingRelativePathsTest_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<ApplicationUsingRelativePaths.Startup>>
{
public ApplicationUsingRelativePathsTest_Desktop(
DesktopApplicationTestFixture<ApplicationUsingRelativePaths.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_WorksForViewsUsingRelativePath()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.Index.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.About.txt", response);
}
}
}
}

View File

@ -1,68 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class ApplicationWithConfigureMvcTest
: IClassFixture<ApplicationWithConfigureMvcTest.ApplicationWithConfigureMvcFixture>
{
public ApplicationWithConfigureMvcTest(ApplicationWithConfigureMvcFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/ViewWithPreprocessor",
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent(
"ApplicationWithConfigureMvc.Home.ViewWithPreprocessor.txt",
response);
}
}
public class ApplicationWithConfigureMvcFixture : ApplicationTestFixture
{
public ApplicationWithConfigureMvcFixture()
: base("ApplicationWithConfigureMvc")
{
}
}
}
}

View File

@ -0,0 +1,62 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationWithConfigureMvcTest_CoreCLR
: LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<ApplicationWithConfigureStartup.Startup>>
{
public ApplicationWithConfigureMvcTest_CoreCLR(
CoreCLRApplicationTestFixture<ApplicationWithConfigureStartup.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_RunsConfiguredCompilationCallbacks()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
}
}
[Fact]
public async Task Precompilation_UsesConfiguredParseOptions()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/ViewWithPreprocessor",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent(
"ApplicationWithConfigureMvc.Home.ViewWithPreprocessor.txt",
response);
}
}
}
}

View File

@ -0,0 +1,65 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationWithConfigureMvcTest_Desktop
: LoggedTest, IClassFixture<DesktopApplicationTestFixture<ApplicationWithConfigureStartup.Startup>>
{
public ApplicationWithConfigureMvcTest_Desktop(
DesktopApplicationTestFixture<ApplicationWithConfigureStartup.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_RunsConfiguredCompilationCallbacks()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_UsesConfiguredParseOptions()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/ViewWithPreprocessor",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent(
"ApplicationWithConfigureMvc.Home.ViewWithPreprocessor.txt",
response);
}
}
}
}

View File

@ -0,0 +1,105 @@
// 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.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationWithCustomInputFilesTest_CoreCLR
: LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<ApplicationWithCustomInputFiles.Startup>>
{
public ApplicationWithCustomInputFilesTest_CoreCLR(
CoreCLRApplicationTestFixture<ApplicationWithCustomInputFiles.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task ApplicationWithCustomInputFiles_Works()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var expectedText = "Hello Index!";
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
Assert.Equal(expectedText, response.Trim());
}
}
[Fact]
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var expectedViews = new[]
{
"/Views/Home/About.cshtml",
"/Views/Home/Index.cshtml",
};
// Act
var response2 = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/GetPrecompiledResourceNames",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
var actual = response2.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.OrderBy(p => p, StringComparer.OrdinalIgnoreCase);
Assert.Equal(expectedViews, actual);
}
}
[Fact]
public async Task MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var viewsNotPublished = new[]
{
"Index.cshtml",
"About.cshtml",
};
var viewsPublished = new[]
{
"NotIncluded.cshtml",
};
var viewsDirectory = Path.Combine(deployment.ContentRoot, "Views", "Home");
// Act & Assert
foreach (var file in viewsPublished)
{
var filePath = Path.Combine(viewsDirectory, file);
Assert.True(File.Exists(filePath), $"{filePath} was not published.");
}
foreach (var file in viewsNotPublished)
{
var filePath = Path.Combine(viewsDirectory, file);
Assert.False(File.Exists(filePath), $"{filePath} was published.");
}
}
}
}
}

View File

@ -5,62 +5,64 @@ using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationWithCustomInputFilesTest
: IClassFixture<ApplicationWithCustomInputFilesTest.ApplicationWithCustomInputFilesTestFixture>
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationWithCustomInputFilesTest_Desktop
: LoggedTest, IClassFixture<DesktopApplicationTestFixture<ApplicationWithCustomInputFiles.Startup>>
{
private const string ApplicationName = "ApplicationWithCustomInputFiles";
public ApplicationWithCustomInputFilesTest(ApplicationWithCustomInputFilesTestFixture fixture)
public ApplicationWithCustomInputFilesTest_Desktop(
DesktopApplicationTestFixture<ApplicationWithCustomInputFiles.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task ApplicationWithCustomInputFiles_Works(RuntimeFlavor flavor)
[ConditionalFact]
public async Task ApplicationWithCustomInputFiles_Works()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var expectedText = "Hello Index!";
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
Assert.Equal(expectedText, response.Trim());
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled(RuntimeFlavor flavor)
[ConditionalFact]
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var expectedViews = new[]
{
"/Views/Home/About.cshtml",
"/Views/Home/Index.cshtml",
};
{
"/Views/Home/About.cshtml",
"/Views/Home/Index.cshtml",
};
// Act
var response2 = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/GetPrecompiledResourceNames",
Fixture.Logger);
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
var actual = response2.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
@ -69,13 +71,13 @@ namespace FunctionalTests
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled(RuntimeFlavor flavor)
[ConditionalFact]
public async Task MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var viewsNotPublished = new[]
{
"Index.cshtml",
@ -86,7 +88,7 @@ namespace FunctionalTests
{
"NotIncluded.cshtml",
};
var viewsDirectory = Path.Combine(deployment.DeploymentResult.ContentRoot, "Views", "Home");
var viewsDirectory = Path.Combine(deployment.ContentRoot, "Views", "Home");
// Act & Assert
foreach (var file in viewsPublished)
@ -102,13 +104,5 @@ namespace FunctionalTests
}
}
}
public class ApplicationWithCustomInputFilesTestFixture : ApplicationTestFixture
{
public ApplicationWithCustomInputFilesTestFixture()
: base(ApplicationWithCustomInputFilesTest.ApplicationName)
{
}
}
}
}

View File

@ -0,0 +1,50 @@
// 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.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
namespace FunctionalTests
{
public class ApplicationWithParseErrorsTest_CoreCLR
: IClassFixture<CoreCLRApplicationTestFixture<ApplicationWithParseErrors.Startup>>
{
public ApplicationWithParseErrorsTest_CoreCLR(CoreCLRApplicationTestFixture<ApplicationWithParseErrors.Startup> fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task PublishingPrintsParseErrors()
{
// Arrange
var applicationPath = ApplicationPaths.GetTestAppDirectory("ApplicationWithParseErrors");
var indexPath = Path.Combine(applicationPath, "Views", "Home", "Index.cshtml");
var viewImportsPath = Path.Combine(applicationPath, "Views", "Home", "About.cshtml");
var expectedErrors = new[]
{
indexPath + " (0): The code block is missing a closing \"}\" character. Make sure you have a matching \"}\" character for all the \"{\" characters within this block, and that none of the \"}\" characters are being interpreted as markup.",
viewImportsPath + " (1): A space or line break was encountered after the \"@\" character. Only valid identifiers, keywords, comments, \"(\" and \"{\" are valid at the start of a code block and they must occur immediately following \"@\" with no space in between.",
};
var testSink = new TestSink();
var loggerFactory = new TestLoggerFactory(testSink, enabled: true);
// Act
await Assert.ThrowsAsync<Exception>(() => Fixture.CreateDeploymentAsync(loggerFactory));
// Assert
var logs = testSink.Writes.Select(w => w.State.ToString().Trim()).ToList();
foreach (var expectedError in expectedErrors)
{
Assert.Contains(logs, log => log.Contains(expectedError));
}
}
}
}

View File

@ -5,20 +5,26 @@ using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
namespace FunctionalTests
{
public class ApplicationWithParseErrorsTest
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationWithParseErrorsTest_Desktop
: IClassFixture<DesktopApplicationTestFixture<ApplicationWithParseErrors.Startup>>
{
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
public ApplicationWithParseErrorsTest_Desktop(DesktopApplicationTestFixture<ApplicationWithParseErrors.Startup> fixture)
{
Fixture = fixture;
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task PublishingPrintsParseErrors(RuntimeFlavor flavor)
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task PublishingPrintsParseErrors()
{
// Arrange
var applicationPath = ApplicationPaths.GetTestAppDirectory("ApplicationWithParseErrors");
@ -31,19 +37,16 @@ namespace FunctionalTests
};
var testSink = new TestSink();
var deploymentParameters = ApplicationTestFixture.GetDeploymentParameters(applicationPath, flavor);
var loggerFactory = new TestLoggerFactory(testSink, enabled: true);
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
// Act
await Assert.ThrowsAsync<Exception>(() => deployer.DeployAsync());
// Assert
var logs = testSink.Writes.Select(w => w.State.ToString().Trim()).ToList();
foreach (var expectedError in expectedErrors)
{
Assert.Contains(logs, log => log.Contains(expectedError));
}
// Act
await Assert.ThrowsAsync<Exception>(() => Fixture.CreateDeploymentAsync(loggerFactory));
// Assert
var logs = testSink.Writes.Select(w => w.State.ToString().Trim()).ToList();
foreach (var expectedError in expectedErrors)
{
Assert.Contains(logs, log => log.Contains(expectedError));
}
}
}

View File

@ -1,69 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Xunit;
namespace FunctionalTests
{
public class TagHelperTest : IClassFixture<TagHelperTest.ApplicationWithTagHelpersFixture>
{
public TagHelperTest(ApplicationWithTagHelpersFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData ApplicationWithTagHelpersData
{
get
{
var urls = new[]
{
"ClassLibraryTagHelper",
"LocalTagHelper",
};
var data = new TheoryData<string, RuntimeFlavor>();
foreach (var runtimeFlavor in RuntimeFlavors.SupportedFlavors)
{
foreach(var url in urls)
{
data.Add(url, runtimeFlavor);
}
}
return data;
}
}
[Theory]
[MemberData(nameof(ApplicationWithTagHelpersData))]
public async Task Precompilation_WorksForViewsThatUseTagHelpers(string url, RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
$"Home/{url}",
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.{url}.txt", response);
}
}
public class ApplicationWithTagHelpersFixture : ApplicationTestFixture
{
public ApplicationWithTagHelpersFixture()
: base("ApplicationWithTagHelpers")
{
}
}
}
}

View File

@ -0,0 +1,60 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationWithTagHelpersTest_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<ApplicationWithTagHelpers.Startup>>
{
public ApplicationWithTagHelpersTest_CoreCLR(
CoreCLRApplicationTestFixture<ApplicationWithTagHelpers.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_WorksForViewsThatUseTagHelpersFromProjectReferences()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/ClassLibraryTagHelper",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.ClassLibraryTagHelper.txt", response);
}
}
[Fact]
public async Task Precompilation_WorksForViewsThatUseTagHelpersFromCurrentProject()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/LocalTagHelper",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.LocalTagHelper.txt", response);
}
}
}
}

View File

@ -0,0 +1,63 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationWithTagHelpersTest_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<ApplicationWithTagHelpers.Startup>>
{
public ApplicationWithTagHelpersTest_Desktop(
DesktopApplicationTestFixture<ApplicationWithTagHelpers.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_WorksForViewsThatUseTagHelpersFromProjectReferences()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/ClassLibraryTagHelper",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.ClassLibraryTagHelper.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksForViewsThatUseTagHelpersFromCurrentProject()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/LocalTagHelper",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.LocalTagHelper.txt", response);
}
}
}
}

View File

@ -6,6 +6,8 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
<DefineConstants>$(DefineConstants);__remove_this_to__GENERATE_BASELINES</DefineConstants>
<DefineConstants Condition="'$(GenerateBaseLines)'=='true'">$(DefineConstants);GENERATE_BASELINES</DefineConstants>
<SignAssembly>false</SignAssembly>
<PublicSign>false</PublicSign>
</PropertyGroup>
<ItemGroup>
@ -23,4 +25,18 @@
<PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\testapps\ApplicationUsingPrecompiledViewClassLibrary\ApplicationUsingPrecompiledViewClassLibrary.csproj" />
<ProjectReference Include="..\..\testapps\ApplicationUsingRelativePaths\ApplicationUsingRelativePaths.csproj" />
<ProjectReference Include="..\..\testapps\ApplicationWithConfigureMvc\ApplicationWithConfigureMvc.csproj" />
<ProjectReference Include="..\..\testapps\ApplicationWithCustomInputFiles\ApplicationWithCustomInputFiles.csproj" />
<ProjectReference Include="..\..\testapps\ApplicationWithParseErrors\ApplicationWithParseErrors.csproj" />
<ProjectReference Include="..\..\testapps\ApplicationWithTagHelpers\ApplicationWithTagHelpers.csproj" />
<ProjectReference Include="..\..\testapps\PublishWithEmbedViewSources\PublishWithEmbedViewSources.csproj" />
<ProjectReference Include="..\..\testapps\RazorPagesApp\RazorPagesApp.csproj" />
<ProjectReference Include="..\..\testapps\SimpleAppWithAssemblyRename\SimpleAppWithAssemblyRename.csproj" />
<ProjectReference Include="..\..\testapps\SimpleApp\SimpleApp.csproj" />
<ProjectReference Include="..\..\testapps\StrongNamedApp\StrongNamedApp.csproj" />
</ItemGroup>
</Project>

View File

@ -3,8 +3,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.Logging;
@ -13,40 +11,36 @@ namespace FunctionalTests
{
public abstract class ApplicationTestFixture : IDisposable
{
public const string DotnetCLITelemetryOptOut = "DOTNET_CLI_TELEMETRY_OPTOUT";
private const string DotnetCLITelemetryOptOut = "DOTNET_CLI_TELEMETRY_OPTOUT";
private readonly object _deploymentLock = new object();
private Task<DeploymentResult> _deploymentTask;
private IApplicationDeployer _deployer;
protected ApplicationTestFixture(string applicationName)
protected ApplicationTestFixture(string applicationName, string applicationPath)
{
ApplicationName = applicationName;
LoggerFactory = CreateLoggerFactory();
Logger = LoggerFactory.CreateLogger($"{ApplicationName}");
ApplicationPath = applicationPath ?? ApplicationPaths.GetTestAppDirectory(applicationName);
}
public string ApplicationName { get; }
public string ApplicationPath => ApplicationPaths.GetTestAppDirectory(ApplicationName);
public string ApplicationPath { get; }
public ILogger Logger { get; private set; }
protected abstract DeploymentParameters GetDeploymentParameters();
public ILoggerFactory LoggerFactory { get; private set; }
public virtual DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor)
{
return GetDeploymentParameters(ApplicationPath, flavor);
}
public static DeploymentParameters GetDeploymentParameters(string applicationPath, RuntimeFlavor flavor)
protected DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor)
{
var telemetryOptOut = new KeyValuePair<string, string>(
DotnetCLITelemetryOptOut,
"1");
var deploymentParameters = new DeploymentParameters(
applicationPath,
ApplicationPath,
ServerType.Kestrel,
flavor,
RuntimeArchitecture.x64)
{
ApplicationName = ApplicationName,
PublishApplicationBeforeDeployment = true,
TargetFramework = flavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
#if DEBUG
@ -67,56 +61,29 @@ namespace FunctionalTests
return deploymentParameters;
}
public virtual ILoggerFactory CreateLoggerFactory()
{
return new LoggerFactory().AddConsole();
}
public void Dispose()
{
if (_deploymentTask?.Status == TaskStatus.RanToCompletion)
{
_deploymentTask.Result.HttpClient?.Dispose();
}
_deployer?.Dispose();
}
private static void TryDeleteDirectory(string directory)
public async Task<DeploymentResult> CreateDeploymentAsync(ILoggerFactory loggerFactory)
{
try
lock (_deploymentLock)
{
Directory.Delete(directory, recursive: true);
}
catch (IOException)
{
// Ignore delete failures.
}
}
public async Task<Deployment> CreateDeploymentAsync(RuntimeFlavor flavor)
{
var deploymentParameters = GetDeploymentParameters(flavor);
var deployer = ApplicationDeployerFactory.Create(deploymentParameters, LoggerFactory);
var deploymentResult = await deployer.DeployAsync();
return new Deployment(deployer, deploymentResult);
}
public class Deployment : IDisposable
{
public Deployment(IApplicationDeployer deployer, DeploymentResult deploymentResult)
{
Deployer = deployer;
DeploymentResult = deploymentResult;
HttpClient = deploymentResult.HttpClient;
if (_deploymentTask == null)
{
var deploymentParameters = GetDeploymentParameters();
_deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory);
_deploymentTask = _deployer.DeployAsync();
}
}
public IApplicationDeployer Deployer { get; }
public HttpClient HttpClient { get; }
public DeploymentResult DeploymentResult { get; }
public void Dispose()
{
Deployer.Dispose();
HttpClient.Dispose();
}
return await _deploymentTask;
}
}
}

View File

@ -0,0 +1,22 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
namespace FunctionalTests
{
public class CoreCLRApplicationTestFixture<TStartup> : ApplicationTestFixture
{
public CoreCLRApplicationTestFixture()
: this(typeof(TStartup).Assembly.GetName().Name, null)
{
}
protected CoreCLRApplicationTestFixture(string applicationName, string applicationPath)
: base(applicationName, applicationPath)
{
}
protected override DeploymentParameters GetDeploymentParameters() => base.GetDeploymentParameters(RuntimeFlavor.CoreClr);
}
}

View File

@ -0,0 +1,22 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
namespace FunctionalTests
{
public class DesktopApplicationTestFixture<TStartup> : ApplicationTestFixture
{
public DesktopApplicationTestFixture()
: this(typeof(TStartup).Assembly.GetName().Name, null)
{
}
protected DesktopApplicationTestFixture(string applicationName, string applicationPath)
: base(applicationName, applicationPath)
{
}
protected override DeploymentParameters GetDeploymentParameters() => base.GetDeploymentParameters(RuntimeFlavor.Clr);
}
}

View File

@ -0,0 +1,62 @@
// 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.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class PublishWithEmbedViewSourcesTest_CoreCLR
: LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<PublishWithEmbedViewSources.Startup>>
{
public PublishWithEmbedViewSourcesTest_CoreCLR(
CoreCLRApplicationTestFixture<PublishWithEmbedViewSources.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_CanEmbedViewSourcesAsResources()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var logger = loggerFactory.CreateLogger(Fixture.ApplicationName);
var expectedViews = new[]
{
"/Areas/TestArea/Views/Home/Index.cshtml",
"/Views/Home/About.cshtml",
"/Views/Home/Index.cshtml",
};
var expectedText = "Hello Index!";
// Act - 1
var response1 = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/Index",
logger);
// Assert - 1
Assert.Equal(expectedText, response1.Trim());
// Act - 2
var response2 = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/GetPrecompiledResourceNames",
logger);
// Assert - 2
var actual = response2.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.OrderBy(p => p, StringComparer.OrdinalIgnoreCase);
Assert.Equal(expectedViews, actual);
}
}
}
}

View File

@ -2,36 +2,38 @@
// 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.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class PublishWithEmbedViewSourcesTest
: IClassFixture<PublishWithEmbedViewSourcesTest.PublishWithEmbedViewSourcesTestFixture>
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class PublishWithEmbedViewSourcesTest_Desktop
: LoggedTest, IClassFixture<DesktopApplicationTestFixture<PublishWithEmbedViewSources.Startup>>
{
private const string ApplicationName = "PublishWithEmbedViewSources";
public PublishWithEmbedViewSourcesTest(PublishWithEmbedViewSourcesTestFixture fixture)
public PublishWithEmbedViewSourcesTest_Desktop(
DesktopApplicationTestFixture<PublishWithEmbedViewSources.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_CanEmbedViewSourcesAsResources(RuntimeFlavor flavor)
[ConditionalFact]
public async Task Precompilation_CanEmbedViewSourcesAsResources()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var logger = loggerFactory.CreateLogger(Fixture.ApplicationName);
var expectedViews = new[]
{
"/Areas/TestArea/Views/Home/Index.cshtml",
@ -43,7 +45,7 @@ namespace FunctionalTests
// Act - 1
var response1 = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/Index",
Fixture.Logger);
logger);
// Assert - 1
Assert.Equal(expectedText, response1.Trim());
@ -51,7 +53,7 @@ namespace FunctionalTests
// Act - 2
var response2 = await deployment.HttpClient.GetStringWithRetryAsync(
"Home/GetPrecompiledResourceNames",
Fixture.Logger);
logger);
// Assert - 2
var actual = response2.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
@ -59,13 +61,5 @@ namespace FunctionalTests
Assert.Equal(expectedViews, actual);
}
}
public class PublishWithEmbedViewSourcesTestFixture : ApplicationTestFixture
{
public PublishWithEmbedViewSourcesTestFixture()
: base(PublishWithEmbedViewSourcesTest.ApplicationName)
{
}
}
}
}

View File

@ -3,131 +3,132 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class RazorPagesAppTest : IClassFixture<RazorPagesAppTest.TestFixture>
public class RazorPagesAppTest_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<RazorPagesApp.Startup>>
{
public RazorPagesAppTest(TestFixture fixture)
public RazorPagesAppTest_CoreCLR(
CoreCLRApplicationTestFixture<RazorPagesApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForIndexPage_UsingFolderName(RuntimeFlavor flavor)
[Fact]
public async Task Precompilation_WorksForIndexPage_UsingFolderName()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/",
Fixture.Logger);
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.Index.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForIndexPage_UsingFileName(RuntimeFlavor flavor)
[Fact]
public async Task Precompilation_WorksForIndexPage_UsingFileName()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/Index",
Fixture.Logger);
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.Index.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForPageWithModel(RuntimeFlavor flavor)
[Fact]
public async Task Precompilation_WorksForPageWithModel()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/PageWithModel?person=Dan",
Fixture.Logger);
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.PageWithModel.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForPageWithRoute(RuntimeFlavor flavor)
[Fact]
public async Task Precompilation_WorksForPageWithRoute()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/PageWithRoute/Dan",
Fixture.Logger);
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.PageWithRoute.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForPageInNestedFolder(RuntimeFlavor flavor)
[Fact]
public async Task Precompilation_WorksForPageInNestedFolder()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/Nested1/Nested2/PageWithTagHelper",
Fixture.Logger);
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.Nested1.Nested2.PageWithTagHelper.txt", response);
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksWithPageConventions(RuntimeFlavor flavor)
[Fact]
public async Task Precompilation_WorksWithPageConventions()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await RetryHelper.RetryRequest(
() => deployment.HttpClient.GetAsync("/Auth/Index"),
Fixture.Logger,
retryCount: 5);
() => deployment.HttpClient.GetAsync("/Auth/Index"),
loggerFactory.CreateLogger(Fixture.ApplicationName),
retryCount: 5);
// Assert
Assert.Equal("/Login?ReturnUrl=%2FAuth%2FIndex", response.RequestMessage.RequestUri.PathAndQuery);
}
}
public class TestFixture : ApplicationTestFixture
{
public TestFixture()
: base("RazorPagesApp")
{
}
}
}
}

View File

@ -0,0 +1,137 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class RazorPagesAppTest_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<RazorPagesApp.Startup>>
{
public RazorPagesAppTest_Desktop(
DesktopApplicationTestFixture<RazorPagesApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_WorksForIndexPage_UsingFolderName()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.Index.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksForIndexPage_UsingFileName()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/Index",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.Index.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksForPageWithModel()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/PageWithModel?person=Dan",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.PageWithModel.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksForPageWithRoute()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/PageWithRoute/Dan",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.PageWithRoute.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksForPageInNestedFolder()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
"/Nested1/Nested2/PageWithTagHelper",
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("RazorPages.Nested1.Nested2.PageWithTagHelper.txt", response);
}
}
[ConditionalFact]
public async Task Precompilation_WorksWithPageConventions()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await RetryHelper.RetryRequest(
() => deployment.HttpClient.GetAsync("/Auth/Index"),
loggerFactory.CreateLogger(Fixture.ApplicationName),
retryCount: 5);
// Assert
Assert.Equal("/Login?ReturnUrl=%2FAuth%2FIndex", response.RequestMessage.RequestUri.PathAndQuery);
}
}
}
}

View File

@ -1,39 +0,0 @@
// 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.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Xunit;
namespace FunctionalTests
{
public static class RuntimeFlavors
{
public static IEnumerable<RuntimeFlavor> SupportedFlavors
{
get
{
yield return RuntimeFlavor.CoreClr;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
yield return RuntimeFlavor.Clr;
}
}
}
public static TheoryData SupportedFlavorsTheoryData
{
get
{
var theory = new TheoryData<RuntimeFlavor>();
foreach (var item in SupportedFlavors)
{
theory.Add(item);
}
return theory;
}
}
}
}

View File

@ -1,47 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class SimpleAppTest : IClassFixture<SimpleAppTest.SimpleAppTestFixture>
{
public SimpleAppTest(SimpleAppTestFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("SimpleAppTest.Home.Index.txt", response);
}
}
public class SimpleAppTestFixture : ApplicationTestFixture
{
public SimpleAppTestFixture()
: base("SimpleApp")
{
}
}
}
}

View File

@ -0,0 +1,42 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class SimpleAppTest_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<SimpleApp.Startup>>
{
public SimpleAppTest_CoreCLR(
CoreCLRApplicationTestFixture<SimpleApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_WorksForSimpleApps()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("SimpleAppTest.Home.Index.txt", response);
}
}
}
}

View File

@ -0,0 +1,45 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class SimpleAppTest_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<SimpleApp.Startup>>
{
public SimpleAppTest_Desktop(
DesktopApplicationTestFixture<SimpleApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_WorksForSimpleApps()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("SimpleAppTest.Home.Index.txt", response);
}
}
}
}

View File

@ -1,54 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class SimpleAppWithAssemblyRenameTest : IClassFixture<SimpleAppWithAssemblyRenameTest.TestFixture>
{
public SimpleAppWithAssemblyRenameTest(TestFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("SimpleAppWithAssemblyRenameTest.Home.Index.txt", response);
}
}
public class TestFixture : ApplicationTestFixture
{
public TestFixture()
: base("SimpleAppWithAssemblyRename")
{
}
public override DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor)
{
var parameters = base.GetDeploymentParameters(flavor);
parameters.ApplicationName = "NewAssemblyName";
return parameters;
}
}
}
}

View File

@ -0,0 +1,52 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class SimpleAppWithAssemblyRenameTest_CoreCLR :
LoggedTest, IClassFixture<SimpleAppWithAssemblyRenameTest_CoreCLR.TestFixture>
{
public SimpleAppWithAssemblyRenameTest_CoreCLR(
TestFixture fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_WorksForSimpleApps()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("SimpleAppWithAssemblyRenameTest.Home.Index.txt", response);
}
}
public class TestFixture : CoreCLRApplicationTestFixture<SimpleAppWithAssemblyRename.Startup>
{
public TestFixture()
: base(
typeof(SimpleAppWithAssemblyRename.Startup).Assembly.GetName().Name,
ApplicationPaths.GetTestAppDirectory(nameof(SimpleAppWithAssemblyRename)))
{
}
}
}
}

View File

@ -0,0 +1,55 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class SimpleAppWithAssemblyRenameTest_Desktop :
LoggedTest, IClassFixture<SimpleAppWithAssemblyRenameTest_Desktop.TestFixture>
{
public SimpleAppWithAssemblyRenameTest_Desktop(
TestFixture fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_WorksForSimpleApps()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("SimpleAppWithAssemblyRenameTest.Home.Index.txt", response);
}
}
public class TestFixture : DesktopApplicationTestFixture<SimpleAppWithAssemblyRename.Startup>
{
public TestFixture()
: base(
typeof(SimpleAppWithAssemblyRename.Startup).Assembly.GetName().Name,
ApplicationPaths.GetTestAppDirectory(nameof(SimpleAppWithAssemblyRename)))
{
}
}
}
}

View File

@ -1,43 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Xunit;
namespace FunctionalTests
{
public class SimpleAppX86DesktopOnlyTest : IClassFixture<SimpleAppX86DesktopOnlyTest.SimpleAppX86DesktopOnlyFixture>
{
public SimpleAppX86DesktopOnlyTest(SimpleAppX86DesktopOnlyFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact(Skip = "https://github.com/aspnet/MvcPrecompilation/issues/134")]
public async Task Precompilation_WorksForSimpleApps()
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(RuntimeFlavor.Clr))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("SimpleAppX86DesktopOnly.Home.Index.txt", response);
}
}
public class SimpleAppX86DesktopOnlyFixture : ApplicationTestFixture
{
public SimpleAppX86DesktopOnlyFixture()
: base("SimpleAppX86DesktopOnly")
{
}
}
}
}

View File

@ -1,47 +0,0 @@
// 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 Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class StrongNamedAppTest : IClassFixture<StrongNamedAppTest.StrongNamedAppFixture>
{
public StrongNamedAppTest(StrongNamedAppFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.DeploymentResult.ApplicationBaseUri,
Fixture.Logger);
// Assert
TestEmbeddedResource.AssertContent("StrongNamedApp.Home.Index.txt", response);
}
}
public class StrongNamedAppFixture : ApplicationTestFixture
{
public StrongNamedAppFixture()
: base("StrongNamedApp")
{
}
}
}
}

View File

@ -0,0 +1,42 @@
// 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 Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class StrongNamedAppTest_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<StrongNamedApp.Startup>>
{
public StrongNamedAppTest_CoreCLR(
CoreCLRApplicationTestFixture<StrongNamedApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("StrongNamedApp.Home.Index.txt", response);
}
}
}
}

View File

@ -0,0 +1,45 @@
// 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 Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class StrongNamedAppTest_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<StrongNamedApp.Startup>>
{
public StrongNamedAppTest_Desktop(
DesktopApplicationTestFixture<StrongNamedApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
TestEmbeddedResource.AssertContent("StrongNamedApp.Home.Index.txt", response);
}
}
}
}

View File

@ -1,77 +0,0 @@
// 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.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace FunctionalTests
{
public class ViewCompilationOptionsTest : IClassFixture<ViewCompilationOptionsTest.TestFixture>
{
public ViewCompilationOptionsTest(TestFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_PreventsRefAssembliesFromBeingPublished(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
// Act & Assert
Assert.False(Directory.Exists(Path.Combine(deployment.DeploymentResult.ContentRoot, "refs")));
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task PublishingWithOption_AllowsPublishingRefAssemblies(RuntimeFlavor flavor)
{
// Arrange
var deploymentParameters = Fixture.GetDeploymentParameters(flavor);
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("MvcRazorExcludeRefAssembliesFromPublish", "false"));
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, Fixture.LoggerFactory))
{
// Act
var deploymentResult = await deployer.DeployAsync();
// Assert
Assert.True(Directory.Exists(Path.Combine(deploymentResult.ContentRoot, "refs")));
}
}
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_PublishesPdbsToOutputDirectory(RuntimeFlavor flavor)
{
// Arrange
using (var deployment = await Fixture.CreateDeploymentAsync(flavor))
{
var pdbPath = Path.Combine(deployment.DeploymentResult.ContentRoot, Fixture.ApplicationName + ".PrecompiledViews.pdb");
// Act & Assert
Assert.True(File.Exists(pdbPath), $"PDB at {pdbPath} was not found.");
}
}
public class TestFixture : ApplicationTestFixture
{
public TestFixture()
: base("SimpleApp")
{
}
}
}
}

View File

@ -0,0 +1,93 @@
// 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.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class ViewCompilationOptions_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<SimpleApp.Startup>>
{
public ViewCompilationOptions_CoreCLR(
CoreCLRApplicationTestFixture<SimpleApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task Precompilation_PreventsRefAssembliesFromBeingPublished()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act & Assert
Assert.False(Directory.Exists(Path.Combine(deployment.ContentRoot, "refs")));
}
}
[Fact]
public async Task Precompilation_PublishesPdbsToOutputDirectory()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var pdbPath = Path.Combine(deployment.ContentRoot, Fixture.ApplicationName + ".PrecompiledViews.pdb");
// Act & Assert
Assert.True(File.Exists(pdbPath), $"PDB at {pdbPath} was not found.");
}
}
}
public class ViewCompilationOptions_CoreCLR_ScenarioRefAssembliesDoNotGetPublished :
LoggedTest, IClassFixture<ViewCompilationOptions_CoreCLR_ScenarioRefAssembliesDoNotGetPublished.TestFixture>
{
public ViewCompilationOptions_CoreCLR_ScenarioRefAssembliesDoNotGetPublished(
TestFixture fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task PublishingWithOption_AllowsPublishingRefAssemblies()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act & Assert
Assert.True(Directory.Exists(Path.Combine(deployment.ContentRoot, "refs")));
}
}
public class TestFixture : CoreCLRApplicationTestFixture<SimpleApp.Startup>
{
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("MvcRazorExcludeRefAssembliesFromPublish", "false"));
return deploymentParameters;
}
}
}
}

View File

@ -0,0 +1,98 @@
// 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.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ViewCompilationOptions_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<SimpleApp.Startup>>
{
public ViewCompilationOptions_Desktop(
DesktopApplicationTestFixture<SimpleApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task Precompilation_PreventsRefAssembliesFromBeingPublished()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act & Assert
Assert.False(Directory.Exists(Path.Combine(deployment.ContentRoot, "refs")));
}
}
[ConditionalFact]
public async Task Precompilation_PublishesPdbsToOutputDirectory()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
var pdbPath = Path.Combine(deployment.ContentRoot, Fixture.ApplicationName + ".PrecompiledViews.pdb");
// Act & Assert
Assert.True(File.Exists(pdbPath), $"PDB at {pdbPath} was not found.");
}
}
}
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ViewCompilationOptions_Desktop_ScenarioRefAssembliesDoNotGetPublished :
LoggedTest, IClassFixture<ViewCompilationOptions_Desktop_ScenarioRefAssembliesDoNotGetPublished.TestFixture>
{
public ViewCompilationOptions_Desktop_ScenarioRefAssembliesDoNotGetPublished(
TestFixture fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task PublishingWithOption_AllowsPublishingRefAssemblies()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act & Assert
Assert.True(Directory.Exists(Path.Combine(deployment.ContentRoot, "refs")));
}
}
public class TestFixture : DesktopApplicationTestFixture<SimpleApp.Startup>
{
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("MvcRazorExcludeRefAssembliesFromPublish", "false"));
return deploymentParameters;
}
}
}
}

View File

@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace ApplicationWithTagHelpers
namespace ApplicationUsingPrecompiledViewClassLibrary
{
public class Program
{

View File

@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace ApplicationWithTagHelpers
namespace ApplicationUsingPrecompiledViewClassLibrary
{
public class Startup
{

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
namespace SimpleApp.Controllers
namespace SimpleAppDesktopOnly.Controllers
{
public class HomeController : Controller
{

View File

@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace SimpleApp
namespace SimpleAppDesktopOnly
{
public class Program
{

View File

@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace SimpleApp
namespace SimpleAppDesktopOnly
{
public class Startup
{

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - SimpleApp</title>
<title>@ViewData["Title"] - SimpleAppDesktopOnly</title>
<environment names="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
@ -26,7 +26,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">SimpleApp</a>
<a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">SimpleAppDesktopOnly</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
@ -41,7 +41,7 @@
@RenderBody()
<hr />
<footer>
<p>&copy; 2016 - SimpleApp</p>
<p>&copy; 2016 - SimpleAppDesktopOnly</p>
</footer>
</div>

View File

@ -1,2 +1,2 @@
@using SimpleApp
@using SimpleAppDesktopOnly
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers