Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for FunctionsPreservedDependencies functionality. #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 125 additions & 118 deletions FunctionsSdkE2ETests.sln

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions FunctionsSdkE2ETests/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,70 @@ public void Publish_DirectRef()
ValidateSharedStartupExtension);
}

[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} /bl");

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)));
}
}

[Fact]
public void Build_DifferentFrameworks()
{
Expand Down
31 changes: 31 additions & 0 deletions PreservedDependencies.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

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", "{FF7D2243-8660-4961-A68F-09B09DF9A549}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedStartup", "SharedStartup\SharedStartup.csproj", "{196A4BB6-8FF2-44C9-BF31-D3517140FD3A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FF7D2243-8660-4961-A68F-09B09DF9A549}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF7D2243-8660-4961-A68F-09B09DF9A549}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF7D2243-8660-4961-A68F-09B09DF9A549}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF7D2243-8660-4961-A68F-09B09DF9A549}.Release|Any CPU.Build.0 = Release|Any CPU
{196A4BB6-8FF2-44C9-BF31-D3517140FD3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{196A4BB6-8FF2-44C9-BF31-D3517140FD3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{196A4BB6-8FF2-44C9-BF31-D3517140FD3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{196A4BB6-8FF2-44C9-BF31-D3517140FD3A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {54BD5AE1-6A12-4857-A500-5A8E3AA3235C}
EndGlobalSection
EndGlobal
35 changes: 35 additions & 0 deletions PreservedDependencies/Function1.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
27 changes: 27 additions & 0 deletions PreservedDependencies/PreservedDependencies.csproj
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 11 additions & 0 deletions PreservedDependencies/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
7 changes: 7 additions & 0 deletions PreservedDependencies/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}