Added tests for FunctionsPreservedDependencies functionality.
This commit is contained in:
Родитель
b8dfd88ce5
Коммит
4ae32c3b39
|
@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RefNotFound", "Razor\RefNot
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedStartup", "SharedStartup\SharedStartup.csproj", "{36AFB021-DBBD-447D-A6FA-78FB3023D191}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreservedDependencies", "PreservedDependencies\PreservedDependencies.csproj", "{5FD501A6-B510-4CFE-BAEA-4F44220E1DCC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -52,6 +54,10 @@ Global
|
|||
{36AFB021-DBBD-447D-A6FA-78FB3023D191}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{36AFB021-DBBD-447D-A6FA-78FB3023D191}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{36AFB021-DBBD-447D-A6FA-78FB3023D191}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FD501A6-B510-4CFE-BAEA-4F44220E1DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FD501A6-B510-4CFE-BAEA-4F44220E1DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5FD501A6-B510-4CFE-BAEA-4F44220E1DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FD501A6-B510-4CFE-BAEA-4F44220E1DCC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -62,6 +68,7 @@ Global
|
|||
{BD963FE0-0F9E-4480-AA2D-A1F9C8089327} = {41E8547B-A497-4C51-B648-80DC7FE9A681}
|
||||
{41E58322-B3F0-4B2D-8B7A-0626BCEBEDA3} = {41E8547B-A497-4C51-B648-80DC7FE9A681}
|
||||
{36AFB021-DBBD-447D-A6FA-78FB3023D191} = {41E8547B-A497-4C51-B648-80DC7FE9A681}
|
||||
{5FD501A6-B510-4CFE-BAEA-4F44220E1DCC} = {41E8547B-A497-4C51-B648-80DC7FE9A681}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E0021489-706A-4A64-98FA-2D1DFE28695E}
|
||||
|
|
|
@ -91,6 +91,70 @@ namespace FunctionsSdkE2ETests
|
|||
RunBasicValidation("V3");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_PreservedDependencies()
|
||||
{
|
||||
string solutionName = "PreservedDependencies";
|
||||
string solutionFile = solutionName + ".sln";
|
||||
string workingDir = FindContainingDirectory(solutionFile);
|
||||
string projectDir = Path.Combine(workingDir, solutionName);
|
||||
|
||||
RunDotNet("restore", workingDir, solutionFile);
|
||||
RunDotNet("clean", workingDir, solutionFile);
|
||||
RunDotNet("build", workingDir, solutionFile);
|
||||
|
||||
ValidateExtensionsJsonRecursive(projectDir, 1, expectedFolder: _expectedBinFolder, ValidateSharedStartupExtension);
|
||||
|
||||
string[] expectedCleanedOutputPath = new string[] { projectDir, "bin", "Debug", "netcoreapp3.1", "bin" };
|
||||
string cleanedOutputDir = Path.Combine(expectedCleanedOutputPath);
|
||||
List<string> preservedFiles = new List<string>() { "Microsoft.Azure.WebJobs.dll", "Microsoft.Azure.WebJobs.Host.dll" };
|
||||
List<string> cleanedFiles = new List<string>() { "Microsoft.Net.Http.Headers.dll", "Microsoft.Azure.WebJobs.Extensions.Http.dll" };
|
||||
|
||||
foreach (var preservedFile in preservedFiles)
|
||||
{
|
||||
Assert.True(File.Exists(Path.Combine(cleanedOutputDir, preservedFile)));
|
||||
}
|
||||
|
||||
foreach (var cleanedFile in cleanedFiles)
|
||||
{
|
||||
Assert.False(File.Exists(Path.Combine(cleanedOutputDir, cleanedFile)));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Publish_PreservedDependencies()
|
||||
{
|
||||
string publishDir = Path.Combine(Path.GetTempPath(), "FunctionsSdkTests", "pub_preservedDeps");
|
||||
if (Directory.Exists(publishDir))
|
||||
{
|
||||
Directory.Delete(publishDir, true);
|
||||
}
|
||||
|
||||
string solutionName = "PreservedDependencies";
|
||||
string solutionFile = solutionName + ".sln";
|
||||
string workingDir = FindContainingDirectory(solutionFile);
|
||||
|
||||
RunDotNet("restore", workingDir, solutionFile);
|
||||
RunDotNet("clean", workingDir, solutionFile);
|
||||
RunDotNet("publish", workingDir, solutionFile, $"-o {publishDir}");
|
||||
|
||||
ValidateExtensionsJsonRecursive(publishDir, 1, expectedFolder: _expectedBinFolder, ValidateSharedStartupExtension);
|
||||
|
||||
string cleanedOutputDir = Path.Combine(publishDir, "bin");
|
||||
List<string> preservedFiles = new List<string>() { "Microsoft.Azure.WebJobs.dll", "Microsoft.Azure.WebJobs.Host.dll" };
|
||||
List<string> cleanedFiles = new List<string>() { "Microsoft.Net.Http.Headers.dll", "Microsoft.Azure.WebJobs.Extensions.Http.dll" };
|
||||
|
||||
foreach (var preservedFile in preservedFiles)
|
||||
{
|
||||
Assert.True(File.Exists(Path.Combine(cleanedOutputDir, preservedFile)));
|
||||
}
|
||||
|
||||
foreach (var cleanedFile in cleanedFiles)
|
||||
{
|
||||
Assert.False(File.Exists(Path.Combine(cleanedOutputDir, cleanedFile)));
|
||||
}
|
||||
}
|
||||
|
||||
private void RunBasicValidation(string solutionName)
|
||||
{
|
||||
string solutionFile = solutionName + ".sln";
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30611.23
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PreservedDependencies", "PreservedDependencies\PreservedDependencies.csproj", "{4BA1535A-085C-4FA1-8AAE-D623388193E5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4BA1535A-085C-4FA1-8AAE-D623388193E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4BA1535A-085C-4FA1-8AAE-D623388193E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4BA1535A-085C-4FA1-8AAE-D623388193E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4BA1535A-085C-4FA1-8AAE-D623388193E5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D734900A-C074-48A9-B687-BF49AD5F5697}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PreservedDependencies
|
||||
{
|
||||
public static class Function1
|
||||
{
|
||||
[FunctionName("Function1")]
|
||||
public static async Task<IActionResult> Run(
|
||||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
||||
ILogger log)
|
||||
{
|
||||
log.LogInformation("C# HTTP trigger function processed a request.");
|
||||
|
||||
string name = req.Query["name"];
|
||||
|
||||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
||||
dynamic data = JsonConvert.DeserializeObject(requestBody);
|
||||
name = name ?? data?.name;
|
||||
|
||||
string responseMessage = string.IsNullOrEmpty(name)
|
||||
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
|
||||
: $"Hello, {name}. This HTTP triggered function executed successfully.";
|
||||
|
||||
return new OkObjectResult(responseMessage);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\SdkVersion.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<FunctionsPreservedDependencies Include="Microsoft.Azure.WebJobs.dll" />
|
||||
<FunctionsPreservedDependencies Include="Microsoft.Azure.WebJobs.Host.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="$(ExtensionsMetadataGeneratorDirectReferenceVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="$(MicrosoftNetSdkFunctionsV3Version)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SharedStartup\SharedStartup.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="host.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="local.settings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"version": "2.0",
|
||||
"logging": {
|
||||
"applicationInsights": {
|
||||
"samplingExcludedTypes": "Request",
|
||||
"samplingSettings": {
|
||||
"isEnabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"IsEncrypted": false,
|
||||
"Values": {
|
||||
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
|
||||
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
|
||||
}
|
||||
}
|
|
@ -8,6 +8,6 @@
|
|||
<MicrosoftNetSdkFunctionsV3PreviousVersion>3.0.10</MicrosoftNetSdkFunctionsV3PreviousVersion>
|
||||
|
||||
<!-- Some tests directly reference EMG; this should be latest -->
|
||||
<ExtensionsMetadataGeneratorDirectReferenceVersion>1.2.0</ExtensionsMetadataGeneratorDirectReferenceVersion>
|
||||
<ExtensionsMetadataGeneratorDirectReferenceVersion>1.2.1</ExtensionsMetadataGeneratorDirectReferenceVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче