Skip to content

Commit 6f501a2

Browse files
authored
Merge pull request #6 from gcastellov/feature/net8
Feature/net8
2 parents b9750dd + 8fa263f commit 6f501a2

11 files changed

Lines changed: 168 additions & 95 deletions

File tree

.github/workflows/dotnet-core.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
name: .NET Core
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET
25

36
on:
47
push:
5-
branches: [ main ]
8+
branches: [ "main" ]
69
pull_request:
7-
branches: [ main ]
10+
branches: [ "main" ]
811

912
jobs:
1013
build:
1114

1215
runs-on: ubuntu-latest
1316

1417
steps:
15-
- uses: actions/checkout@v2
16-
- name: Setup .NET Core
17-
uses: actions/setup-dotnet@v1
18+
- uses: actions/checkout@v4
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v4
1821
with:
19-
dotnet-version: 3.1.301
22+
dotnet-version: 8.0.x
2023
- name: Install dependencies
2124
run: dotnet restore ./src/FluentEndurance.sln
2225
- name: Build

README.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
![.NET Core](https://github.com/gcastellov/fluent-endurance/workflows/.NET%20Core/badge.svg)
2-
![Publish NuGet](https://github.com/gcastellov/fluent-endurance/workflows/Publish%20NuGet/badge.svg?branch=main&event=push)
31

42
# FluentEndurance
53
A fluent endurance automation framework whose API helps you to fluently create your endurance tests defining repetitions and timeouts.
64

5+
![FluentEndurance](img/logo512x512.png)
76

87
## Samples
98
For the sake of providing some examples, the solution contains set of tests which simulates certain car features.
@@ -72,34 +71,6 @@ public Task CarShouldMakeItsRoutineTwice()
7271
.Run();
7372
```
7473

75-
76-
## Setup your tests
77-
This library depends on *IMediator* for triggering events in order to provide certain status about performance during the execution.
78-
79-
The library provides a base class *BaseTest* which registers the *IMediator* default implementation and also provides a helper method to easly start defining the tests. Nonetheless, is up to you whether use this class or implement yours depending on your needs.
80-
81-
82-
```csharp
83-
protected BaseTest(Action<IConfigurationBuilder> configureApp, Action<IServiceCollection> configureServices)
84-
{
85-
var hostBuilder = new HostBuilder();
86-
hostBuilder.ConfigureAppConfiguration(builder =>
87-
{
88-
configureApp(builder);
89-
_configuration = builder.Build();
90-
});
91-
92-
hostBuilder.ConfigureServices(collection =>
93-
{
94-
collection.AddScoped<FeatureSetGroup>();
95-
collection.AddSingleton<IMediator>(sp => new Mediator(sp.GetService));
96-
configureServices(collection);
97-
});
98-
99-
_host = hostBuilder.Build();
100-
}
101-
```
102-
10374
## Output status
10475

10576
There are two ways of collecting notifications:

img/logo.png

1.41 MB
Loading

img/logo512x512.png

111 KB
Loading

src/FluentEndurance.Samples/FluentEndurance.Samples.csproj

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
4+
<TargetFramework>net8.0</TargetFramework>
65
<IsPackable>false</IsPackable>
76
</PropertyGroup>
87

98
<ItemGroup>
10-
<PackageReference Include="MediatR" Version="9.0.0" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
12-
<PackageReference Include="xunit" Version="2.4.1" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16-
</PackageReference>
17-
<PackageReference Include="coverlet.collector" Version="1.3.0">
9+
<PackageReference Include="MediatR" Version="13.0.0" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
11+
<PackageReference Include="xunit" Version="2.9.3" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
1813
<PrivateAssets>all</PrivateAssets>
1914
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2015
</PackageReference>

src/FluentEndurance/BaseTest.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
11
using System;
2-
using MediatR;
32
using Microsoft.Extensions.Configuration;
43
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.Extensions.Hosting;
64

75
namespace FluentEndurance
86
{
97
public abstract class BaseTest
108
{
11-
private readonly IHost _host;
12-
private IConfigurationRoot _configuration;
9+
private readonly IConfigurationRoot _configuration;
10+
private readonly IServiceProvider _serviceProvider;
1311

14-
protected BaseTest(Action<IConfigurationBuilder> configureApp, Action<IServiceCollection> configureServices)
12+
protected BaseTest(Action<IConfigurationBuilder> configureApp, Action<IServiceCollection> configureServices)
1513
{
16-
var hostBuilder = new HostBuilder();
17-
hostBuilder.ConfigureAppConfiguration(builder =>
18-
{
19-
configureApp(builder);
20-
_configuration = builder.Build();
21-
});
22-
23-
hostBuilder.ConfigureServices(collection =>
24-
{
25-
collection.AddScoped<FeatureSetGroup>();
26-
collection.AddSingleton<IMediator>(sp => new Mediator(sp.GetService));
27-
configureServices(collection);
28-
});
29-
30-
_host = hostBuilder.Build();
14+
var configBuilder = new ConfigurationBuilder();
15+
var services = new ServiceCollection()
16+
.AddLogging()
17+
.AddScoped<FeatureSetGroup>()
18+
.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(this.GetType().Assembly));
19+
20+
configureServices(services);
21+
configureApp(configBuilder);
22+
23+
_configuration = configBuilder.Build();
24+
_serviceProvider = services.BuildServiceProvider();
3125
}
3226

33-
protected IHost Host => _host;
34-
3527
protected IConfigurationRoot Configuration => _configuration;
3628

37-
protected FeatureSetGroup UseFeatureSetGroup()
38-
{
39-
return _host.Services.GetService<FeatureSetGroup>();
40-
}
29+
protected FeatureSetGroup UseFeatureSetGroup() => _serviceProvider.GetRequiredService<FeatureSetGroup>();
4130
}
4231
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
# FluentEndurance
3+
A fluent endurance automation framework whose API helps you to fluently create your endurance tests defining repetitions and timeouts.
4+
5+
6+
## Samples
7+
For the sake of providing some examples, the solution contains set of tests which simulates certain car features.
8+
9+
In the following snippet the engine must start within 1200 ms and stop within 800 ms. If any of these two operation reach the timing the execution fails. This set of operations will repeat for 50 times.
10+
11+
```csharp
12+
[Fact]
13+
public Task EngineShouldStartAndStop()
14+
=> UseFeatureSetGroup().For(Times.As(50))
15+
.WithSet(group => group.Create()
16+
.WithStep(_engineFeature, (engine, ct) => engine.Start(ct), Milliseconds.As(1200))
17+
.WithStep(_engineFeature, (engine, ct) => engine.Stop(ct), Milliseconds.As(800)))
18+
.Run();
19+
```
20+
21+
Which outputs:
22+
```
23+
Executed engine.Start(ct) taking 1007.4665 ms
24+
Executed engine.Stop(ct) taking 60.9244 ms
25+
Executed engine.Start(ct) taking 1002.506 ms
26+
Executed engine.Stop(ct) taking 58.2176 ms
27+
...
28+
```
29+
30+
Timespans can be used in order to define how long the operations must take instead of repeating them certain times.
31+
32+
```csharp
33+
[Fact]
34+
public Task EngineShouldStartRevAndStopDuringTime()
35+
=> UseFeatureSetGroup().During(Minutes.As(1))
36+
.WithSet(group => group.Create().During(Seconds.As(20))
37+
.WithStep(_engineFeature, (engine, ct) => engine.Start(ct))
38+
.WithStep(_engineFeature, (engine, ct) => engine.Rev3000(ct))
39+
.WithStep(_engineFeature, (engine, ct) => engine.Stop(ct)))
40+
.Run();
41+
```
42+
43+
Another more complete sample.
44+
45+
```csharp
46+
[Fact]
47+
public Task CarShouldMakeItsRoutineTwice()
48+
=> UseFeatureSetGroup().For(Times.As(2))
49+
.WithSet(group => group.Create().As("Warm up")
50+
.WithStep(_engineFeature, (engine, ct) => engine.Start(ct))
51+
.WithStep(_engineFeature, (engine, ct) => engine.Rev3000(ct)))
52+
.WithSet(group => group.Create().As("Routine")
53+
.WithStep(_autopilotFeature, (autopilot, ct) => autopilot.UnPark(ct))
54+
.WithStep(_gearsFeature, (gears, ct) => gears.ChangeToNeutral(ct))
55+
.WithStep(_gearsFeature, (gears, ct) => gears.ChangeToDrive(ct)))
56+
.WithSet(group => group.Create().As("Maneuvers").For(Times.Twice)
57+
.WithStep(_engineFeature, (engine, ct) => engine.Accelerate100(ct))
58+
.WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Drive(ct))
59+
.WithStep(_steeringFeature, (steering, ct) => steering.Left(ct))
60+
.WithStep(_steeringFeature, (steering, ct) => steering.Forward(ct))
61+
.WithStep(_steeringFeature, (steering, ct) => steering.Right(ct))
62+
.WithStep(_steeringFeature, (steering, ct) => steering.Forward(ct))
63+
.WithStep(_engineFeature, (engine, ct) => engine.Accelerate150(ct))
64+
.WithStep(_brakesFeature, (brakes, ct) => brakes.BrakeTo50(ct))
65+
.WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Drive(ct))
66+
.WithStep(_brakesFeature, (brakes, ct) => brakes.BrakeTo0(ct)))
67+
.WithSet(group => group.Create().As("Park")
68+
.WithStep(_engineFeature, (engine, ct) => engine.Stop(ct))
69+
.WithStep(_autopilotFeature, (autopilot, ct) => autopilot.Park(ct)))
70+
.Run();
71+
```
72+
73+
## Output status
74+
75+
There are two ways of collecting notifications:
76+
* Live notifications by subscribing to these events.
77+
* Reading the events each feature has triggered at the end of the test execution.
78+
79+
80+
### Live notifications using notification handlers
81+
```csharp
82+
public MotionTests(ITestOutputHelper output)
83+
: base(
84+
_ => { },
85+
services =>
86+
{
87+
var notificationHandler = new StatusNotificationHandler();
88+
notificationHandler.Write += output.WriteLine;
89+
services.AddSingleton<INotificationHandler<StatusNotification>>(notificationHandler);
90+
services.AddSingleton<INotificationHandler<PerformanceStatusNotification>>(notificationHandler);
91+
})
92+
{
93+
// ...
94+
}
95+
```
96+
97+
### Reading feature events
98+
```csharp
99+
public Task DisposeAsync()
100+
{
101+
foreach (var notification in _engineFeature.Notifications)
102+
{
103+
_output.WriteLine(notification.Content);
104+
}
105+
106+
return Task.CompletedTask;
107+
}
108+
```
4.28 KB
Loading
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<NeutralLanguage>en-US</NeutralLanguage>
66
<Authors>Gerard Castello</Authors>
7-
<Company />
8-
<Product />
97
<Description>A fluent endurance automation framework</Description>
108
<RepositoryUrl>https://github.com/gcastellov/fluent-endurance</RepositoryUrl>
119
<RepositoryType>git</RepositoryType>
12-
<PackageTags>endurance automation netstandard21 testing</PackageTags>
13-
<Version>1.2.1</Version>
10+
<PackageTags>endurance automation testing</PackageTags>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<PackageIcon>Content/logo.png</PackageIcon>
13+
<PackageReadmeFile>Content/README.md</PackageReadmeFile>
14+
<Version>2.0.0</Version>
1415
</PropertyGroup>
1516

1617
<ItemGroup>
17-
<PackageReference Include="MediatR" Version="9.0.0" />
18-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
18+
<PackageReference Include="MediatR" Version="13.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.8" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<None Include="Content/logo.png">
24+
<Pack>True</Pack>
25+
<PackagePath>\Content</PackagePath>
26+
</None>
27+
<None Include="Content/README.md">
28+
<Pack>True</Pack>
29+
<PackagePath>\Content</PackagePath>
30+
</None>
1931
</ItemGroup>
2032

2133
</Project>

test/FluentEndurance.Tests/FluentEndurance.Tests.csproj

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
4+
<TargetFramework>net8.0</TargetFramework>
65
<IsPackable>false</IsPackable>
76
</PropertyGroup>
87

98
<ItemGroup>
10-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
12-
<PackageReference Include="Moq" Version="4.15.2" />
13-
<PackageReference Include="xunit" Version="2.4.1" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15-
<PrivateAssets>all</PrivateAssets>
16-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17-
</PackageReference>
18-
<PackageReference Include="coverlet.collector" Version="1.3.0">
9+
<PackageReference Include="FluentAssertions" Version="8.6.0" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
11+
<PackageReference Include="Moq" Version="4.20.72" />
12+
<PackageReference Include="xunit" Version="2.9.3" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
1914
<PrivateAssets>all</PrivateAssets>
2015
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2116
</PackageReference>

0 commit comments

Comments
 (0)