Add test that uses site extension and bundled aspnetcore version (#91)
This commit is contained in:
parent
224c9898c0
commit
80194511f5
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SiteExtensionProjectDirectory>$(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\</SiteExtensionProjectDirectory>
|
<SiteExtensionProjectDirectory>$(RepositoryRoot)src\Microsoft.AspNetCore.AzureAppServices.TestBundle\</SiteExtensionProjectDirectory>
|
||||||
<PublishFeed Condition="$(PublishFeed) == ''">https://dotnet.myget.org/F/aspnetcore-ci-dev/</PublishFeed>
|
<SiteExtensionFeed Condition="$(SiteExtensionFeed) == ''">https://dotnet.myget.org/F/aspnetcore-ci-dev/</SiteExtensionFeed>
|
||||||
<DotnetChannel>master</DotnetChannel>
|
<DotnetChannel>master</DotnetChannel>
|
||||||
<DotnetVersion>coherent</DotnetVersion>
|
<DotnetVersion>coherent</DotnetVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
@ -30,9 +30,9 @@
|
||||||
|
|
||||||
<PushNuGetPackages
|
<PushNuGetPackages
|
||||||
Packages="@(RepositoryNupkgs)"
|
Packages="@(RepositoryNupkgs)"
|
||||||
Feed="$(PublishFeed)"
|
Feed="$(SiteExtensionFeed)"
|
||||||
ApiKey="$(APIKey)"
|
ApiKey="$(APIKey)"
|
||||||
Timeout="6000"/>
|
TimeoutSeconds="600"/>
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
.Create();
|
.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetRequiredEnvironmentVariable(string name)
|
public static string GetRequiredEnvironmentVariable(string name)
|
||||||
{
|
{
|
||||||
var authFile = Environment.GetEnvironmentVariable(name);
|
var authFile = Environment.GetEnvironmentVariable(name);
|
||||||
if (string.IsNullOrEmpty(authFile))
|
if (string.IsNullOrEmpty(authFile))
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// 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.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Microsoft.Azure.Management.AppService.Fluent;
|
using Microsoft.Azure.Management.AppService.Fluent;
|
||||||
using Microsoft.Azure.Management.AppService.Fluent.Models;
|
using Microsoft.Azure.Management.AppService.Fluent.Models;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -35,20 +40,15 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
|
|
||||||
using (var logger = GetLogger(testId))
|
using (var logger = GetLogger(testId))
|
||||||
{
|
{
|
||||||
Assert.NotNull(_fixture.Azure);
|
|
||||||
|
|
||||||
var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId);
|
var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId);
|
||||||
var testDirectory = GetTestDirectory(testId);
|
var testDirectory = GetTestDirectory(testId);
|
||||||
|
|
||||||
var dotnet = DotNet(logger, testDirectory);
|
var dotnet = DotNet(logger, testDirectory);
|
||||||
|
|
||||||
var result = await dotnet.ExecuteAsync("new " + template);
|
await dotnet.ExecuteAndAssertAsync("new " + template);
|
||||||
result.AssertSuccess();
|
|
||||||
|
|
||||||
await site.BuildPublishProfileAsync(testDirectory.FullName);
|
await site.BuildPublishProfileAsync(testDirectory.FullName);
|
||||||
|
|
||||||
result = await dotnet.ExecuteAsync("publish /p:PublishProfile=Profile");
|
await dotnet.ExecuteAndAssertAsync("publish /p:PublishProfile=Profile");
|
||||||
result.AssertSuccess();
|
|
||||||
|
|
||||||
using (var httpClient = site.CreateClient())
|
using (var httpClient = site.CreateClient())
|
||||||
{
|
{
|
||||||
|
|
@ -59,6 +59,81 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("web", "Hello World!")]
|
||||||
|
[InlineData("razor", "Learn how to build ASP.NET apps that can run anywhere.")]
|
||||||
|
[InlineData("mvc", "Learn how to build ASP.NET apps that can run anywhere.")]
|
||||||
|
public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string template, string expected)
|
||||||
|
{
|
||||||
|
var testId = nameof(DotnetNewWebRunsWebAppOnLatestRuntime) + template;
|
||||||
|
|
||||||
|
using (var logger = GetLogger(testId))
|
||||||
|
{
|
||||||
|
var site = await _fixture.Deploy("Templates\\AppServicesWithSiteExtensions.json",
|
||||||
|
baseName: testId,
|
||||||
|
additionalArguments: new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "extensionFeed", AzureFixture.GetRequiredEnvironmentVariable("SiteExtensionFeed") },
|
||||||
|
{ "extensionName", "AspNetCoreTestBundle" },
|
||||||
|
{ "extensionVersion", GetAssemblyInformationalVersion() },
|
||||||
|
});
|
||||||
|
|
||||||
|
var testDirectory = GetTestDirectory(testId);
|
||||||
|
var dotnet = DotNet(logger, testDirectory);
|
||||||
|
|
||||||
|
await dotnet.ExecuteAndAssertAsync("new " + template);
|
||||||
|
|
||||||
|
FixAspNetCoreVersion(testDirectory);
|
||||||
|
|
||||||
|
await dotnet.ExecuteAndAssertAsync("restore");
|
||||||
|
|
||||||
|
await site.BuildPublishProfileAsync(testDirectory.FullName);
|
||||||
|
|
||||||
|
await dotnet.ExecuteAndAssertAsync("publish /p:PublishProfile=Profile");
|
||||||
|
|
||||||
|
using (var httpClient = site.CreateClient())
|
||||||
|
{
|
||||||
|
var getResult = await httpClient.GetAsync("/");
|
||||||
|
getResult.EnsureSuccessStatusCode();
|
||||||
|
Assert.Contains(expected, await getResult.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FixAspNetCoreVersion(DirectoryInfo testDirectory)
|
||||||
|
{
|
||||||
|
// TODO: Temporary workaround for broken templates in latest CLI
|
||||||
|
|
||||||
|
var csproj = testDirectory.GetFiles("*.csproj").Single().FullName;
|
||||||
|
var projectContents = XDocument.Load(csproj);
|
||||||
|
var packageReference = projectContents
|
||||||
|
.Descendants("PackageReference")
|
||||||
|
.Single(element => (string) element.Attribute("Include") == "Microsoft.AspNetCore.All");
|
||||||
|
|
||||||
|
// Detect what version of aspnet core was shipped with this CLI installation
|
||||||
|
var aspnetCoreVersion =
|
||||||
|
new DirectoryInfo(
|
||||||
|
Path.Combine(
|
||||||
|
Path.GetDirectoryName(TestCommand.DotnetPath),
|
||||||
|
"store", "x86", "netcoreapp2.0", "microsoft.aspnetcore"))
|
||||||
|
.GetDirectories()
|
||||||
|
.Single()
|
||||||
|
.Name;
|
||||||
|
|
||||||
|
packageReference.Attribute("Version").Value = aspnetCoreVersion;
|
||||||
|
projectContents.Save(csproj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetAssemblyInformationalVersion()
|
||||||
|
{
|
||||||
|
var assemblyInformationalVersionAttribute = typeof(TemplateFunctionalTests).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||||
|
if (assemblyInformationalVersionAttribute == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Tests assembly lacks AssemblyInformationalVersionAttribute");
|
||||||
|
}
|
||||||
|
return assemblyInformationalVersionAttribute.InformationalVersion;
|
||||||
|
}
|
||||||
|
|
||||||
private TestLogger GetLogger([CallerMemberName] string callerName = null)
|
private TestLogger GetLogger([CallerMemberName] string callerName = null)
|
||||||
{
|
{
|
||||||
_fixture.TestLog.StartTestLog(_outputHelper, nameof(TemplateFunctionalTests), out var factory, callerName);
|
_fixture.TestLog.StartTestLog(_outputHelper, nameof(TemplateFunctionalTests), out var factory, callerName);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
},
|
},
|
||||||
"resources": [
|
"resources": [
|
||||||
{
|
{
|
||||||
"type": "extensions",
|
"type": "siteextensions",
|
||||||
"name": "[parameters('extensionName')]",
|
"name": "[parameters('extensionName')]",
|
||||||
"apiVersion": "2015-08-01",
|
"apiVersion": "2015-08-01",
|
||||||
"location": "West US 2",
|
"location": "West US 2",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
{
|
{
|
||||||
public class TestCommand
|
public class TestCommand
|
||||||
{
|
{
|
||||||
private string _dotnetPath = GetDotnetPath();
|
public static string DotnetPath { get; } = GetDotnetPath();
|
||||||
|
|
||||||
private static string GetDotnetPath()
|
private static string GetDotnetPath()
|
||||||
{
|
{
|
||||||
|
|
@ -77,6 +77,13 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
return await ExecuteAsyncInternal(resolvedCommand, args);
|
return await ExecuteAsyncInternal(resolvedCommand, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task<CommandResult> ExecuteAndAssertAsync(string args = "")
|
||||||
|
{
|
||||||
|
var result = await ExecuteAsync(args);
|
||||||
|
result.AssertSuccess();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<CommandResult> ExecuteAsyncInternal(string executable, string args)
|
private async Task<CommandResult> ExecuteAsyncInternal(string executable, string args)
|
||||||
{
|
{
|
||||||
var stdOut = new List<String>();
|
var stdOut = new List<String>();
|
||||||
|
|
@ -200,7 +207,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests
|
||||||
{
|
{
|
||||||
if (executable == "dotnet")
|
if (executable == "dotnet")
|
||||||
{
|
{
|
||||||
executable = _dotnetPath;
|
executable = DotnetPath;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue