@@ -14,21 +14,25 @@ public class SettingsViewModelTests
14
14
private const string Name = "Chris McClellan" ;
15
15
private const string Email = "ckuhn203@gmail" ;
16
16
private const string RepoLocation = @"C:\Users\Christopher\Documents" ;
17
+ private const string CommandPromptLocation = "cmd.exe" ;
17
18
18
19
private const string OtherName = "King Lear" ;
19
20
private const string OtherEmail = "king.lear@yahoo.com" ;
20
21
private const string OtherRepoLocation = @"C:\Users\KingLear\Documents" ;
22
+ private const string OtherCommandPromptLocation = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" ;
21
23
22
24
private Mock < ISourceControlConfigProvider > _configService ;
23
25
private SourceControlSettings _config ;
24
26
25
27
private Mock < IFolderBrowserFactory > _folderBrowserFactory ;
26
28
private Mock < IFolderBrowser > _folderBrowser ;
27
29
30
+ private Mock < IOpenFileDialog > _openFileDialog ;
31
+
28
32
[ TestInitialize ]
29
33
public void Initialize ( )
30
34
{
31
- _config = new SourceControlSettings ( Name , Email , RepoLocation , new List < Repository > ( ) , "cmd.exe" ) ;
35
+ _config = new SourceControlSettings ( Name , Email , RepoLocation , new List < Repository > ( ) , CommandPromptLocation ) ;
32
36
33
37
_configService = new Mock < ISourceControlConfigProvider > ( ) ;
34
38
_configService . Setup ( s => s . Create ( ) ) . Returns ( _config ) ;
@@ -37,13 +41,15 @@ public void Initialize()
37
41
_folderBrowserFactory = new Mock < IFolderBrowserFactory > ( ) ;
38
42
_folderBrowserFactory . Setup ( f => f . CreateFolderBrowser ( It . IsAny < string > ( ) ) ) . Returns ( _folderBrowser . Object ) ;
39
43
_folderBrowserFactory . Setup ( f => f . CreateFolderBrowser ( It . IsAny < string > ( ) , false ) ) . Returns ( _folderBrowser . Object ) ;
44
+
45
+ _openFileDialog = new Mock < IOpenFileDialog > ( ) ;
40
46
}
41
47
42
48
[ TestMethod ]
43
49
public void ViewIsPopulatedOnRefresh ( )
44
50
{
45
51
//arrange
46
- var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , new Rubberduck . UI . OpenFileDialog ( ) ) ;
52
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object ) ;
47
53
48
54
//act
49
55
vm . RefreshView ( ) ;
@@ -52,18 +58,20 @@ public void ViewIsPopulatedOnRefresh()
52
58
Assert . AreEqual ( Name , vm . UserName , "Name" ) ;
53
59
Assert . AreEqual ( Email , vm . EmailAddress , "Email" ) ;
54
60
Assert . AreEqual ( RepoLocation , vm . DefaultRepositoryLocation , "Default Repo Location" ) ;
61
+ Assert . AreEqual ( CommandPromptLocation , vm . CommandPromptLocation , "Command Prompt Location" ) ;
55
62
}
56
63
57
64
[ TestMethod ]
58
65
public void ConfigIsPopulatedFromViewOnSave ( )
59
66
{
60
67
//arrange
61
- var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , new Rubberduck . UI . OpenFileDialog ( ) ) ;
68
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object ) ;
62
69
63
70
//simulate user input
64
71
vm . UserName = OtherName ;
65
72
vm . EmailAddress = OtherEmail ;
66
73
vm . DefaultRepositoryLocation = OtherRepoLocation ;
74
+ vm . CommandPromptLocation = OtherCommandPromptLocation ;
67
75
68
76
//simulate Update button click
69
77
vm . UpdateSettingsCommand . Execute ( null ) ;
@@ -72,13 +80,14 @@ public void ConfigIsPopulatedFromViewOnSave()
72
80
Assert . AreEqual ( OtherName , _config . UserName , "Name" ) ;
73
81
Assert . AreEqual ( OtherEmail , _config . EmailAddress , "Email" ) ;
74
82
Assert . AreEqual ( OtherRepoLocation , _config . DefaultRepositoryLocation , "Default Repo Location" ) ;
83
+ Assert . AreEqual ( OtherCommandPromptLocation , _config . CommandPromptLocation , "Command Prompt Location" ) ;
75
84
}
76
85
77
86
[ TestMethod ]
78
87
public void ConfigIsSavedOnSave ( )
79
88
{
80
89
//arrange
81
- var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , new Rubberduck . UI . OpenFileDialog ( ) ) ;
90
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object ) ;
82
91
83
92
//act
84
93
//simulate Update button click
@@ -92,12 +101,13 @@ public void ConfigIsSavedOnSave()
92
101
public void ChangesToViewAreRevertedOnCancel ( )
93
102
{
94
103
//arrange
95
- var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , new Rubberduck . UI . OpenFileDialog ( ) ) ;
104
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object ) ;
96
105
97
106
//simulate user input
98
107
vm . UserName = OtherName ;
99
108
vm . EmailAddress = OtherEmail ;
100
109
vm . DefaultRepositoryLocation = OtherRepoLocation ;
110
+ vm . DefaultRepositoryLocation = OtherCommandPromptLocation ;
101
111
102
112
//act
103
113
//simulate Cancel button click
@@ -107,13 +117,14 @@ public void ChangesToViewAreRevertedOnCancel()
107
117
Assert . AreEqual ( Name , vm . UserName , "Name" ) ;
108
118
Assert . AreEqual ( Email , vm . EmailAddress , "Email" ) ;
109
119
Assert . AreEqual ( RepoLocation , vm . DefaultRepositoryLocation , "Default Repo Location" ) ;
120
+ Assert . AreEqual ( CommandPromptLocation , vm . CommandPromptLocation , "Command Prompt Location" ) ;
110
121
}
111
122
112
123
[ TestMethod ]
113
124
public void OnBrowseDefaultRepoLocation_WhenUserConfirms_ViewMatchesSelectedPath ( )
114
125
{
115
126
//arrange
116
- var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , new Rubberduck . UI . OpenFileDialog ( ) )
127
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object )
117
128
{
118
129
DefaultRepositoryLocation = RepoLocation
119
130
} ;
@@ -128,10 +139,10 @@ public void OnBrowseDefaultRepoLocation_WhenUserConfirms_ViewMatchesSelectedPath
128
139
}
129
140
130
141
[ TestMethod ]
131
- public void OnBrowserDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged ( )
142
+ public void OnBrowseDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged ( )
132
143
{
133
144
//arrange
134
- var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , new Rubberduck . UI . OpenFileDialog ( ) )
145
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object )
135
146
{
136
147
DefaultRepositoryLocation = RepoLocation
137
148
} ;
@@ -144,5 +155,41 @@ public void OnBrowserDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged()
144
155
//assert
145
156
Assert . AreEqual ( RepoLocation , vm . DefaultRepositoryLocation ) ;
146
157
}
158
+
159
+ [ TestMethod ]
160
+ public void OnBrowseCommandPromptLocation_WhenUserConfirms_ViewMatchesSelectedPath ( )
161
+ {
162
+ //arrange
163
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object )
164
+ {
165
+ CommandPromptLocation = CommandPromptLocation
166
+ } ;
167
+ _openFileDialog . Setup ( o => o . FileName ) . Returns ( OtherCommandPromptLocation ) ;
168
+ _openFileDialog . Setup ( o => o . ShowDialog ( ) ) . Returns ( DialogResult . OK ) ;
169
+
170
+ //act
171
+ vm . ShowCommandPromptExePickerCommand . Execute ( null ) ;
172
+
173
+ //assert
174
+ Assert . AreEqual ( _openFileDialog . Object . FileName , vm . CommandPromptLocation ) ;
175
+ }
176
+
177
+ [ TestMethod ]
178
+ public void OnBrowseCommandPromptLocation_WhenUserCancels_ViewRemainsUnchanged ( )
179
+ {
180
+ //arrange
181
+ var vm = new SettingsViewViewModel ( _configService . Object , _folderBrowserFactory . Object , _openFileDialog . Object )
182
+ {
183
+ CommandPromptLocation = CommandPromptLocation
184
+ } ;
185
+ _openFileDialog . Setup ( o => o . FileName ) . Returns ( OtherCommandPromptLocation ) ;
186
+ _openFileDialog . Setup ( o => o . ShowDialog ( ) ) . Returns ( DialogResult . Cancel ) ;
187
+
188
+ //act
189
+ vm . ShowDefaultRepoFolderPickerCommand . Execute ( null ) ;
190
+
191
+ //assert
192
+ Assert . AreEqual ( CommandPromptLocation , vm . CommandPromptLocation ) ;
193
+ }
147
194
}
148
195
}
0 commit comments