Skip to content

Commit

Permalink
Fonlow.Testing.Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
zijianhuang committed Jun 25, 2024
1 parent 4784c0b commit 4c54882
Show file tree
Hide file tree
Showing 20 changed files with 531 additions and 161 deletions.
2 changes: 1 addition & 1 deletion DotNetPack.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$packCmd = 'dotnet pack $Name --no-build --output ./Release --configuration Release'
$projList = 'Fonlow.Testing.HttpCore/Fonlow.Testing.HttpCore.csproj', 'Fonlow.Testing.ServiceCore/Fonlow.Testing.ServiceCore.csproj'
$projList = 'Fonlow.Testing.HttpCore/Fonlow.Testing.HttpCore.csproj', 'Fonlow.Testing.ServiceCore/Fonlow.Testing.ServiceCore.csproj', 'Fonlow.Testing.Basic/Fonlow.Testing.Basic.csproj', 'Fonlow.Testing.Integration/Fonlow.Testing.Integration.csproj', 'Fonlow.Testing.Utilities/Fonlow.Testing.Utilities.csproj'
foreach($name in $projList){
Invoke-Expression $ExecutionContext.InvokeCommand.ExpandString($packCmd)
}
32 changes: 32 additions & 0 deletions Fonlow.Testing.Basic/Fonlow.Testing.Basic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0-Alpha</Version>
<Authors>Zijian Huang</Authors>
<Description>Basic types and functions of Fonlow.Testing.Integration suite.</Description>
<PackageReleaseNotes></PackageReleaseNotes>
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<None Include="./README.md" Pack="true" PackagePath="/" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions Fonlow.Testing.Basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Fonlow.Testing.Basic

Basic types and functions used by other packages of [Fonlow.Testing.Integration](https://www.nuget.org/packages/Fonlow.Testing.Integration/)

## NuGet Packages

### For .NET Core 8.0 +

* Package [Fonlow.Testing.Integration](https://www.nuget.org/packages/Fonlow.Testing.Integration/), including all packages.
* Package [Fonlow.Testing.ServiceCore](https://www.nuget.org/packages/Fonlow.Testing.ServiceCore/)
* Class [ServiceCommandsFixture](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs)
* Package [Fonlow.Testing.HttpCore](https://www.nuget.org/packages/Fonlow.Testing.HttpCore/)
* Class [BasicHttpClient](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.HttpCore/BasicHttpClient.cs)
* Class [HttpClientWithUsername](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.HttpCore/HttpClientWithUsername.cs)
* Class [TestingSettings](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.HttpCore/TestingSettings.cs)
* [Examples of Integration Test Suite](https://github.com/zijianhuang/DemoCoreWeb/tree/master/Tests/ServiceCommandIntegrationTests)

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static TestingSettings Create()
IConfigurationBuilder configBuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
obj.BuildConfiguration = GetBuildConfiguration();

if (Environment.OSVersion.Platform== PlatformID.Win32NT){
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
obj.ExecutableExt = ".exe";
}

Expand Down Expand Up @@ -131,6 +132,8 @@ static string GetBuildConfiguration()

public ServiceCommand[] ServiceCommands { get; set; }

public CopyItem[] CopyItems { get; set; }

/// <summary>
/// Build configuration of the test suite such as Debug, Release or whatever custom build configuration.
/// ServiceCommandFixture will replace {BuildConfiguration} in commandPath and arguments with this.
Expand All @@ -152,6 +155,12 @@ public sealed class UsernamePassword
public sealed class ServiceCommand
{
public string CommandPath { get; set; }

/// <summary>
/// Such as Get-Date, Copy-Item which will be executed synchronously, that is, wait for it finishes.
/// </summary>
public bool IsPowerShellCommand { get; set; }

public string Arguments { get; set; }

/// <summary>
Expand All @@ -167,4 +176,10 @@ public sealed class ServiceCommand
/// <remarks>Obviously 2FA and alike are not welcome. Good enough for integration tests, but not E2E.</remarks>
public UsernamePassword[] Users { get; set; }
}

public sealed class CopyItem
{
public string Source { get; set; }
public string Destination { get; set; }
}
}
10 changes: 6 additions & 4 deletions Fonlow.Testing.HttpCore/Fonlow.Testing.HttpCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
<PackageTags>xunit nunit mstest unittesting iisexpress iis webapi restful dotnet</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<Version>3.4.2</Version>
<Version>3.5-Alpha</Version>
<PackageReleaseNotes>Upgraded to .NET 8.</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisLevel>latest-all</AnalysisLevel>
Expand All @@ -25,8 +25,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
<None Include="../README.md" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fonlow.Testing.Basic\Fonlow.Testing.Basic.csproj" />
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions Fonlow.Testing.Integration/Fonlow.Testing.Integration.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0-Alpha</Version>
<Authors>Zijian Huang</Authors>
<Description>Utilities and fixtures for integration testing with xUnit</Description>
<PackageReleaseNotes></PackageReleaseNotes>
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
</PropertyGroup>

<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fonlow.Testing.HttpCore\Fonlow.Testing.HttpCore.csproj" />
<ProjectReference Include="..\Fonlow.Testing.ServiceCore\Fonlow.Testing.ServiceCore.csproj" />
</ItemGroup>

</Project>
77 changes: 42 additions & 35 deletions Fonlow.Testing.ServiceCore/Fonlow.Testing.ServiceCore.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Authors>Zijian Huang</Authors>
<Description>Setup and teardown of service resources in unit testing and integration testing.</Description>
<PackageReleaseNotes>upgraded to .NET 8. Linux and Github Actions friendly.</PackageReleaseNotes>
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>3.6.2</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fonlow.Testing.HttpCore\Fonlow.Testing.HttpCore.csproj" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Authors>Zijian Huang</Authors>
<Description>Setup and teardown of service resources in unit testing and integration testing.</Description>
<PackageReleaseNotes>upgraded to .NET 8. Linux and Github Actions friendly.</PackageReleaseNotes>
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>3.7-Alpha</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.3" />
</ItemGroup>


<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="/" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Fonlow.Testing.Basic\Fonlow.Testing.Basic.csproj" />
<ProjectReference Include="..\Fonlow.Testing.Utilities\Fonlow.Testing.Utilities.csproj" />
</ItemGroup>
</Project>
74 changes: 51 additions & 23 deletions Fonlow.Testing.ServiceCore/ServiceCommandAgent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Management.Automation;

namespace Fonlow.Testing
{
Expand All @@ -10,45 +12,71 @@ public class ServiceCommandAgent
{
public ServiceCommandAgent(ServiceCommand serviceCommand)
{
this.ServicCommand = serviceCommand;
this.Command = serviceCommand;
}

public ServiceCommand ServicCommand { get; private set; }
public ServiceCommand Command { get; private set; }

/// <summary>
/// Start DotNet Kestrel Web server.
/// </summary>
public void Start()
{
ProcessStartInfo info;
var dir = System.IO.Path.GetDirectoryName(ServicCommand.CommandPath);
if (string.IsNullOrEmpty(dir))
if (Command.IsPowerShellCommand)
{
info = new ProcessStartInfo(ServicCommand.CommandPath, ServicCommand.Arguments)
try
{
UseShellExecute = true,
};
using var ps = PowerShell.Create();
ps.AddScript(Command.CommandPath);//.AddArgument("c:/temp/auth.db").AddArgument("c:/temp/authGGGGGG.db");
var rs = ps.Invoke();
if (ps.HadErrors){
var errMsg = string.Join(Environment.NewLine, ps.Streams.Error.Select(d => d.ErrorDetails.ToString()));
Console.Error.WriteLine(errMsg);
}
}
catch (CommandNotFoundException ex)
{
Console.Error.WriteLine(ex);
throw;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
throw;
}
}
else
{
string command = System.IO.Path.GetFileName(ServicCommand.CommandPath);
string workingDir = System.IO.Path.GetFullPath(dir);
info = new ProcessStartInfo(command, ServicCommand.Arguments)
ProcessStartInfo info;
var dir = System.IO.Path.GetDirectoryName(Command.CommandPath);
if (string.IsNullOrEmpty(dir))
{
UseShellExecute = true,
WorkingDirectory = workingDir,
};
info = new ProcessStartInfo(Command.CommandPath, Command.Arguments)
{
UseShellExecute = true,
};
}
else
{
string command = System.IO.Path.GetFileName(Command.CommandPath);
string workingDir = System.IO.Path.GetFullPath(dir);
info = new ProcessStartInfo(command, Command.Arguments)
{
UseShellExecute = true,
WorkingDirectory = workingDir,
};

Console.WriteLine($"Working Dir: {workingDir}; Current Dir: {System.IO.Directory.GetCurrentDirectory()}");
}
Console.WriteLine($"Working Dir: {workingDir}; Current Dir: {System.IO.Directory.GetCurrentDirectory()}");
}

Console.WriteLine($"Starting {ServicCommand.CommandPath} {ServicCommand.Arguments} ...");
process = Process.Start(info);
timeStart = DateTime.Now;
Console.WriteLine($"Started: {ServicCommand.CommandPath} {ServicCommand.Arguments} at {timeStart}");
System.Threading.Thread.Sleep(this.ServicCommand.Delay * 1000);
timeStart = DateTime.Now;
Console.WriteLine($"Wait a second: {ServicCommand.CommandPath} {ServicCommand.Arguments} at {timeStart}");
Console.WriteLine($"Starting {Command.CommandPath} {Command.Arguments} ...");
process = Process.Start(info);
timeStart = DateTime.Now;
Console.WriteLine($"Started: {Command.CommandPath} {Command.Arguments} at {timeStart}");
System.Threading.Thread.Sleep(this.Command.Delay * 1000);
timeStart = DateTime.Now;
Console.WriteLine($"Wait a second: {Command.CommandPath} {Command.Arguments} at {timeStart}");
}
}

DateTime timeStart;
Expand Down
Loading

0 comments on commit 4c54882

Please sign in to comment.