Skip to content

Commit be912d5

Browse files
committed
Settings VM tests
1 parent 21374a6 commit be912d5

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<Compile Include="SourceControlConfig.cs" />
138138
<Compile Include="SourceControl\BranchesViewModelTests.cs" />
139139
<Compile Include="SourceControl\ChangesViewModelTests.cs" />
140+
<Compile Include="SourceControl\SettingsViewModelTests.cs" />
140141
<Compile Include="SourceControl\SourceControlTests.cs" />
141142
<Compile Include="SourceControl\UnsyncedCommitsViewModelTests.cs" />
142143
<Compile Include="StringExtensionsTests.cs" />
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows.Forms;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using Moq;
6+
using Rubberduck.Settings;
7+
using Rubberduck.SourceControl;
8+
using Rubberduck.UI;
9+
using Rubberduck.UI.SourceControl;
10+
11+
namespace RubberduckTests.SourceControl
12+
{
13+
[TestClass]
14+
public class SettingsViewModelTests
15+
{
16+
private const string Name = "Chris McClellan";
17+
private const string Email = "ckuhn203@gmail";
18+
private const string RepoLocation = @"C:\Users\Christopher\Documents";
19+
20+
private const string OtherName = "King Lear";
21+
private const string OtherEmail = "king.lear@yahoo.com";
22+
private const string OtherRepoLocation = @"C:\Users\KingLear\Documents";
23+
24+
private Mock<IConfigurationService<SourceControlConfiguration>> _configService;
25+
private SourceControlConfiguration _config;
26+
27+
private Mock<IFolderBrowserFactory> _folderBrowserFactory;
28+
private Mock<IFolderBrowser> _folderBrowser;
29+
30+
[TestInitialize]
31+
public void Initialize()
32+
{
33+
_config = new SourceControlConfiguration(Name, Email, RepoLocation, new List<Repository>());
34+
35+
_configService = new Mock<IConfigurationService<SourceControlConfiguration>>();
36+
_configService.Setup(s => s.LoadConfiguration()).Returns(_config);
37+
38+
_folderBrowser = new Mock<IFolderBrowser>();
39+
_folderBrowserFactory = new Mock<IFolderBrowserFactory>();
40+
_folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny<string>())).Returns(_folderBrowser.Object);
41+
_folderBrowserFactory.Setup(f => f.CreateFolderBrowser(It.IsAny<string>(), false)).Returns(_folderBrowser.Object);
42+
}
43+
44+
[TestMethod]
45+
public void ViewIsPopulatedOnRefresh()
46+
{
47+
//arrange
48+
var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);
49+
50+
//act
51+
vm.RefreshView();
52+
53+
//assert
54+
Assert.AreEqual(Name, vm.UserName, "Name");
55+
Assert.AreEqual(Email, vm.EmailAddress, "Email");
56+
Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location");
57+
}
58+
59+
[TestMethod]
60+
public void ConfigIsPopulatedFromViewOnSave()
61+
{
62+
//arrange
63+
var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);
64+
65+
//simulate user input
66+
vm.UserName = OtherName;
67+
vm.EmailAddress = OtherEmail;
68+
vm.DefaultRepositoryLocation = OtherRepoLocation;
69+
70+
//simulate Update button click
71+
vm.UpdateSettingsCommand.Execute(null);
72+
73+
//assert
74+
Assert.AreEqual(OtherName, _config.UserName, "Name");
75+
Assert.AreEqual(OtherEmail, _config.EmailAddress, "Email");
76+
Assert.AreEqual(OtherRepoLocation, _config.DefaultRepositoryLocation, "Default Repo Location");
77+
}
78+
79+
[TestMethod]
80+
public void ConfigIsSavedOnSave()
81+
{
82+
//arrange
83+
var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);
84+
85+
//act
86+
//simulate Update button click
87+
vm.UpdateSettingsCommand.Execute(null);
88+
89+
//assert
90+
_configService.Verify(s => s.SaveConfiguration(_config));
91+
}
92+
93+
[TestMethod]
94+
public void ChangesToViewAreRevertedOnCancel()
95+
{
96+
//arrange
97+
var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object);
98+
99+
//simulate user input
100+
vm.UserName = OtherName;
101+
vm.EmailAddress = OtherEmail;
102+
vm.DefaultRepositoryLocation = OtherRepoLocation;
103+
104+
//act
105+
//simulate Cancel button click
106+
vm.CancelSettingsChangesCommand.Execute(null);
107+
108+
//assert
109+
Assert.AreEqual(Name, vm.UserName, "Name");
110+
Assert.AreEqual(Email, vm.EmailAddress, "Email");
111+
Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation, "Default Repo Location");
112+
}
113+
114+
[TestMethod]
115+
public void OnBrowseDefaultRepoLocation_WhenUserConfirms_ViewMatchesSelectedPath()
116+
{
117+
//arrange
118+
var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object)
119+
{
120+
DefaultRepositoryLocation = RepoLocation
121+
};
122+
_folderBrowser.Object.SelectedPath = OtherRepoLocation;
123+
_folderBrowser.Setup(f => f.ShowDialog()).Returns(DialogResult.OK);
124+
125+
//act
126+
vm.ShowFilePickerCommand.Execute(null);
127+
128+
//assert
129+
Assert.AreEqual(_folderBrowser.Object.SelectedPath, vm.DefaultRepositoryLocation);
130+
}
131+
132+
[TestMethod]
133+
public void OnBrowserDefaultRepoLocation_WhenUserCancels_ViewRemainsUnchanged()
134+
{
135+
//arrange
136+
var vm = new SettingsViewViewModel(_configService.Object, _folderBrowserFactory.Object)
137+
{
138+
DefaultRepositoryLocation = RepoLocation
139+
};
140+
_folderBrowser.Object.SelectedPath = OtherRepoLocation;
141+
_folderBrowser.Setup(f => f.ShowDialog()).Returns(DialogResult.Cancel);
142+
143+
//act
144+
vm.ShowFilePickerCommand.Execute(null);
145+
146+
//assert
147+
Assert.AreEqual(RepoLocation, vm.DefaultRepositoryLocation);
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)