Skip to content

Commit fc2277e

Browse files
committed
Update/add tests
1 parent 761b209 commit fc2277e

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

RetailCoder.VBE/UI/SourceControl/SettingsViewViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private void CancelSettingsChanges()
128128
UserName = _config.UserName;
129129
EmailAddress = _config.EmailAddress;
130130
DefaultRepositoryLocation = _config.DefaultRepositoryLocation;
131+
CommandPromptLocation = _config.CommandPromptLocation;
131132
}
132133

133134
private void UpdateSettings()

RubberduckTests/SourceControl/SettingsViewModelTests.cs

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@ public class SettingsViewModelTests
1414
private const string Name = "Chris McClellan";
1515
private const string Email = "ckuhn203@gmail";
1616
private const string RepoLocation = @"C:\Users\Christopher\Documents";
17+
private const string CommandPromptLocation = "cmd.exe";
1718

1819
private const string OtherName = "King Lear";
1920
private const string OtherEmail = "king.lear@yahoo.com";
2021
private const string OtherRepoLocation = @"C:\Users\KingLear\Documents";
22+
private const string OtherCommandPromptLocation = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
2123

2224
private Mock<ISourceControlConfigProvider> _configService;
2325
private SourceControlSettings _config;
2426

2527
private Mock<IFolderBrowserFactory> _folderBrowserFactory;
2628
private Mock<IFolderBrowser> _folderBrowser;
2729

30+
private Mock<IOpenFileDialog> _openFileDialog;
31+
2832
[TestInitialize]
2933
public void Initialize()
3034
{
31-
_config = new SourceControlSettings(Name, Email, RepoLocation, new List<Repository>(), "cmd.exe");
35+
_config = new SourceControlSettings(Name, Email, RepoLocation, new List<Repository>(), CommandPromptLocation);
3236

3337
_configService = new Mock<ISourceControlConfigProvider>();
3438
_configService.Setup(s => s.Create()).Returns(_config);
@@ -37,13 +41,15 @@ public void Initialize()
3741
_folderBrowserFactory = new Mock<IFolderBrowserFactory>();
3842
_folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny<string>())).Returns(_folderBrowser.Object);
3943
_folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny<string>(), false)).Returns(_folderBrowser.Object);
44+
45+
_openFileDialog = new Mock<IOpenFileDialog>();
4046
}
4147

4248
[TestMethod]
4349
public void ViewIsPopulatedOnRefresh()
4450
{
4551
//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);
4753

4854
//act
4955
vm.RefreshView();
@@ -52,18 +58,20 @@ public void ViewIsPopulatedOnRefresh()
5258
Assert.AreEqual(Name, vm.UserName, "Name");
5359
Assert.AreEqual(Email, vm.EmailAddress, "Email");
5460
Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location");
61+
Assert.AreEqual(CommandPromptLocation, vm.CommandPromptLocation, "Command Prompt Location");
5562
}
5663

5764
[TestMethod]
5865
public void ConfigIsPopulatedFromViewOnSave()
5966
{
6067
//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);
6269

6370
//simulate user input
6471
vm.UserName = OtherName;
6572
vm.EmailAddress = OtherEmail;
6673
vm.DefaultRepositoryLocation = OtherRepoLocation;
74+
vm.CommandPromptLocation = OtherCommandPromptLocation;
6775

6876
//simulate Update button click
6977
vm.UpdateSettingsCommand.Execute(null);
@@ -72,13 +80,14 @@ public void ConfigIsPopulatedFromViewOnSave()
7280
Assert.AreEqual(OtherName, _config.UserName, "Name");
7381
Assert.AreEqual(OtherEmail, _config.EmailAddress, "Email");
7482
Assert.AreEqual(OtherRepoLocation, _config.DefaultRepositoryLocation, "Default Repo Location");
83+
Assert.AreEqual(OtherCommandPromptLocation, _config.CommandPromptLocation, "Command Prompt Location");
7584
}
7685

7786
[TestMethod]
7887
public void ConfigIsSavedOnSave()
7988
{
8089
//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);
8291

8392
//act
8493
//simulate Update button click
@@ -92,12 +101,13 @@ public void ConfigIsSavedOnSave()
92101
public void ChangesToViewAreRevertedOnCancel()
93102
{
94103
//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);
96105

97106
//simulate user input
98107
vm.UserName = OtherName;
99108
vm.EmailAddress = OtherEmail;
100109
vm.DefaultRepositoryLocation = OtherRepoLocation;
110+
vm.DefaultRepositoryLocation = OtherCommandPromptLocation;
101111

102112
//act
103113
//simulate Cancel button click
@@ -107,13 +117,14 @@ public void ChangesToViewAreRevertedOnCancel()
107117
Assert.AreEqual(Name, vm.UserName, "Name");
108118
Assert.AreEqual(Email, vm.EmailAddress, "Email");
109119
Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location");
120+
Assert.AreEqual(CommandPromptLocation, vm.CommandPromptLocation, "Command Prompt Location");
110121
}
111122

112123
[TestMethod]
113124
public void OnBrowseDefaultRepoLocation_WhenUserConfirms_ViewMatchesSelectedPath()
114125
{
115126
//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)
117128
{
118129
DefaultRepositoryLocation = RepoLocation
119130
};
@@ -128,10 +139,10 @@ public void OnBrowseDefaultRepoLocation_WhenUserConfirms_ViewMatchesSelectedPath
128139
}
129140

130141
[TestMethod]
131-
public void OnBrowserDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged()
142+
public void OnBrowseDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged()
132143
{
133144
//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)
135146
{
136147
DefaultRepositoryLocation = RepoLocation
137148
};
@@ -144,5 +155,41 @@ public void OnBrowserDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged()
144155
//assert
145156
Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation);
146157
}
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+
}
147194
}
148195
}

0 commit comments

Comments
 (0)