Skip to content

Commit 4c54882

Browse files
committed
Fonlow.Testing.Integration
1 parent 4784c0b commit 4c54882

20 files changed

+531
-161
lines changed

DotNetPack.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$packCmd = 'dotnet pack $Name --no-build --output ./Release --configuration Release'
2-
$projList = 'Fonlow.Testing.HttpCore/Fonlow.Testing.HttpCore.csproj', 'Fonlow.Testing.ServiceCore/Fonlow.Testing.ServiceCore.csproj'
2+
$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'
33
foreach($name in $projList){
44
Invoke-Expression $ExecutionContext.InvokeCommand.ExpandString($packCmd)
55
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Version>1.0-Alpha</Version>
6+
<Authors>Zijian Huang</Authors>
7+
<Description>Basic types and functions of Fonlow.Testing.Integration suite.</Description>
8+
<PackageReleaseNotes></PackageReleaseNotes>
9+
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
10+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
11+
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
12+
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
13+
<NeutralLanguage>en</NeutralLanguage>
14+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<AnalysisLevel>latest-all</AnalysisLevel>
17+
</PropertyGroup>
18+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
19+
<IncludeSymbols>true</IncludeSymbols>
20+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
21+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
22+
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
23+
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
24+
</PropertyGroup>
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<None Include="./README.md" Pack="true" PackagePath="/" />
31+
</ItemGroup>
32+
</Project>

Fonlow.Testing.Basic/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Fonlow.Testing.Basic
2+
3+
Basic types and functions used by other packages of [Fonlow.Testing.Integration](https://www.nuget.org/packages/Fonlow.Testing.Integration/)
4+
5+
## NuGet Packages
6+
7+
### For .NET Core 8.0 +
8+
9+
* Package [Fonlow.Testing.Integration](https://www.nuget.org/packages/Fonlow.Testing.Integration/), including all packages.
10+
* Package [Fonlow.Testing.ServiceCore](https://www.nuget.org/packages/Fonlow.Testing.ServiceCore/)
11+
* Class [ServiceCommandsFixture](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs)
12+
* Package [Fonlow.Testing.HttpCore](https://www.nuget.org/packages/Fonlow.Testing.HttpCore/)
13+
* Class [BasicHttpClient](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.HttpCore/BasicHttpClient.cs)
14+
* Class [HttpClientWithUsername](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.HttpCore/HttpClientWithUsername.cs)
15+
* Class [TestingSettings](https://github.com/zijianhuang/FonlowTesting/blob/master/Fonlow.Testing.HttpCore/TestingSettings.cs)
16+
* [Examples of Integration Test Suite](https://github.com/zijianhuang/DemoCoreWeb/tree/master/Tests/ServiceCommandIntegrationTests)
17+

Fonlow.Testing.HttpCore/TestingSettings.cs renamed to Fonlow.Testing.Basic/TestingSettings.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static TestingSettings Create()
3131
IConfigurationBuilder configBuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
3232
obj.BuildConfiguration = GetBuildConfiguration();
3333

34-
if (Environment.OSVersion.Platform== PlatformID.Win32NT){
34+
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
35+
{
3536
obj.ExecutableExt = ".exe";
3637
}
3738

@@ -131,6 +132,8 @@ static string GetBuildConfiguration()
131132

132133
public ServiceCommand[] ServiceCommands { get; set; }
133134

135+
public CopyItem[] CopyItems { get; set; }
136+
134137
/// <summary>
135138
/// Build configuration of the test suite such as Debug, Release or whatever custom build configuration.
136139
/// ServiceCommandFixture will replace {BuildConfiguration} in commandPath and arguments with this.
@@ -152,6 +155,12 @@ public sealed class UsernamePassword
152155
public sealed class ServiceCommand
153156
{
154157
public string CommandPath { get; set; }
158+
159+
/// <summary>
160+
/// Such as Get-Date, Copy-Item which will be executed synchronously, that is, wait for it finishes.
161+
/// </summary>
162+
public bool IsPowerShellCommand { get; set; }
163+
155164
public string Arguments { get; set; }
156165

157166
/// <summary>
@@ -167,4 +176,10 @@ public sealed class ServiceCommand
167176
/// <remarks>Obviously 2FA and alike are not welcome. Good enough for integration tests, but not E2E.</remarks>
168177
public UsernamePassword[] Users { get; set; }
169178
}
179+
180+
public sealed class CopyItem
181+
{
182+
public string Source { get; set; }
183+
public string Destination { get; set; }
184+
}
170185
}

Fonlow.Testing.HttpCore/Fonlow.Testing.HttpCore.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
1111
<PackageTags>xunit nunit mstest unittesting iisexpress iis webapi restful dotnet</PackageTags>
1212
<NeutralLanguage>en</NeutralLanguage>
13-
<Version>3.4.2</Version>
13+
<Version>3.5-Alpha</Version>
1414
<PackageReleaseNotes>Upgraded to .NET 8.</PackageReleaseNotes>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
1616
<AnalysisLevel>latest-all</AnalysisLevel>
@@ -25,8 +25,10 @@
2525
</PropertyGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
29-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
30-
<None Include="..\README.md" Pack="true" PackagePath="\" />
28+
<None Include="../README.md" Pack="true" PackagePath="/" />
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<ProjectReference Include="..\Fonlow.Testing.Basic\Fonlow.Testing.Basic.csproj" />
3133
</ItemGroup>
3234
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Version>1.0-Alpha</Version>
6+
<Authors>Zijian Huang</Authors>
7+
<Description>Utilities and fixtures for integration testing with xUnit</Description>
8+
<PackageReleaseNotes></PackageReleaseNotes>
9+
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
10+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
11+
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
12+
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
13+
<NeutralLanguage>en</NeutralLanguage>
14+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<AnalysisLevel>latest-all</AnalysisLevel>
17+
</PropertyGroup>
18+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
19+
<IncludeSymbols>true</IncludeSymbols>
20+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
21+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
22+
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
23+
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<None Include="../README.md" Pack="true" PackagePath="/" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<ProjectReference Include="..\Fonlow.Testing.HttpCore\Fonlow.Testing.HttpCore.csproj" />
32+
<ProjectReference Include="..\Fonlow.Testing.ServiceCore\Fonlow.Testing.ServiceCore.csproj" />
33+
</ItemGroup>
34+
35+
</Project>
Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<Authors>Zijian Huang</Authors>
6-
<Description>Setup and teardown of service resources in unit testing and integration testing.</Description>
7-
<PackageReleaseNotes>upgraded to .NET 8. Linux and Github Actions friendly.</PackageReleaseNotes>
8-
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
9-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
10-
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
11-
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
12-
<NeutralLanguage>en</NeutralLanguage>
13-
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14-
<Version>3.6.2</Version>
15-
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
<AnalysisLevel>latest-all</AnalysisLevel>
17-
</PropertyGroup>
18-
19-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
20-
<IncludeSymbols>true</IncludeSymbols>
21-
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
22-
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
23-
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
24-
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
25-
</PropertyGroup>
26-
27-
<ItemGroup>
28-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
29-
</ItemGroup>
30-
31-
<ItemGroup>
32-
<ProjectReference Include="..\Fonlow.Testing.HttpCore\Fonlow.Testing.HttpCore.csproj" />
33-
<None Include="..\README.md" Pack="true" PackagePath="\" />
34-
</ItemGroup>
35-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Authors>Zijian Huang</Authors>
6+
<Description>Setup and teardown of service resources in unit testing and integration testing.</Description>
7+
<PackageReleaseNotes>upgraded to .NET 8. Linux and Github Actions friendly.</PackageReleaseNotes>
8+
<Copyright>Copyright © Fonlow 2015-$([System.DateTime]::Now.Year)</Copyright>
9+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
10+
<PackageProjectUrl>https://github.com/zijianhuang/FonlowTesting</PackageProjectUrl>
11+
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
12+
<NeutralLanguage>en</NeutralLanguage>
13+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14+
<Version>3.7-Alpha</Version>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<AnalysisLevel>latest-all</AnalysisLevel>
17+
</PropertyGroup>
18+
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
20+
<IncludeSymbols>true</IncludeSymbols>
21+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
22+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
23+
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
24+
<CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
25+
</PropertyGroup>
26+
27+
<ItemGroup>
28+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
29+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.3" />
30+
</ItemGroup>
31+
32+
33+
<ItemGroup>
34+
<None Include="../README.md" Pack="true" PackagePath="/" />
35+
</ItemGroup>
36+
37+
38+
<ItemGroup>
39+
<ProjectReference Include="..\Fonlow.Testing.Basic\Fonlow.Testing.Basic.csproj" />
40+
<ProjectReference Include="..\Fonlow.Testing.Utilities\Fonlow.Testing.Utilities.csproj" />
41+
</ItemGroup>
42+
</Project>

Fonlow.Testing.ServiceCore/ServiceCommandAgent.cs

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Linq;
4+
using System.Management.Automation;
35

46
namespace Fonlow.Testing
57
{
@@ -10,45 +12,71 @@ public class ServiceCommandAgent
1012
{
1113
public ServiceCommandAgent(ServiceCommand serviceCommand)
1214
{
13-
this.ServicCommand = serviceCommand;
15+
this.Command = serviceCommand;
1416
}
1517

16-
public ServiceCommand ServicCommand { get; private set; }
18+
public ServiceCommand Command { get; private set; }
1719

1820
/// <summary>
1921
/// Start DotNet Kestrel Web server.
2022
/// </summary>
2123
public void Start()
2224
{
23-
ProcessStartInfo info;
24-
var dir = System.IO.Path.GetDirectoryName(ServicCommand.CommandPath);
25-
if (string.IsNullOrEmpty(dir))
25+
if (Command.IsPowerShellCommand)
2626
{
27-
info = new ProcessStartInfo(ServicCommand.CommandPath, ServicCommand.Arguments)
27+
try
2828
{
29-
UseShellExecute = true,
30-
};
29+
using var ps = PowerShell.Create();
30+
ps.AddScript(Command.CommandPath);//.AddArgument("c:/temp/auth.db").AddArgument("c:/temp/authGGGGGG.db");
31+
var rs = ps.Invoke();
32+
if (ps.HadErrors){
33+
var errMsg = string.Join(Environment.NewLine, ps.Streams.Error.Select(d => d.ErrorDetails.ToString()));
34+
Console.Error.WriteLine(errMsg);
35+
}
36+
}
37+
catch (CommandNotFoundException ex)
38+
{
39+
Console.Error.WriteLine(ex);
40+
throw;
41+
}
42+
catch (Exception ex)
43+
{
44+
Console.Error.WriteLine(ex);
45+
throw;
46+
}
3147
}
3248
else
3349
{
34-
string command = System.IO.Path.GetFileName(ServicCommand.CommandPath);
35-
string workingDir = System.IO.Path.GetFullPath(dir);
36-
info = new ProcessStartInfo(command, ServicCommand.Arguments)
50+
ProcessStartInfo info;
51+
var dir = System.IO.Path.GetDirectoryName(Command.CommandPath);
52+
if (string.IsNullOrEmpty(dir))
3753
{
38-
UseShellExecute = true,
39-
WorkingDirectory = workingDir,
40-
};
54+
info = new ProcessStartInfo(Command.CommandPath, Command.Arguments)
55+
{
56+
UseShellExecute = true,
57+
};
58+
}
59+
else
60+
{
61+
string command = System.IO.Path.GetFileName(Command.CommandPath);
62+
string workingDir = System.IO.Path.GetFullPath(dir);
63+
info = new ProcessStartInfo(command, Command.Arguments)
64+
{
65+
UseShellExecute = true,
66+
WorkingDirectory = workingDir,
67+
};
4168

42-
Console.WriteLine($"Working Dir: {workingDir}; Current Dir: {System.IO.Directory.GetCurrentDirectory()}");
43-
}
69+
Console.WriteLine($"Working Dir: {workingDir}; Current Dir: {System.IO.Directory.GetCurrentDirectory()}");
70+
}
4471

45-
Console.WriteLine($"Starting {ServicCommand.CommandPath} {ServicCommand.Arguments} ...");
46-
process = Process.Start(info);
47-
timeStart = DateTime.Now;
48-
Console.WriteLine($"Started: {ServicCommand.CommandPath} {ServicCommand.Arguments} at {timeStart}");
49-
System.Threading.Thread.Sleep(this.ServicCommand.Delay * 1000);
50-
timeStart = DateTime.Now;
51-
Console.WriteLine($"Wait a second: {ServicCommand.CommandPath} {ServicCommand.Arguments} at {timeStart}");
72+
Console.WriteLine($"Starting {Command.CommandPath} {Command.Arguments} ...");
73+
process = Process.Start(info);
74+
timeStart = DateTime.Now;
75+
Console.WriteLine($"Started: {Command.CommandPath} {Command.Arguments} at {timeStart}");
76+
System.Threading.Thread.Sleep(this.Command.Delay * 1000);
77+
timeStart = DateTime.Now;
78+
Console.WriteLine($"Wait a second: {Command.CommandPath} {Command.Arguments} at {timeStart}");
79+
}
5280
}
5381

5482
DateTime timeStart;

0 commit comments

Comments
 (0)