1
1
using Microsoft . Extensions . Configuration ;
2
2
using NBomber . Contracts ;
3
+ using NBomber . Contracts . Stats ;
3
4
using NBomber . CSharp ;
4
5
5
6
namespace CSharpProd . Features . CustomSettings ;
6
7
7
8
public class CustomScenarioSettings
8
9
{
9
- public int TestField { get ; set ; }
10
- public int PauseMs { get ; set ; }
10
+ public int MyTestField { get ; set ; }
11
+ public int MyPauseMs { get ; set ; }
11
12
}
12
13
13
14
public class CustomSettingsExample
@@ -19,8 +20,8 @@ Task Init(IScenarioInitContext initContext)
19
20
_customSettings = initContext . CustomSettings . Get < CustomScenarioSettings > ( ) ;
20
21
21
22
initContext . Logger . Information (
22
- "test init received CustomSettings.TestField '{TestField }'" ,
23
- _customSettings . TestField
23
+ "test init received CustomSettings.MyTestField '{0 }'" ,
24
+ _customSettings . MyTestField
24
25
) ;
25
26
26
27
return Task . CompletedTask ;
@@ -30,23 +31,33 @@ public void Run()
30
31
{
31
32
var scenario = Scenario . Create ( "my_scenario" , async context =>
32
33
{
33
- await Task . Delay ( _customSettings . PauseMs ) ;
34
+ await Task . Delay ( _customSettings . MyPauseMs ) ;
34
35
35
36
var step = await Step . Run ( "step" , context , async ( ) =>
36
37
{
37
38
await Task . Delay ( 1_000 ) ;
38
- context . Logger . Debug ( "step received CustomSettings.TestField '{0}'" , _customSettings . TestField ) ;
39
+ context . Logger . Debug ( "step received CustomSettings.MyTestField '{0}'" , _customSettings . MyTestField ) ;
39
40
return Response . Ok ( ) ;
40
41
} ) ;
41
42
42
43
return Response . Ok ( ) ;
43
44
} )
44
45
. WithInit ( Init )
45
- . WithoutWarmUp ( ) ;
46
+ . WithLoadSimulations ( Simulation . Inject ( rate : 50 , interval : TimeSpan . FromSeconds ( 1 ) , during : TimeSpan . FromMinutes ( 1 ) ) )
47
+ . WithWarmUpDuration ( TimeSpan . FromSeconds ( 10 ) )
48
+ . WithMaxFailCount ( 1_000 ) ;
46
49
47
50
NBomberRunner
48
51
. RegisterScenarios ( scenario )
49
52
. LoadConfig ( "./Features/CustomSettings/config.json" )
53
+ . WithTestSuite ( "my test suite" )
54
+ . WithTestName ( "my test name" )
55
+ . WithTargetScenarios ( "my_scenario" )
56
+ . WithReportFileName ( "my_report" )
57
+ . WithReportFolder ( "report_folder" )
58
+ . WithReportFormats ( ReportFormat . Txt , ReportFormat . Html )
59
+ . WithReportingInterval ( TimeSpan . FromSeconds ( 10 ) )
60
+ . EnableHintsAnalyzer ( true )
50
61
. Run ( ) ;
51
62
}
52
63
}
0 commit comments