Skip to content

Commit 4c54882

Browse files
committedJun 25, 2024·
Fonlow.Testing.Integration
1 parent 4784c0b commit 4c54882

20 files changed

+531
-161
lines changed
 

‎DotNetPack.ps1

+1-1
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
}
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

+17
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 ‎Fonlow.Testing.Basic/TestingSettings.cs

+16-1
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

+6-4
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>
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>
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

+51-23
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;

‎Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs

+62-51
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,67 @@
33

44
namespace Fonlow.Testing
55
{
6-
/// <summary>
7-
/// Launch services defined in TestingSettings
8-
/// </summary>
9-
public class ServiceCommandsFixture : IDisposable
10-
{
11-
/// <summary>
12-
/// Create the fixture. And this constructor is also used in XUnit.ICollectionFixture.
13-
/// </summary>
14-
public ServiceCommandsFixture()
15-
{
16-
foreach (var item in TestingSettings.Instance.ServiceCommands)
17-
{
18-
item.Arguments = item.Arguments?.Replace("{BuildConfiguration}", TestingSettings.Instance.BuildConfiguration);
19-
item.CommandPath = item.CommandPath?.Replace("{BuildConfiguration}", TestingSettings.Instance.BuildConfiguration);
20-
item.CommandPath = item.CommandPath?.Replace("{ExecutableExt}", TestingSettings.Instance.ExecutableExt);
21-
var serviceCommandAgent = new ServiceCommandAgent(item);
22-
serviceCommandAgent.Start();
23-
serviceCommandAgents.Add(serviceCommandAgent);
24-
}
25-
}
26-
27-
List<ServiceCommandAgent> serviceCommandAgents = new List<ServiceCommandAgent>();
28-
29-
bool disposed;
30-
31-
public void Dispose()
32-
{
33-
Dispose(true);
34-
GC.SuppressFinalize(this);
35-
}
36-
37-
protected virtual void Dispose(bool disposing)
38-
{
39-
if (!disposed)
40-
{
41-
if (disposing)
42-
{
43-
foreach (var agent in serviceCommandAgents)
44-
{
45-
if (agent != null)
46-
{
47-
agent.Stop();
48-
}
49-
}
50-
}
51-
52-
disposed = true;
53-
}
54-
}
55-
56-
}
6+
/// <summary>
7+
/// Launch services defined in TestingSettings
8+
/// </summary>
9+
public class ServiceCommandsFixture : IDisposable
10+
{
11+
/// <summary>
12+
/// Create the fixture. And this constructor is also used in XUnit.ICollectionFixture.
13+
/// </summary>
14+
public ServiceCommandsFixture()
15+
{
16+
if (TestingSettings.Instance.ServiceCommands != null)
17+
{
18+
foreach (var item in TestingSettings.Instance.ServiceCommands)
19+
{
20+
item.Arguments = item.Arguments?.Replace("{BuildConfiguration}", TestingSettings.Instance.BuildConfiguration);
21+
item.CommandPath = item.CommandPath?.Replace("{BuildConfiguration}", TestingSettings.Instance.BuildConfiguration);
22+
item.CommandPath = item.CommandPath?.Replace("{ExecutableExt}", TestingSettings.Instance.ExecutableExt);
23+
var serviceCommandAgent = new ServiceCommandAgent(item);
24+
serviceCommandAgent.Start();
25+
serviceCommandAgents.Add(serviceCommandAgent);
26+
}
27+
}
28+
29+
if (TestingSettings.Instance.CopyItems != null)
30+
{
31+
foreach (var item in TestingSettings.Instance.CopyItems)
32+
{
33+
DeploymentItemFixture.CopyDirectory(item.Source, item.Destination, true);
34+
}
35+
}
36+
}
37+
38+
List<ServiceCommandAgent> serviceCommandAgents = new List<ServiceCommandAgent>();
39+
40+
bool disposed;
41+
42+
public void Dispose()
43+
{
44+
Dispose(true);
45+
GC.SuppressFinalize(this);
46+
}
47+
48+
protected virtual void Dispose(bool disposing)
49+
{
50+
if (!disposed)
51+
{
52+
if (disposing)
53+
{
54+
foreach (var agent in serviceCommandAgents)
55+
{
56+
if (agent != null)
57+
{
58+
agent.Stop();
59+
}
60+
}
61+
}
62+
63+
disposed = true;
64+
}
65+
}
66+
67+
}
5768

5869
}

‎Fonlow.Testing.ServiceCore/DeploymentItemFixture.cs ‎Fonlow.Testing.Utilities/DeploymentItemFixture.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace Fonlow.Testing
66
{
77
/// <summary>
8-
/// Copy files from source to destination. If file exists, copy only newer.
8+
/// Copy files from source to destination. If file exists, copy only newer. Comparing with PS Copy-Item, this runs synchronously in the same thread.
9+
/// Start-ThreadJob is not working in .NET 8 with Microsoft.PowerShell.SDK.
910
/// </summary>
10-
[Obsolete("In favour of PowerShell scripts")]
11-
public class DeploymentItemFixture
11+
public sealed class DeploymentItemFixture
1212
{
1313
public DeploymentItemFixture()
1414
{
@@ -24,6 +24,7 @@ public DeploymentItemFixture()
2424
}
2525

2626
CopyDirectory(source, dest, true);
27+
System.Threading.Thread.Sleep(500);
2728
}
2829
}
2930

@@ -36,7 +37,7 @@ public DeploymentItemFixture()
3637
/// <param name="destinationDir"></param>
3738
/// <param name="recursive"></param>
3839
/// <exception cref="DirectoryNotFoundException"></exception>
39-
static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
40+
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
4041
{
4142
var dir = new DirectoryInfo(sourceDir);
4243
if (!dir.Exists)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Version>2.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+
<ProjectReference Include="..\Fonlow.Testing.Basic\Fonlow.Testing.Basic.csproj" />
27+
</ItemGroup>
28+
<ItemGroup>
29+
<None Include="./README.md" Pack="true" PackagePath="/" />
30+
</ItemGroup>
31+
</Project>

‎Fonlow.Testing.Utilities/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Fonlow.Testing.Utilities
2+
3+
Common utilities for setting up and tearing down assets used in integration testing, such as CopyItems.
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+

‎FonlowTesting.sln

+18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DemoServices", "DemoService
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceCommandIntegrationTests", "Tests\ServiceCommandTests\ServiceCommandIntegrationTests.csproj", "{7B224B32-9D36-4BF4-8363-1864F1700C13}"
2727
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fonlow.Testing.Basic", "Fonlow.Testing.Basic\Fonlow.Testing.Basic.csproj", "{17A001EB-5F92-4F04-96CD-8B0D3E8F26EF}"
29+
EndProject
30+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fonlow.Testing.Utilities", "Fonlow.Testing.Utilities\Fonlow.Testing.Utilities.csproj", "{F748EB4D-DCCA-43E0-8920-979EB4F3961E}"
31+
EndProject
32+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fonlow.Testing.Integration", "Fonlow.Testing.Integration\Fonlow.Testing.Integration.csproj", "{D01F765C-0CAC-4A3F-8323-10856AF78F87}"
33+
EndProject
2834
Global
2935
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3036
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +57,18 @@ Global
5157
{7B224B32-9D36-4BF4-8363-1864F1700C13}.Debug|Any CPU.Build.0 = Debug|Any CPU
5258
{7B224B32-9D36-4BF4-8363-1864F1700C13}.Release|Any CPU.ActiveCfg = Release|Any CPU
5359
{7B224B32-9D36-4BF4-8363-1864F1700C13}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{17A001EB-5F92-4F04-96CD-8B0D3E8F26EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61+
{17A001EB-5F92-4F04-96CD-8B0D3E8F26EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{17A001EB-5F92-4F04-96CD-8B0D3E8F26EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
63+
{17A001EB-5F92-4F04-96CD-8B0D3E8F26EF}.Release|Any CPU.Build.0 = Release|Any CPU
64+
{F748EB4D-DCCA-43E0-8920-979EB4F3961E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65+
{F748EB4D-DCCA-43E0-8920-979EB4F3961E}.Debug|Any CPU.Build.0 = Debug|Any CPU
66+
{F748EB4D-DCCA-43E0-8920-979EB4F3961E}.Release|Any CPU.ActiveCfg = Release|Any CPU
67+
{F748EB4D-DCCA-43E0-8920-979EB4F3961E}.Release|Any CPU.Build.0 = Release|Any CPU
68+
{D01F765C-0CAC-4A3F-8323-10856AF78F87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{D01F765C-0CAC-4A3F-8323-10856AF78F87}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{D01F765C-0CAC-4A3F-8323-10856AF78F87}.Release|Any CPU.ActiveCfg = Release|Any CPU
71+
{D01F765C-0CAC-4A3F-8323-10856AF78F87}.Release|Any CPU.Build.0 = Release|Any CPU
5472
EndGlobalSection
5573
GlobalSection(SolutionProperties) = preSolution
5674
HideSolutionNode = FALSE
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>OacgDemo</title>
6+
<base href="/">
7+
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link rel="icon" type="image/x-icon" href="favicon.ico">
10+
</head>
11+
<body>
12+
<app-root></app-root>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Some assets for integration testing, to be copied over.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Management.Automation;
6+
using System.Management.Automation.Runspaces;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Xunit;
10+
11+
namespace UnitTests
12+
{
13+
public class PowerShellTests
14+
{
15+
[Fact]
16+
public void TestBasic()
17+
{
18+
using var ps = PowerShell.Create();
19+
ps.AddCommand("Get-Date");
20+
var rs = ps.Invoke();
21+
Assert.NotEmpty(rs);
22+
}
23+
24+
[Fact]
25+
public void TestLaunchNotepad()
26+
{
27+
using var ps = PowerShell.Create();
28+
ps.AddCommand("Start-Process").AddArgument("notepad").AddParameter("-passthru");//.AddParameter("-Wait");
29+
var rs = ps.Invoke();
30+
Assert.NotEmpty(rs);
31+
Process process = rs[0].BaseObject as Process;
32+
33+
using var ps2 = PowerShell.Create();
34+
ps2.AddCommand("Stop-Process").AddParameter("-Id", process.Id);
35+
ps2.Invoke();
36+
}
37+
38+
[Fact]
39+
public void TestCopyItemWithArguments()
40+
{
41+
using var ps = PowerShell.Create();
42+
ps.AddCommand("Copy-Item").AddArgument("../../../PowerShellTests.cs").AddArgument("./_PowerShellTests.cs"); // argument cannot have space
43+
var rs = ps.Invoke();
44+
Assert.Empty(rs);
45+
Assert.False(ps.HadErrors);
46+
Assert.Empty(ps.Streams.Error);
47+
}
48+
49+
[Fact]
50+
public void TestCopyItemWithParameters()
51+
{
52+
using var ps = PowerShell.Create();
53+
ps.AddCommand("Copy-Item").AddParameter("-Path", "../../../PowerShellTests.cs").AddParameter("-Destination", "./CopiedPowerShellTests.cs");
54+
var rs = ps.Invoke();
55+
Assert.Empty(rs);
56+
Assert.False(ps.HadErrors);
57+
Assert.Empty(ps.Streams.Error);
58+
}
59+
60+
[Fact]
61+
public void TestCopyItemNotExists()
62+
{
63+
using var ps = PowerShell.Create();
64+
ps.AddCommand("Copy-Item").AddParameter("-Path", "../../../PowerShellKKK.cs").AddParameter("-Destination", "./CopiedPowerShellTests.cs");
65+
var rs = ps.Invoke();
66+
Assert.Empty(rs);
67+
Assert.True(ps.HadErrors);
68+
Assert.NotEmpty(ps.Streams.Error);
69+
}
70+
71+
[Fact]
72+
public void TestCopyItemWithScript()
73+
{
74+
using var ps = PowerShell.Create();
75+
ps.AddScript("Copy-Item ../../../PowerShellTests.cs ./A_PowerShellTests.cs");
76+
var rs = ps.Invoke();
77+
Assert.Empty(rs);
78+
Assert.False(ps.HadErrors);
79+
Assert.Empty(ps.Streams.Error);
80+
}
81+
82+
//[Fact]
83+
//public void TestCopyItemWithStartJobThrowsError()
84+
//{
85+
// using var ps = PowerShell.Create();
86+
// ps.AddScript("Start-ThreadJob -ScriptBlock {Copy-Item ../../../PowerShellTests.cs ./A_PowerShellTests.cs}");
87+
// var rs = ps.Invoke();
88+
// Assert.Empty(rs);
89+
// Assert.True(ps.HadErrors); //not supported as of .NET 8, Microsoft.PowerShell.SDK v7.4.3
90+
// //Assert.Empty(ps.Streams.Error);
91+
//}
92+
93+
//[Fact]
94+
//public void TestThreadJobThrowsError()//not supported as of .NET 8, Microsoft.PowerShell.SDK v7.4.3
95+
//{
96+
// using var ps = PowerShell.Create();
97+
// ps.AddCommand("Import-Module").AddArgument("ThreadJob").AddCommand("Start-ThreadJob")
98+
// .AddParameter("-ScriptBlock", "{Copy-Item ../../../PowerShellTests.cs ./A_PowerShellTests.cs}");
99+
// var rs = ps.Invoke();
100+
// //Assert.Empty(rs);
101+
// //Assert.True(ps.HadErrors);
102+
// //Assert.NotEmpty(ps.Streams.Error);
103+
//}
104+
105+
//[Fact]
106+
//public void TestThreadJobThrows()//not supported as of .NET 8, Microsoft.PowerShell.SDK v7.4.3
107+
//{
108+
// using Runspace runSpace = RunspaceFactory.CreateRunspace();
109+
// runSpace.Open();
110+
// var pipeline = runSpace.CreatePipeline();
111+
// pipeline.Commands.Add("Import-Module");
112+
// pipeline.Commands[0].Parameters.Add("-Name", "ThreadJob");
113+
// pipeline.Invoke();
114+
// using var ps = PowerShell.Create(runSpace);
115+
// ps.AddCommand("Start-ThreadJob")
116+
// .AddParameter("-ScriptBlock", "{Copy-Item ../../../PowerShellTests.cs ./A_PowerShellTests.cs}");
117+
// var rs = ps.Invoke();
118+
// //Assert.Empty(rs);
119+
// //Assert.True(ps.HadErrors);
120+
// //Assert.NotEmpty(ps.Streams.Error);
121+
//}
122+
123+
124+
}
125+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
8-
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
99
<ItemGroup>
1010
<None Remove="appsettings.Debug.json" />
1111
<None Remove="appsettings.json" />
1212
<None Remove="appsettings.Release.json" />
13-
</ItemGroup>
14-
13+
</ItemGroup>
14+
1515
<ItemGroup>
1616
<Content Include="appsettings.Debug.json">
1717
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -22,31 +22,31 @@
2222
<Content Include="appsettings.Release.json">
2323
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2424
</Content>
25-
</ItemGroup>
26-
27-
<ItemGroup>
28-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
29-
<PackageReference Include="xunit" Version="2.8.1" />
30-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
31-
<PrivateAssets>all</PrivateAssets>
32-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33-
</PackageReference>
34-
<PackageReference Include="coverlet.collector" Version="6.0.2">
35-
<PrivateAssets>all</PrivateAssets>
36-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
37-
</PackageReference>
38-
</ItemGroup>
39-
40-
<ItemGroup>
41-
<ProjectReference Include="..\..\DemoCoreWeb.ClientApi\DemoCoreWeb.ClientApi.csproj" />
42-
<ProjectReference Include="..\..\Fonlow.Testing.HttpCore\Fonlow.Testing.HttpCore.csproj" />
43-
<ProjectReference Include="..\..\Fonlow.Testing.ServiceCore\Fonlow.Testing.ServiceCore.csproj" />
44-
</ItemGroup>
45-
46-
<ItemGroup>
47-
<None Update="xunit.runner.json">
48-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49-
</None>
50-
</ItemGroup>
51-
52-
</Project>
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
29+
<PackageReference Include="xunit" Version="2.8.1" />
30+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
31+
<PrivateAssets>all</PrivateAssets>
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33+
</PackageReference>
34+
<PackageReference Include="coverlet.collector" Version="6.0.2">
35+
<PrivateAssets>all</PrivateAssets>
36+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
37+
</PackageReference>
38+
</ItemGroup>
39+
40+
<ItemGroup>
41+
<ProjectReference Include="..\..\DemoCoreWeb.ClientApi\DemoCoreWeb.ClientApi.csproj" />
42+
<ProjectReference Include="..\..\Fonlow.Testing.HttpCore\Fonlow.Testing.HttpCore.csproj" />
43+
<ProjectReference Include="..\..\Fonlow.Testing.ServiceCore\Fonlow.Testing.ServiceCore.csproj" />
44+
</ItemGroup>
45+
46+
<ItemGroup>
47+
<None Update="xunit.runner.json">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</None>
50+
</ItemGroup>
51+
52+
</Project>

‎Tests/ServiceCommandTests/UnitTest1.cs ‎Tests/ServiceCommandTests/WeatherIntegrationTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class WhetherApiFixture : BasicHttpClient
88
{
99
public WhetherApiFixture()
1010
{
11-
var c = TestingSettings.Instance.ServiceCommands[0];
11+
var c = TestingSettings.Instance.ServiceCommands[1];
1212
this.HttpClient.BaseAddress = new System.Uri(c.BaseUrl);
1313
Api = new DemoCoreWeb.Controllers.Client.WeatherForecast(this.HttpClient);
1414
}
@@ -17,9 +17,9 @@ public WhetherApiFixture()
1717
}
1818

1919
[Collection("ServicesLaunch")]
20-
public class UnitTest1: IClassFixture<WhetherApiFixture>
20+
public class WeatherIntegrationTests: IClassFixture<WhetherApiFixture>
2121
{
22-
public UnitTest1(WhetherApiFixture fixture)
22+
public WeatherIntegrationTests(WhetherApiFixture fixture)
2323
{
2424
api = fixture.Api;
2525
}
+17-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
{
22
"Testing": {
33
"ServiceCommands": [
4+
{
5+
"CommandPath": "Copy-Item ../../../PowerShellTests.cs ./D_PowerShellTests.cs",
6+
"IsPowerShellCommand": true
7+
},
48
{
59
"CommandPath": "../../../../../DemoCoreWeb/bin/{BuildConfiguration}/net8.0/DemoCoreWeb{ExecutableExt}",
610
"BaseUrl": "http://127.0.0.1:5000/",
7-
"Delay": 2
11+
"Delay": 3
12+
},
13+
{
14+
"CommandPath": "Start-Process notepad",
15+
"IsPowerShellCommand": true
16+
}
17+
18+
],
19+
"CopyItems": [
20+
{
21+
"Source": "../../../Assets",
22+
"Destination": "./Assets"
823
}
924
]
25+
1026
}
1127
}

0 commit comments

Comments
 (0)
Please sign in to comment.