@@ -32,11 +32,13 @@ public class SpecFlowUnitTestConverter : ISpecFlowUnitTestConverter
32
32
private const string SPECFLOW_NAMESPACE = "TechTalk.SpecFlow" ;
33
33
34
34
private readonly IUnitTestGeneratorProvider testGeneratorProvider ;
35
+ private readonly CodeDomHelper codeDomHelper ;
35
36
private readonly bool allowDebugGeneratedFiles ;
36
37
37
- public SpecFlowUnitTestConverter ( IUnitTestGeneratorProvider testGeneratorProvider , bool allowDebugGeneratedFiles )
38
+ public SpecFlowUnitTestConverter ( IUnitTestGeneratorProvider testGeneratorProvider , CodeDomHelper codeDomHelper , bool allowDebugGeneratedFiles )
38
39
{
39
40
this . testGeneratorProvider = testGeneratorProvider ;
41
+ this . codeDomHelper = codeDomHelper ;
40
42
this . allowDebugGeneratedFiles = allowDebugGeneratedFiles ;
41
43
}
42
44
@@ -125,7 +127,7 @@ private CodeMemberMethod GenerateTestFixtureSetup(CodeTypeDeclaration testType,
125
127
setupMethod . Statements . Add (
126
128
new CodeVariableDeclarationStatement ( FEATUREINFO_TYPE , "featureInfo" ,
127
129
new CodeObjectCreateExpression ( FEATUREINFO_TYPE ,
128
- new CodeObjectCreateExpression ( typeof ( CultureInfo ) ,
130
+ new CodeObjectCreateExpression ( typeof ( CultureInfo ) ,
129
131
new CodePrimitiveExpression ( feature . Language ) ) ,
130
132
new CodePrimitiveExpression ( feature . Title ) ,
131
133
new CodePrimitiveExpression ( feature . Description ) ,
@@ -152,7 +154,7 @@ private CodeExpression GetStringArrayExpression(Tags tags)
152
154
items . Add ( new CodePrimitiveExpression ( tag . Name ) ) ;
153
155
}
154
156
155
- return new CodeArrayCreateExpression ( typeof ( string [ ] ) , items . ToArray ( ) ) ;
157
+ return new CodeArrayCreateExpression ( typeof ( string [ ] ) , items . ToArray ( ) ) ;
156
158
}
157
159
158
160
private CodeExpression GetStringArrayExpression ( IEnumerable < string > items , ParameterSubstitution paramToIdentifier )
@@ -163,7 +165,7 @@ private CodeExpression GetStringArrayExpression(IEnumerable<string> items, Param
163
165
expressions . Add ( GetSubstitutedString ( item , paramToIdentifier ) ) ;
164
166
}
165
167
166
- return new CodeArrayCreateExpression ( typeof ( string [ ] ) , expressions . ToArray ( ) ) ;
168
+ return new CodeArrayCreateExpression ( typeof ( string [ ] ) , expressions . ToArray ( ) ) ;
167
169
}
168
170
169
171
private CodeMemberMethod GenerateTestFixtureTearDown ( CodeTypeDeclaration testType )
@@ -327,7 +329,7 @@ private void GenerateScenarioOutlineBody(Feature feature, ScenarioOutline scenar
327
329
328
330
foreach ( var pair in paramToIdentifier )
329
331
{
330
- testMethod . Parameters . Add ( new CodeParameterDeclarationExpression ( typeof ( string ) , pair . Value ) ) ;
332
+ testMethod . Parameters . Add ( new CodeParameterDeclarationExpression ( typeof ( string ) , pair . Value ) ) ;
331
333
}
332
334
333
335
GenerateTestBody ( feature , scenarioOutline , testMethod , testSetup , paramToIdentifier ) ;
@@ -397,7 +399,7 @@ private CodeMemberMethod GetTestMethodDeclaration(CodeTypeDeclaration testType,
397
399
{
398
400
CodeMemberMethod testMethod = new CodeMemberMethod ( ) ;
399
401
testType . Members . Add ( testMethod ) ;
400
-
402
+
401
403
testMethod . Attributes = MemberAttributes . Public ;
402
404
testMethod . Name = string . Format ( TEST_FORMAT , scenario . Title . ToIdentifier ( ) ) ;
403
405
@@ -446,7 +448,7 @@ private CodeExpression GetSubstitutedString(string text, ParameterSubstitution p
446
448
formatArguments . Add ( new CodeVariableReferenceExpression ( id ) ) ;
447
449
448
450
return new CodeMethodInvokeExpression (
449
- new CodeTypeReferenceExpression ( typeof ( string ) ) ,
451
+ new CodeTypeReferenceExpression ( typeof ( string ) ) ,
450
452
"Format" ,
451
453
formatArguments . ToArray ( ) ) ;
452
454
}
@@ -513,50 +515,41 @@ private CodeExpression GetMultilineTextArgExpression(string multiLineTextArgumen
513
515
514
516
private void AddLinePragmaInitial ( CodeTypeDeclaration testType , Feature feature )
515
517
{
516
- if ( allowDebugGeneratedFiles )
517
- return ;
518
+ if ( allowDebugGeneratedFiles )
519
+ return ;
518
520
519
- testType . Members . Add ( new CodeSnippetTypeMember ( string . Format ( "#line 1 \" {0}\" " , Path . GetFileName ( feature . SourceFile ) ) ) ) ;
520
- testType . Members . Add ( new CodeSnippetTypeMember ( "#line hidden" ) ) ;
521
+ codeDomHelper . BindTypeToSourceFile ( testType , Path . GetFileName ( feature . SourceFile ) ) ;
521
522
}
522
523
523
524
private void AddLineDirectiveHidden ( CodeStatementCollection statements )
524
525
{
525
526
if ( allowDebugGeneratedFiles )
526
527
return ;
527
528
528
- statements . Add ( new CodeSnippetStatement ( "#line hidden" ) ) ;
529
+ codeDomHelper . AddDisableSourceLinePragmaStatement ( statements ) ;
529
530
}
530
531
531
532
private void AddLineDirective ( CodeStatementCollection statements , Background background )
532
533
{
533
- AddLineDirective ( statements , null , background . FilePosition ) ;
534
+ AddLineDirective ( statements , background . FilePosition ) ;
534
535
}
535
536
536
537
private void AddLineDirective ( CodeStatementCollection statements , Scenario scenario )
537
538
{
538
- AddLineDirective ( statements , null , scenario . FilePosition ) ;
539
+ AddLineDirective ( statements , scenario . FilePosition ) ;
539
540
}
540
541
541
542
private void AddLineDirective ( CodeStatementCollection statements , ScenarioStep step )
542
543
{
543
- AddLineDirective ( statements , null , step . FilePosition ) ;
544
+ AddLineDirective ( statements , step . FilePosition ) ;
544
545
}
545
546
546
- private void AddLineDirective ( CodeStatementCollection statements , string sourceFile , FilePosition filePosition )
547
+ private void AddLineDirective ( CodeStatementCollection statements , FilePosition filePosition )
547
548
{
548
549
if ( filePosition == null || allowDebugGeneratedFiles )
549
550
return ;
550
551
551
- if ( sourceFile == null )
552
- statements . Add ( new CodeSnippetStatement (
553
- string . Format ( "#line {0}" , filePosition . Line ) ) ) ;
554
- else
555
- statements . Add ( new CodeSnippetStatement (
556
- string . Format ( "#line {0} \" {1}\" " , filePosition . Line , Path . GetFileName ( sourceFile ) ) ) ) ;
557
-
558
- statements . Add ( new CodeSnippetStatement (
559
- string . Format ( "//#indentnext {0}" , filePosition . Column - 1 ) ) ) ;
552
+ codeDomHelper . AddSourceLinePragmaStatement ( statements , filePosition . Line , filePosition . Column ) ;
560
553
}
561
554
562
555
#endregion
0 commit comments