1
+ using System ;
2
+ using System . Threading ;
3
+ using Microsoft . Vbe . Interop ;
4
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
5
+ using Moq ;
6
+ using Rubberduck . Parsing ;
7
+ using Rubberduck . Parsing . VBA ;
8
+ using Rubberduck . UI . Command ;
9
+ using Rubberduck . UnitTesting ;
10
+ using Rubberduck . VBEditor . Extensions ;
11
+ using Rubberduck . VBEditor . VBEHost ;
12
+ using RubberduckTests . Mocks ;
13
+
14
+ namespace RubberduckTests . Commands
15
+ {
16
+ [ TestClass ]
17
+ public class AddTestMethodCommandTests
18
+ {
19
+ [ TestMethod ]
20
+ public void AddsTest ( )
21
+ {
22
+ var input =
23
+ @"Option Explicit
24
+ Option Private Module
25
+
26
+
27
+ '@TestModule
28
+ Private Assert As Object
29
+ {0}" ;
30
+
31
+ var builder = new MockVbeBuilder ( ) ;
32
+ VBComponent component ;
33
+ var vbe = builder . BuildFromSingleStandardModule ( string . Format ( input , string . Empty ) , out component ) ;
34
+ var mockHost = new Mock < IHostApplication > ( ) ;
35
+ mockHost . SetupAllProperties ( ) ;
36
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
37
+
38
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
39
+ if ( parser . State . Status >= ParserState . Error )
40
+ {
41
+ Assert . Inconclusive ( "Parser Error" ) ;
42
+ }
43
+
44
+ var newTestMethodCommand = new Mock < NewTestMethodCommand > ( vbe . Object , parser . State ) ;
45
+ var addTestMethodCommand = new AddTestMethodCommand ( vbe . Object , parser . State , newTestMethodCommand . Object ) ;
46
+
47
+ addTestMethodCommand . Execute ( null ) ;
48
+
49
+ Assert . AreEqual (
50
+ string . Format ( input ,
51
+ NewTestMethodCommand . TestMethodTemplate . Replace ( NewTestMethodCommand . NamePlaceholder , "TestMethod1" ) ) +
52
+ Environment . NewLine , vbe . Object . ActiveCodePane . CodeModule . Lines ( ) ) ;
53
+ }
54
+
55
+ [ TestMethod ]
56
+ public void AddsExpectedErrorTest ( )
57
+ {
58
+ var input =
59
+ @"Option Explicit
60
+ Option Private Module
61
+
62
+
63
+ '@TestModule
64
+ Private Assert As Object
65
+ {0}" ;
66
+
67
+ var builder = new MockVbeBuilder ( ) ;
68
+ VBComponent component ;
69
+ var vbe = builder . BuildFromSingleStandardModule ( string . Format ( input , string . Empty ) , out component ) ;
70
+ var mockHost = new Mock < IHostApplication > ( ) ;
71
+ mockHost . SetupAllProperties ( ) ;
72
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
73
+
74
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
75
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
76
+
77
+ var newTestMethodCommand = new Mock < NewTestMethodCommand > ( vbe . Object , parser . State ) ;
78
+ var addTestMethodCommand = new AddTestMethodExpectedErrorCommand ( vbe . Object , parser . State , newTestMethodCommand . Object ) ;
79
+
80
+ addTestMethodCommand . Execute ( null ) ;
81
+
82
+ Assert . AreEqual (
83
+ string . Format ( input ,
84
+ NewTestMethodCommand . TestMethodExpectedErrorTemplate . Replace ( NewTestMethodCommand . NamePlaceholder ,
85
+ "TestMethod1" ) ) + Environment . NewLine , vbe . Object . ActiveCodePane . CodeModule . Lines ( ) ) ;
86
+ }
87
+ }
88
+ }
0 commit comments