File tree Expand file tree Collapse file tree 7 files changed +95
-11
lines changed
Expand file tree Collapse file tree 7 files changed +95
-11
lines changed Original file line number Diff line number Diff line change 120120 ],
121121 "cwd" : " ${workspaceFolder}/src/testr.Cli" ,
122122 "stopAtEntry" : false
123- }
123+ },
124+ {
125+ "name" : " testR:validate-TC-Login-001" ,
126+ "type" : " coreclr" ,
127+ "request" : " launch" ,
128+ "preLaunchTask" : " build-testR" ,
129+ "program" : " ${workspaceFolder}/src/testr.Cli/bin/Debug/net9.0/tomware.TestR.dll" ,
130+ "args" : [
131+ " validate" ,
132+ " TC-Login-001" ,
133+ " -i" ,
134+ " ../../samples/Definitions/localhost"
135+ ],
136+ "cwd" : " ${workspaceFolder}/src/testr.Cli" ,
137+ "stopAtEntry" : false
138+ },
124139 ]
125140}
Original file line number Diff line number Diff line change 1+ {
2+ "Id": "51458661-5966-40f2-8fd7-c8354380eadc",
3+ "IssueId": "",
4+ "Prefix": "Fixed",
5+ "Tag": "",
6+ "Message": "Fixed validation command for test cases that contain variables.",
7+ "CreatedAt": "2025-07-02T05:09:47.4358615+00:00",
8+ "CreatedBy": "thomasduft"
9+ }
Original file line number Diff line number Diff line change @@ -158,19 +158,12 @@ CancellationToken cancellationToken
158158 {
159159 _stopwatch . Reset ( ) ;
160160 var domain = _domain . ParsedValue ;
161- var variables = _variables . HasValue ( )
162- ? _variables . Values
163- . Where ( item => item ! . Contains ( '=' ) )
164- . Select ( item => item ! . Split ( '=' , 2 ) )
165- . Where ( parts => parts . Length == 2 )
166- . ToDictionary ( parts => parts [ 0 ] , parts => parts [ 1 ] )
167- : [ ] ;
168161
169162 // Read the Test Case definition
170163 var testCase = await TestCase . FromTestCaseFileAsync ( file , cancellationToken ) ;
171164 testCase
172165 . WithDomain ( domain )
173- . WithVariables ( variables ) ;
166+ . WithVariables ( VariablesHelper . CreateVariables ( _variables . Values ) ) ;
174167
175168 ConsoleHelper . WriteLineYellow ( $ "Running Test Case: { testCase . Id } ") ;
176169
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ private async Task<int> ExecuteAsync(CancellationToken cancellationToken)
3636
3737 // 2. Read the Test Case definition
3838 var testCase = await TestCase . FromTestCaseFileAsync ( file , cancellationToken ) ;
39+ testCase . WithVariables (
40+ VariablesHelper . CreateDummyVariables ( testCase . Steps )
41+ ) ;
3942
4043 // 3. Validate the Test Case definition
4144 var testCaseValidator = new TestCaseValidator ( testCase ) ;
@@ -54,4 +57,4 @@ private async Task<int> ExecuteAsync(CancellationToken cancellationToken)
5457
5558 return await Task . FromResult ( 0 ) ;
5659 }
57- }
60+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ internal class TestCase
1818 public string Domain => _domain ;
1919 public bool HasDomain => ! string . IsNullOrEmpty ( _domain ) ;
2020 public Dictionary < string , string > Variables { get ; set ; } = [ ] ;
21+ public bool HasVariables => Variables . Count > 0 ;
2122
2223 public TestCase WithDomain ( string domain )
2324 {
Original file line number Diff line number Diff line change 1+ using System . Text . RegularExpressions ;
2+
3+ namespace tomware . TestR ;
4+
5+ internal static class VariablesHelper
6+ {
7+ public static Dictionary < string , string > CreateVariables (
8+ IReadOnlyList < string ? > variables )
9+ {
10+ if ( variables == null || ! variables . Any ( ) )
11+ {
12+ return [ ] ;
13+ }
14+
15+ return variables
16+ . Select ( v => v . Split ( '=' ) )
17+ . Where ( parts => parts . Length == 2 )
18+ . ToDictionary ( parts => parts [ 0 ] . Trim ( ) , parts => parts [ 1 ] . Trim ( ) ) ;
19+ }
20+
21+ internal static Dictionary < string , string > CreateDummyVariables ( IEnumerable < TestStep > steps )
22+ {
23+ // For each test step data that contains a variable starting with an
24+ // @ sign, create a dummy variable
25+ var variables = new Dictionary < string , string > ( ) ;
26+ foreach ( var step in steps )
27+ {
28+ if ( string . IsNullOrWhiteSpace ( step . TestData ) )
29+ {
30+ continue ;
31+ }
32+
33+ var matches = Regex . Matches ( step . TestData , @"@(\w+)" ) ;
34+ foreach ( Match match in matches )
35+ {
36+ if ( ! variables . ContainsKey ( match . Groups [ 1 ] . Value ) )
37+ {
38+ variables . Add ( match . Groups [ 1 ] . Value , "dummy-value" ) ;
39+ }
40+ }
41+ }
42+ return variables ;
43+ }
44+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ namespace testr.Tests;
55public class TestCaseValidatorTests
66{
77 [ Fact ]
8- public async Task Validate_With4TestSteps_ShouldReturnNoValidationErrors ( )
8+ public async Task Validate_With4TestStepsAndRealVariables_ShouldReturnNoValidationErrors ( )
99 {
1010 // Arrange
1111 var file = Path . Combine ( Environment . CurrentDirectory , "TestData" , "TC-001-Login.md" ) ;
@@ -26,6 +26,25 @@ public async Task Validate_With4TestSteps_ShouldReturnNoValidationErrors()
2626 Assert . True ( result . IsValid ) ;
2727 }
2828
29+ [ Fact ]
30+ public async Task Validate_With4TestStepsAndDummyVariables_ShouldReturnNoValidationErrors ( )
31+ {
32+ // Arrange
33+ var file = Path . Combine ( Environment . CurrentDirectory , "TestData" , "TC-001-Login.md" ) ;
34+ var testCase = await TestCase
35+ . FromTestCaseFileAsync ( file , default ) ;
36+ testCase . WithVariables ( VariablesHelper . CreateDummyVariables ( testCase . Steps ) ) ;
37+
38+ var validator = new TestCaseValidator ( testCase ) ;
39+
40+ // Act
41+ var result = validator . Validate ( ) ;
42+
43+ // Assert
44+ Assert . NotNull ( result ) ;
45+ Assert . True ( result . IsValid ) ;
46+ }
47+
2948 [ Fact ]
3049 public async Task Validate_WithNotAllowedType_ShouldReturnOneValidationError ( )
3150 {
You can’t perform that action at this time.
0 commit comments