Adding tests for functions v1 & upgrading tests for functions v3. (#446)

Moving the v1 & v3 tests to separate folders.
Removing the samples folder and moving the tests to endtoend tests
Moving the pack folder under src
Updating build.cmd with tests
Adding directly.build.props with version info.
Updating the build version for the binaries based on each build
This commit is contained in:
Vijay Ramakrishnan 2020-07-13 18:26:31 -07:00 коммит произвёл GitHub
Родитель 0992e21cc6
Коммит 2384fdc500
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
77 изменённых файлов: 226 добавлений и 160 удалений

4
Directory.Build.props Normal file
Просмотреть файл

@ -0,0 +1,4 @@
<Project>
<Import Project="src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props"/>
</Project>

Просмотреть файл

@ -9,16 +9,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9B6D0171-3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions.Generator.Tests", "test\Microsoft.NET.Sdk.Functions.Generator.Tests\Microsoft.NET.Sdk.Functions.Generator.Tests.csproj", "{9D59910B-B90E-4BBE-BD26-C2CBF85D37E1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pack", "pack", "{8D555953-A625-4C7F-93A7-C737644820AB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions", "pack\Microsoft.NET.Sdk.Functions\Microsoft.NET.Sdk.Functions.csproj", "{5DCBB929-5248-4701-82C9-88BB566E404C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions.Generator", "src\Microsoft.NET.Sdk.Functions.Generator\Microsoft.NET.Sdk.Functions.Generator.csproj", "{6CEDE940-9F0A-4B2A-97D4-D1EEEE42AF35}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{03DEE129-17B6-4CE0-B2D8-5B648D5BEE64}"
ProjectSection(SolutionItems) = preProject
build.cmd = build.cmd
devbuild.cmd = devbuild.cmd
build.fsx = build.fsx
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions.MSBuild.Tests", "test\Microsoft.NET.Sdk.Functions.MSBuild.Tests\Microsoft.NET.Sdk.Functions.MSBuild.Tests.csproj", "{B80DA350-8A69-4CD2-9E60-01C51B5A8633}"
@ -27,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions.EndToEnd.Tests", "test\Microsoft.NET.Sdk.Functions.EndToEnd.Tests\Microsoft.NET.Sdk.Functions.EndToEnd.Tests.csproj", "{3F8DD976-ABCC-4B6B-B991-CEAAA4C03736}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Functions", "src\Microsoft.NET.Sdk.Functions\Microsoft.NET.Sdk.Functions.csproj", "{5B57C72D-8E4E-40DC-B434-A4163C2467E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -37,10 +35,6 @@ Global
{9D59910B-B90E-4BBE-BD26-C2CBF85D37E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D59910B-B90E-4BBE-BD26-C2CBF85D37E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D59910B-B90E-4BBE-BD26-C2CBF85D37E1}.Release|Any CPU.Build.0 = Release|Any CPU
{5DCBB929-5248-4701-82C9-88BB566E404C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DCBB929-5248-4701-82C9-88BB566E404C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DCBB929-5248-4701-82C9-88BB566E404C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DCBB929-5248-4701-82C9-88BB566E404C}.Release|Any CPU.Build.0 = Release|Any CPU
{6CEDE940-9F0A-4B2A-97D4-D1EEEE42AF35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CEDE940-9F0A-4B2A-97D4-D1EEEE42AF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CEDE940-9F0A-4B2A-97D4-D1EEEE42AF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -57,17 +51,21 @@ Global
{3F8DD976-ABCC-4B6B-B991-CEAAA4C03736}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F8DD976-ABCC-4B6B-B991-CEAAA4C03736}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F8DD976-ABCC-4B6B-B991-CEAAA4C03736}.Release|Any CPU.Build.0 = Release|Any CPU
{5B57C72D-8E4E-40DC-B434-A4163C2467E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B57C72D-8E4E-40DC-B434-A4163C2467E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B57C72D-8E4E-40DC-B434-A4163C2467E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B57C72D-8E4E-40DC-B434-A4163C2467E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9D59910B-B90E-4BBE-BD26-C2CBF85D37E1} = {9B6D0171-3FFD-4892-B407-B633CA4E6712}
{5DCBB929-5248-4701-82C9-88BB566E404C} = {8D555953-A625-4C7F-93A7-C737644820AB}
{6CEDE940-9F0A-4B2A-97D4-D1EEEE42AF35} = {14D6456E-2F9D-4483-A378-03701A6EB12D}
{B80DA350-8A69-4CD2-9E60-01C51B5A8633} = {9B6D0171-3FFD-4892-B407-B633CA4E6712}
{1DB38EB5-DBA9-4678-BB99-2BCD1255DDBE} = {14D6456E-2F9D-4483-A378-03701A6EB12D}
{3F8DD976-ABCC-4B6B-B991-CEAAA4C03736} = {9B6D0171-3FFD-4892-B407-B633CA4E6712}
{5B57C72D-8E4E-40DC-B434-A4163C2467E4} = {14D6456E-2F9D-4483-A378-03701A6EB12D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DA731A15-774F-46C2-B8DF-298F828DCC2A}

Просмотреть файл

@ -11,88 +11,18 @@ dotnet build src\Microsoft.NET.Sdk.Functions.Generator --configuration=Release
if errorlevel 1 GOTO ERROR
REM Pack the functions sdk.
dotnet pack pack\Microsoft.NET.Sdk.Functions --configuration=Release
dotnet pack src\Microsoft.NET.Sdk.Functions --configuration=Release
if errorlevel 1 GOTO ERROR
REM Run tests
dotnet test test\\Microsoft.NET.Sdk.Functions.Generator.Tests --configuration Debug
dotnet test test\\Microsoft.NET.Sdk.Functions.MSBuild.Tests --configuration Debug
dotnet test test\\Microsoft.NET.Sdk.Functions.EndToEnd.Tests --configuration Debug --logger console;verbosity=detailed
REM Remove the functions sdk in the user profile so that the built sdk will be restored.
rmdir /S /Q %userprofile%\.nuget\packages\microsoft.net.sdk.functions
if errorlevel 1 GOTO ERROR
REM Restore the NuGet.exe.
dotnet restore sample\NuGet\NuGet.csproj
if errorlevel 1 GOTO ERROR
REM ***************************NETFramework************************************
REM Restore the sample NETFramework project.
%userprofile%\.nuget\packages\nuget.commandline\4.1.0\tools\nuget.exe restore sample\FunctionAppNETFramework\FunctionAppNETFramework.sln
if errorlevel 1 GOTO ERROR
REM Build the sample NETFramework solution.
msbuild sample\FunctionAppNETFramework\FunctionAppNETFramework.sln /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Publish the sample .NETFramework function app using the publish target (full framework msbuild).
msbuild sample\FunctionAppNETFramework\FunctionAppNETFramework\FunctionAppNETFramework.csproj /t:Publish /p:PublishDir="bin\Release\dotnetpublishoutput" /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Publish the sample .NETFramework function app using DeployOnBuild (full framework msbuild).
msbuild sample\FunctionAppNETFramework\FunctionAppNETFramework\FunctionAppNETFramework.csproj /p:DeployOnBuild=true /p:PublishUrl="bin\Release\deployOnBuildOutput" /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Run tests on .NETFramework projects.
dotnet test sample\FunctionAppNETFramework\UnitTestProject2\UnitTestProject2.csproj --configuration=Release --no-build
if errorlevel 1 GOTO ERROR
dotnet test sample\FunctionAppNETFramework\XUnitTestProject1\XUnitTestProject1.csproj --configuration=Release --no-build
if errorlevel 1 GOTO ERROR
REM Run tests on unit test projects that references the functions project.
dotnet test sample\FunctionAppNETFramework\UnitTestProject1\UnitTestProject1.csproj --configuration=Release --no-build
if errorlevel 1 GOTO ERROR
REM ***************************NETStandard************************************
REM Restore the sample NETStandard project.
dotnet restore sample\FunctionAppNETStandard\FunctionAppNETStandard.sln
if errorlevel 1 GOTO ERROR
REM Build the sample NETStandard solution.
msbuild sample\FunctionAppNETStandard\FunctionAppNETStandard.sln /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Publish the sample .NETStandard function app using the publish target (core msbuild).
dotnet build sample\FunctionAppNETStandard\FunctionAppNETStandard\FunctionAppNETStandard.csproj /t:Publish /p:PublishDir="bin\Release\core\dotnetpublishoutput" /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Publish the sample .NETStandard function app using DeployOnBuild (core msbuild).
dotnet build sample\FunctionAppNETStandard\FunctionAppNETStandard\FunctionAppNETStandard.csproj /p:DeployOnBuild=true /p:PublishUrl="bin\Release\core\deployOnBuildOutput" /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Publish the sample .NETStandard function app using the publish target (full framework msbuild).
msbuild sample\FunctionAppNETStandard\FunctionAppNETStandard\FunctionAppNETStandard.csproj /t:Publish /p:PublishDir="bin\Release\full\dotnetpublishoutput" /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Publish the sample .NETStandard function app using DeployOnBuild (full framework msbuild).
msbuild sample\FunctionAppNETStandard\FunctionAppNETStandard\FunctionAppNETStandard.csproj /p:DeployOnBuild=true /p:PublishUrl="bin\Release\full\deployOnBuildOutput" /p:configuration=Release
if errorlevel 1 GOTO ERROR
REM Run tests on .NETStandard projects
dotnet test sample\FunctionAppNETStandard\UnitTestNETFramework\UnitTestNETFramework.csproj --configuration=Release --no-build
if errorlevel 1 GOTO ERROR
dotnet test sample\FunctionAppNETStandard\UnitTestProject2\UnitTestProject2.csproj --configuration=Release --no-build
if errorlevel 1 GOTO ERROR
dotnet test sample\FunctionAppNETStandard\XUnitTestProject1\XUnitTestProject1.csproj --configuration=Release --no-build
if errorlevel 1 GOTO ERROR
:ERROR
endlocal
exit /b 1

Просмотреть файл

@ -30,7 +30,7 @@ let connectionString =
"DefaultEndpointsProtocol=https;AccountName=" + (env "FILES_ACCOUNT_NAME") + ";AccountKey=" + (env "FILES_ACCOUNT_KEY")
let buildTaskOutputPath = "src\\Microsoft.NET.Sdk.Functions.MSBuild\\bin\\Release"
let generatorOutputPath = "src\\Microsoft.NET.Sdk.Functions.Generator\\bin\\Release"
let packOutputPath = "pack\\Microsoft.NET.Sdk.Functions\\bin\\Release"
let packOutputPath = "src\\Microsoft.NET.Sdk.Functions\\bin\\Release"
let version = if isNull appVeyorBuildVersion then "1.0.0.3" else appVeyorBuildVersion
Target "Clean" (fun _ ->
@ -53,7 +53,7 @@ Target "Build" (fun _ ->
DotNetCli.Build (fun p ->
{p with
Project = "pack\\Microsoft.NET.Sdk.Functions"
Project = "src\\Microsoft.NET.Sdk.Functions"
Configuration = "Release"})
)
@ -152,7 +152,7 @@ Target "WaitForSigning" (fun _ ->
Target "Pack" (fun _ ->
DotNetCli.Pack (fun p ->
{p with
Project = "pack\\Microsoft.NET.Sdk.Functions"
Project = "src\\Microsoft.NET.Sdk.Functions"
Configuration = "Release"
AdditionalArgs = [ "--no-build" ]})
)

Просмотреть файл

@ -11,9 +11,13 @@ dotnet build src\Microsoft.NET.Sdk.Functions.Generator --configuration=Release
if errorlevel 1 GOTO ERROR
REM Pack the functions sdk.
dotnet pack pack\Microsoft.NET.Sdk.Functions --configuration=Release
dotnet pack src\Microsoft.NET.Sdk.Functions --configuration=Release
if errorlevel 1 GOTO ERROR
REM Run tests
dotnet test test\\Microsoft.NET.Sdk.Functions.Generator.Tests --configuration Debug
dotnet test test\\Microsoft.NET.Sdk.Functions.MSBuild.Tests --configuration Debug
REM Remove the functions sdk in the user profile so that the built sdk will be restored.
rmdir /S /Q %userprofile%\.nuget\packages\microsoft.net.sdk.functions
if errorlevel 1 GOTO ERROR

Просмотреть файл

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="FunctionsSdkPath" value="../pack/Microsoft.NET.Sdk.Functions/bin/Release" />
<add key="azure_app_service" value="https://www.myget.org/F/azure-appservice/api/v2" />
</packageSources>
</configuration>

Просмотреть файл

@ -0,0 +1,9 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<FunctionsBuildVersion Condition="'$(APPVEYOR_BUILD_NUMBER)' != ''">$(APPVEYOR_BUILD_NUMBER)</FunctionsBuildVersion>
<FunctionsBuildVersion Condition="'$(FunctionsBuildVersion)' == ''">0</FunctionsBuildVersion>
<Version>$(FunctionsSdkVersion).$(FunctionsBuildVersion)</Version>
</PropertyGroup>
</Project>

Просмотреть файл

@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props" />
<PropertyGroup>
<Version>$(FunctionsSdkVersion)</Version>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@ -24,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\pack\Microsoft.NET.Sdk.Functions\Microsoft.NET.Sdk.Functions.csproj" />
<ProjectReference Include="..\..\src\Microsoft.NET.Sdk.Functions\Microsoft.NET.Sdk.Functions.csproj" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props" />
<PropertyGroup>
<Version>$(FunctionsSdkVersion)</Version>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>

Просмотреть файл

@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\ExtensionsMetadataGeneratorVersion.props" />
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props" />
<PropertyGroup>
<!-- Version of the package should not contain the build version -->
<Version>$(FunctionsSdkVersion)</Version>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<PackageName>Microsoft.NET.Sdk.Functions</PackageName>
<Version>$(FunctionsSdkVersion)</Version>
<Authors>Microsoft</Authors>
<ProjectUrl>https://github.com/Azure/azure-functions-vs-build-sdk</ProjectUrl>
<PackageProjectUrl>https://github.com/Azure/azure-functions-vs-build-sdk</PackageProjectUrl>

Просмотреть файл

@ -0,0 +1,100 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
{
public class FunctionsV1SdkTests
{
private string _testsDirectory;
private string _msbuildPath;
private string _nugetExePath;
private bool _isTestPreReqSatisfied;
private TestInitialize _testInitializer;
private ITestOutputHelper _testOutputHelper;
private const string _testVersion = "v1";
private const string _msbuildLoggingVerbosity = "m";
public FunctionsV1SdkTests(ITestOutputHelper testOutputHelper)
{
// Running the pack command is only needed for tests running against the latest version.
_testInitializer = new TestInitialize(testOutputHelper, _testVersion, runPack: false);
_testOutputHelper = testOutputHelper;
_testsDirectory = _testInitializer.TestDirectory;
_msbuildPath = GetMSBuildPath();
_nugetExePath = GetNuGetPath();
_isTestPreReqSatisfied = File.Exists(_msbuildPath) && File.Exists(_nugetExePath);
}
private string GetMSBuildPath()
{
var vswherePath = Environment.ExpandEnvironmentVariables($@"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\{TestInitialize.VsWhere}");
if (!File.Exists(vswherePath))
{
return null;
}
var args = $@"-latest -requires Microsoft.Component.MSBuild -find ""MSBuild\**\Bin\{TestInitialize.MSBuildExecutable}""";
ProcessOutput readOutput = new ProcessOutput();
int? exitCode = new ProcessWrapper().RunProcess(vswherePath, args, _testsDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: readOutput);
Debug.Assert(exitCode.HasValue && exitCode.Value == 0);
return readOutput.StdOut?.TrimEnd('\r', '\n'); ;
}
private string GetNuGetPath()
{
string projectToRestore = "NuGet";
string projectFilePath = Path.Combine(_testsDirectory, projectToRestore);
string dotnetArgs = $"restore {projectToRestore}.csproj";
int? exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFilePath, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Debug.Assert(exitCode.HasValue && exitCode.Value == 0);
return Environment.ExpandEnvironmentVariables($@"%userprofile%\.nuget\packages\nuget.commandline\5.6.0\tools\{TestInitialize.NuGetExecutable}");
}
[Theory]
[InlineData("FunctionAppNETFramework", "FunctionAppNETFramework", TestInitialize.NetFramework)]
[InlineData("FunctionAppNETStandard", "FunctionAppNETStandard", TestInitialize.NetStandard)]
[InlineData("FunctionAppNETFxNETStandard", "FunctionAppNETFramework", TestInitialize.NetFramework)]
public void BuildAndPublish_V1Functions(string solutionName, string projectName, string targetFramework)
{
if (!_isTestPreReqSatisfied)
{
return;
}
// Name of the csproj
string solutionToTest = solutionName;
string projectToTest = projectName;
string solutionFileDirectory = Path.Combine(_testsDirectory, solutionToTest);
string projectFileDirectory = Path.Combine(solutionFileDirectory, projectToTest);
// Restore
string exeArgs = $"restore {solutionToTest}.sln";
int? exitCode = new ProcessWrapper().RunProcess(_nugetExePath, exeArgs, solutionFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
// Build
exeArgs = $"{solutionToTest}.sln /p:configuration={TestInitialize.Configuration} /v:{_msbuildLoggingVerbosity}";
exitCode = new ProcessWrapper().RunProcess(_msbuildPath, exeArgs, solutionFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
// Test additional bin
string additionalBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, targetFramework, "bin");
Assert.True(Directory.Exists(additionalBinDir));
var files = Directory.EnumerateFiles(additionalBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
// Publish
exeArgs = $"{projectToTest}.csproj /t:Publish /p:configuration={TestInitialize.Configuration} /v:{_msbuildLoggingVerbosity}";
exitCode = new ProcessWrapper().RunProcess(_msbuildPath, exeArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
// Test additional bin
string additionalPublishBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, targetFramework, "publish", "bin");
Assert.True(Directory.Exists(additionalPublishBinDir));
files = Directory.EnumerateFiles(additionalPublishBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
}
}
}

Просмотреть файл

@ -5,17 +5,19 @@ using Xunit.Abstractions;
namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
{
public class FunctionsSdkTests
public class FunctionsV3SdkTests
{
private string _packageSource;
private string _functionsSdkPackageSource;
private string _testsDirectory;
private TestInitialize _testInitializer;
private ITestOutputHelper _testOutputHelper;
public FunctionsSdkTests(ITestOutputHelper output)
private const string _testVersion = "v3";
public FunctionsV3SdkTests(ITestOutputHelper testOutputHelper)
{
_testInitializer = new TestInitialize(output);
_testOutputHelper = output;
_packageSource = _testInitializer.PackageSource;
_testInitializer = new TestInitialize(testOutputHelper, _testVersion);
_testOutputHelper = testOutputHelper;
_functionsSdkPackageSource = _testInitializer.FunctionsSdkPackageSource;
_testsDirectory = _testInitializer.TestDirectory;
}
@ -27,7 +29,7 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
string projectFileDirectory = Path.Combine(_testsDirectory, projectFileToTest);
// Restore
string dotnetArgs = $"restore {projectFileToTest}.csproj --source {_packageSource}";
string dotnetArgs = $"restore {projectFileToTest}.csproj --source {_functionsSdkPackageSource}";
int? exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
@ -35,10 +37,8 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"build {projectFileToTest}.csproj --configuration {TestInitialize.Configuration}";
exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
string additionalBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.Framework, "bin");
string additionalBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.NetCoreFramework, "bin");
Assert.True(Directory.Exists(additionalBinDir));
var files = Directory.EnumerateFiles(additionalBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
@ -46,10 +46,9 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"publish {projectFileToTest}.csproj --configuration {TestInitialize.Configuration}";
exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
string additionalPublishBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.Framework, "publish", "bin");
// Test additional bin
string additionalPublishBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.NetCoreFramework, "publish", "bin");
Assert.True(Directory.Exists(additionalPublishBinDir));
files = Directory.EnumerateFiles(additionalPublishBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
}
@ -62,7 +61,7 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
string projectFileDirectory = Path.Combine(_testsDirectory, projectFileToTest);
// Restore
string dotnetArgs = $"restore {projectFileToTest}.csproj --source {TestInitialize.NuGetPackageSource};{_packageSource}";
string dotnetArgs = $"restore {projectFileToTest}.csproj --source {TestInitialize.NuGetPackageSource};{_functionsSdkPackageSource}";
int? exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
@ -70,13 +69,12 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"build {projectFileToTest}.csproj --configuration {TestInitialize.Configuration}";
exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
string additionalBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.Framework, "bin");
// Test additional bin
string additionalBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.NetCoreFramework, "bin");
Assert.True(Directory.Exists(additionalBinDir));
var files = Directory.EnumerateFiles(additionalBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
// Test addional runtimes
files = Directory.EnumerateFiles(Path.Combine(additionalBinDir, "runtimes"), "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
@ -84,26 +82,25 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"publish {projectFileToTest}.csproj --configuration {TestInitialize.Configuration}";
exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
string additionalPublishBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.Framework, "publish", "bin");
// Test additional bin
string additionalPublishBinDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.NetCoreFramework, "publish", "bin");
Assert.True(Directory.Exists(additionalPublishBinDir));
files = Directory.EnumerateFiles(additionalPublishBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
// Test additional runtimes
files = Directory.EnumerateFiles(Path.Combine(additionalPublishBinDir, "runtimes"), "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
}
[Fact]
public void Build_FunctionAppWithHttpTrigger_GeneratedFunction()
public void BuildAndPublish_GeneratesFunctions()
{
// Name of the csproj
string projectFileToTest = "FunctionAppWithHttpTrigger";
string projectFileDirectory = Path.Combine(_testsDirectory, projectFileToTest);
// Restore
string dotnetArgs = $"restore {projectFileToTest}.csproj --source {_packageSource}";
string dotnetArgs = $"restore {projectFileToTest}.csproj --source {_functionsSdkPackageSource}";
int? exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
@ -111,14 +108,13 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"build {projectFileToTest}.csproj --configuration {TestInitialize.Configuration}";
exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
string binDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.Framework);
// Test addional bin
string binDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.NetCoreFramework);
string additionalBinDir = Path.Combine(binDir, "bin");
Assert.True(Directory.Exists(additionalBinDir));
var files = Directory.EnumerateFiles(additionalBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
// Check if the http function is generated
// Test functions generator output
string httpTriggerFunctionpath = Path.Combine(binDir, "HttpFunction", "function.json");
Assert.True(File.Exists(httpTriggerFunctionpath));
@ -126,14 +122,13 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"publish {projectFileToTest}.csproj --configuration {TestInitialize.Configuration}";
exitCode = new ProcessWrapper().RunProcess(TestInitialize.DotNetExecutable, dotnetArgs, projectFileDirectory, out int? _, createDirectoryIfNotExists: false, testOutputHelper: _testOutputHelper);
Assert.True(exitCode.HasValue && exitCode.Value == 0);
string publishDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.Framework, "publish");
// Test additional bin
string publishDir = Path.Combine(projectFileDirectory, "bin", TestInitialize.Configuration, TestInitialize.NetCoreFramework, "publish");
string additionalPublishBinDir = Path.Combine(publishDir, "bin");
Assert.True(Directory.Exists(additionalPublishBinDir));
files = Directory.EnumerateFiles(additionalPublishBinDir, "*.dll", SearchOption.AllDirectories);
Assert.True(files.Count() > 1);
// Test functions generator output
httpTriggerFunctionpath = Path.Combine(publishDir, "HttpFunction", "function.json");
Assert.True(File.Exists(httpTriggerFunctionpath));
}

Просмотреть файл

@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<Compile Remove="Resources\FunctionAppWithHttpTrigger\HttpFunction.cs" />
<Compile Remove="Resources\**\*.cs" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,7 @@
namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
{
internal interface IReadProcessOutput
{
public string StdOut { get; }
}
}

Просмотреть файл

@ -0,0 +1,27 @@
using System.Text;
using Xunit.Abstractions;
namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
{
public class ProcessOutput : ITestOutputHelper, IReadProcessOutput
{
private StringBuilder _stringBuilder;
public ProcessOutput()
{
_stringBuilder = new StringBuilder(256);
}
public string StdOut { get => _stringBuilder.ToString(); }
public void WriteLine(string message)
{
_stringBuilder.Append(message);
}
public void WriteLine(string format, params object[] args)
{
_stringBuilder.AppendFormat(format, args);
}
}
}

Просмотреть файл

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using Xunit.Abstractions;
@ -7,7 +6,7 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
{
public class ProcessWrapper
{
public int? RunProcess(string fileName, string arguments, string workingDirectory, out int? processId, bool createDirectoryIfNotExists = true, bool waitForExit = true, ITestOutputHelper testOutputHelper = null)
public int? RunProcess(string fileName, string arguments, string workingDirectory, out int? processId, bool createDirectoryIfNotExists = false, bool waitForExit = true, ITestOutputHelper testOutputHelper = null)
{
if (createDirectoryIfNotExists && !Directory.Exists(workingDirectory))
{

Просмотреть файл

@ -6,6 +6,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.CommandLine" Version="4.1.0" />
<PackageReference Include="NuGet.CommandLine" Version="[5.6.0]" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props"/>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
@ -7,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="$(FunctionsSdkVersion)" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="[$(FunctionsSdkVersion)]" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props"/>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
@ -7,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="$(FunctionsSdkVersion)" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="[$(FunctionsSdkVersion)]" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\src\Microsoft.NET.Sdk.Functions.MSBuild\Targets\Microsoft.NET.Sdk.Functions.Version.props"/>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
@ -7,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="$(FunctionsSdkVersion)" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="[$(FunctionsSdkVersion)]" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,8 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
@ -11,27 +9,36 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
{
public const string TestProjectsSourceDirectory = "Resources";
public const string TestProjectsTargetDirectory = "TestResults";
// Source Project names
public const string FunctionsNetSdkProject = "Microsoft.Net.Sdk.Functions";
public const string FunctionsMsBuildProject = "Microsoft.NET.Sdk.Functions.MSBuild";
public const string FunctionsGeneratorProject = "Microsoft.NET.Sdk.Functions.Generator";
// Configurations
public const string Configuration = "Debug";
public const string Framework = "netcoreapp3.1";
public const string NuGetPackageSource = @"https://api.nuget.org/v3/index.json";
public const string NetCoreFramework = "netcoreapp3.1";
public const string NetFramework = "net461";
public const string NetStandard = "netstandard2.0";
// NuGet Sources
public const string NuGetPackageSource = @"https://api.nuget.org/v3/index.json";
// Paths and executables
public static readonly string DotNetExecutable = "dotnet";
public static readonly string MSBuildExecutable = "msbuild.exe";
public static readonly string NuGetExecutable = "nuget.exe";
public static readonly string VsWhere = "vswhere.exe";
public static readonly string PathToRepoRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, @"..\..\..\..\..\"));
public static readonly string SrcRoot = Path.Combine(PathToRepoRoot, "src");
public static readonly string PackRoot = Path.Combine(PathToRepoRoot, "pack");
public static readonly string TestRoot = Path.Combine(PathToRepoRoot, "test");
public string PackageSource { get; private set; }
public string FunctionsSdkPackageSource { get; private set; }
public string TestDirectory { get; private set; }
public TestInitialize(ITestOutputHelper testOutputHelper, bool runRestore = false, bool runBuild = false, bool runPack = true)
public TestInitialize(ITestOutputHelper testOutputHelper, string testVersion, bool runRestore = false, bool runBuild = false, bool runPack = true)
{
string dotnetArgs;
int? exitCode;
string projectDir = Path.Combine(PackRoot, FunctionsNetSdkProject);
string projectDir = Path.Combine(SrcRoot, FunctionsNetSdkProject);
if (runRestore)
{
@ -61,19 +68,19 @@ namespace Microsoft.NET.Sdk.Functions.EndToEnd.Tests
dotnetArgs = $"pack --configuration {Configuration}";
// Create the package
projectDir = Path.Combine(PackRoot, FunctionsNetSdkProject);
projectDir = Path.Combine(SrcRoot, FunctionsNetSdkProject);
exitCode = new ProcessWrapper().RunProcess(DotNetExecutable, dotnetArgs, projectDir, out _, createDirectoryIfNotExists: false, testOutputHelper: testOutputHelper);
Debug.Assert(exitCode.HasValue && exitCode.Value == 0);
}
// Setup the package source.
PackageSource = Path.Combine(projectDir, "bin", Configuration) + Path.DirectorySeparatorChar;
FunctionsSdkPackageSource = Path.Combine(projectDir, "bin", Configuration) + Path.DirectorySeparatorChar;
// Setup the test directory.
string sourceDirectory = Path.Combine(AppContext.BaseDirectory, TestProjectsSourceDirectory);
string sourceDirectory = Path.Combine(AppContext.BaseDirectory, TestProjectsSourceDirectory, testVersion);
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
string targetDirectory = Path.Combine(PathToRepoRoot, TestProjectsTargetDirectory);
string targetDirectory = Path.Combine(PathToRepoRoot, TestProjectsTargetDirectory, testVersion);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
CopyAll(diSource, diTarget);