Skip to content

Commit a456c2d

Browse files
committed
Merge pull request #1106 from Hosch250/BugBlipper
Settings code tests are basically done.
2 parents 8bd4d27 + cf23df1 commit a456c2d

14 files changed

+512
-33
lines changed

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ private GeneralSettings GetDefaultGeneralSettings()
137137
return new GeneralSettings(new DisplayLanguageSetting("en-US"),
138138
new[]
139139
{
140-
new Hotkey{Name="IndentModule", IsEnabled=true, KeyDisplaySymbol="CTRL-M",},
141-
new Hotkey{Name="IndentProcedure", IsEnabled=true, KeyDisplaySymbol="CTRL-P"}
140+
new Hotkey{Name="IndentProcedure", IsEnabled=true, KeyDisplaySymbol="CTRL-P"},
141+
new Hotkey{Name="IndentModule", IsEnabled=true, KeyDisplaySymbol="CTRL-M"}
142142
});
143143
}
144144

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
<data name="SettingsCaption_GeneralSettings" xml:space="preserve">
191191
<value>General Settings</value>
192192
</data>
193-
<data name="SettingsCaption_CodeInspections" xml:space="preserve">
193+
<data name="SettingsCaption_InspectionSettings" xml:space="preserve">
194194
<value>Code Inspection Settings</value>
195195
</data>
196196
<data name="SettingsCaption_TodoSettings" xml:space="preserve">

RetailCoder.VBE/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Collections.Generic;
2-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
32
using System.Linq;
4-
using Rubberduck.Common;
53
using Rubberduck.Settings;
64

75
namespace Rubberduck.UI.Settings

RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Windows.Input;
2-
using Rubberduck.Settings;
1+
using Rubberduck.Settings;
32
using Rubberduck.SmartIndenter;
4-
using Rubberduck.UI.Command;
53

64
namespace Rubberduck.UI.Settings
75
{

RetailCoder.VBE/UI/Settings/InspectionSettings.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</UserControl.Resources>
3434
<Grid>
3535
<DockPanel Margin="5,5,5,0">
36-
<Label DockPanel.Dock="Top" Background="DarkGray" Foreground="White" FontWeight="SemiBold" Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_CodeInspections}" Margin="0,0,0,3">
36+
<Label DockPanel.Dock="Top" Background="DarkGray" Foreground="White" FontWeight="SemiBold" Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_InspectionSettings}" Margin="0,0,0,3">
3737
<Label.Style>
3838
<Style>
3939
<Style.Resources>

RetailCoder.VBE/UI/Settings/SettingsControlViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Rubberduck.UI.Settings
99
{
1010
public class SettingsView
1111
{
12-
public string Label { get; set; }
12+
public string Label { get { return RubberduckUI.ResourceManager.GetString("SettingsCaption_" + View); } }
1313
public string Instructions
1414
{
1515
get
@@ -35,31 +35,26 @@ public SettingsControlViewModel(IGeneralConfigService configService, SettingsVie
3535
{
3636
new SettingsView
3737
{
38-
Label = RubberduckUI.SettingsCaption_GeneralSettings,
3938
Control = new GeneralSettings(new GeneralSettingsViewModel(_config)),
4039
View = Settings.SettingsViews.GeneralSettings
4140
},
4241
new SettingsView
4342
{
44-
Label = RubberduckUI.SettingsCaption_TodoSettings,
4543
Control = new TodoSettings(new TodoSettingsViewModel(_config)),
4644
View = Settings.SettingsViews.TodoSettings
4745
},
4846
new SettingsView
4947
{
50-
Label = RubberduckUI.SettingsCaption_CodeInspections,
5148
Control = new InspectionSettings(new InspectionSettingsViewModel(_config)),
5249
View = Settings.SettingsViews.InspectionSettings
5350
},
5451
new SettingsView
5552
{
56-
Label = RubberduckUI.SettingsCaption_UnitTestSettings,
5753
Control = new UnitTestSettings(new UnitTestSettingsViewModel(_config)),
5854
View = Settings.SettingsViews.UnitTestSettings
5955
},
6056
new SettingsView
6157
{
62-
Label = RubberduckUI.SettingsCaption_IndenterSettings,
6358
Control = new IndenterSettings(new IndenterSettingsViewModel(_config)),
6459
View = Settings.SettingsViews.IndenterSettings
6560
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@
5757
<Reference Include="Moq">
5858
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
5959
</Reference>
60+
<Reference Include="PresentationFramework" />
6061
<Reference Include="System" />
6162
<Reference Include="System.Windows.Forms" />
63+
<Reference Include="WindowsBase" />
6264
</ItemGroup>
6365
<Choose>
6466
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@@ -117,6 +119,10 @@
117119
<Compile Include="Refactoring\RenameTests.cs" />
118120
<Compile Include="Refactoring\ReorderParametersTests.cs" />
119121
<Compile Include="RubberduckParserTests.cs" />
122+
<Compile Include="Settings\CodeInspectionSettingsTests.cs" />
123+
<Compile Include="Settings\GeneralSettingsTests.cs" />
124+
<Compile Include="Settings\IndenterSettingsTests.cs" />
125+
<Compile Include="Settings\SettingsControlTests.cs" />
120126
<Compile Include="Settings\TodoSettingsTests.cs" />
121127
<Compile Include="Settings\UnitTestSettingsTests.cs" />
122128
<Compile Include="SourceControlConfig.cs" />
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using System.Linq;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Rubberduck.Inspections;
4+
using Rubberduck.Settings;
5+
using Rubberduck.UI.Settings;
6+
7+
namespace RubberduckTests.Settings
8+
{
9+
[TestClass]
10+
public class CodeInspectionSettingsTests
11+
{
12+
private Configuration GetDefaultConfig()
13+
{
14+
var inspectionSettings = new CodeInspectionSettings
15+
{
16+
CodeInspections = new[]
17+
{
18+
new CodeInspectionSetting("DoNotShowInspection", "Do not show me", CodeInspectionType.LanguageOpportunities, CodeInspectionSeverity.DoNotShow, CodeInspectionSeverity.DoNotShow),
19+
new CodeInspectionSetting("HintInspection", "I'm a hint", CodeInspectionType.LanguageOpportunities, CodeInspectionSeverity.Hint, CodeInspectionSeverity.Hint),
20+
new CodeInspectionSetting("SuggestionInspection", "I'm a suggestion", CodeInspectionType.MaintainabilityAndReadabilityIssues, CodeInspectionSeverity.Suggestion, CodeInspectionSeverity.Suggestion),
21+
new CodeInspectionSetting("WarningInspection", "I'm a warning", CodeInspectionType.CodeQualityIssues, CodeInspectionSeverity.Warning, CodeInspectionSeverity.Warning),
22+
new CodeInspectionSetting("ErrorInspection", "FIX ME!", CodeInspectionType.CodeQualityIssues, CodeInspectionSeverity.Error, CodeInspectionSeverity.Error),
23+
new CodeInspectionSetting("NondefaultSeverityInspection", "I do not have my original severity", CodeInspectionType.LanguageOpportunities, CodeInspectionSeverity.Warning, CodeInspectionSeverity.DoNotShow)
24+
}
25+
};
26+
27+
var userSettings = new UserSettings(null, null, inspectionSettings, null, null);
28+
return new Configuration(userSettings);
29+
}
30+
31+
private Configuration GetNondefaultConfig()
32+
{
33+
var inspectionSettings = new CodeInspectionSettings
34+
{
35+
CodeInspections = new[]
36+
{
37+
new CodeInspectionSetting("DoNotShowInspection", "Do not show me", CodeInspectionType.LanguageOpportunities, CodeInspectionSeverity.DoNotShow, CodeInspectionSeverity.Warning),
38+
new CodeInspectionSetting("HintInspection", "I'm a hint", CodeInspectionType.LanguageOpportunities, CodeInspectionSeverity.Hint, CodeInspectionSeverity.Suggestion),
39+
new CodeInspectionSetting("SuggestionInspection", "I'm a suggestion", CodeInspectionType.MaintainabilityAndReadabilityIssues, CodeInspectionSeverity.Suggestion, CodeInspectionSeverity.Hint),
40+
new CodeInspectionSetting("WarningInspection", "I'm a warning", CodeInspectionType.CodeQualityIssues, CodeInspectionSeverity.Warning, CodeInspectionSeverity.Error),
41+
new CodeInspectionSetting("ErrorInspection", "FIX ME!", CodeInspectionType.CodeQualityIssues, CodeInspectionSeverity.Error, CodeInspectionSeverity.DoNotShow),
42+
new CodeInspectionSetting("NondefaultSeverityInspection", "I do not have my original severity", CodeInspectionType.LanguageOpportunities, CodeInspectionSeverity.Warning, CodeInspectionSeverity.Error)
43+
}
44+
};
45+
46+
var userSettings = new UserSettings(null, null, inspectionSettings, null, null);
47+
return new Configuration(userSettings);
48+
}
49+
50+
[TestMethod]
51+
public void SaveConfigWorks()
52+
{
53+
var customConfig = GetNondefaultConfig();
54+
var viewModel = new InspectionSettingsViewModel(customConfig);
55+
56+
var config = GetDefaultConfig();
57+
viewModel.UpdateConfig(config);
58+
59+
Assert.IsTrue(config.UserSettings.CodeInspectionSettings.CodeInspections.SequenceEqual(
60+
viewModel.InspectionSettings.SourceCollection.OfType<CodeInspectionSetting>()));
61+
}
62+
63+
[TestMethod]
64+
public void SetDefaultsWorks()
65+
{
66+
var viewModel = new InspectionSettingsViewModel(GetNondefaultConfig());
67+
68+
var defaultConfig = GetDefaultConfig();
69+
viewModel.SetToDefaults(defaultConfig);
70+
71+
Assert.IsTrue(defaultConfig.UserSettings.CodeInspectionSettings.CodeInspections.SequenceEqual(
72+
viewModel.InspectionSettings.SourceCollection.OfType<CodeInspectionSetting>()));
73+
}
74+
75+
[TestMethod]
76+
public void InspectionsAreSetInCtor()
77+
{
78+
var defaultConfig = GetDefaultConfig();
79+
var viewModel = new InspectionSettingsViewModel(defaultConfig);
80+
81+
Assert.IsTrue(defaultConfig.UserSettings.CodeInspectionSettings.CodeInspections.SequenceEqual(
82+
viewModel.InspectionSettings.SourceCollection.OfType<CodeInspectionSetting>()));
83+
}
84+
85+
[TestMethod]
86+
public void InspectionSeveritiesAreUpdated()
87+
{
88+
var defaultConfig = GetDefaultConfig();
89+
var viewModel = new InspectionSettingsViewModel(defaultConfig);
90+
91+
viewModel.InspectionSettings.SourceCollection.OfType<CodeInspectionSetting>().First().Severity =
92+
GetNondefaultConfig().UserSettings.CodeInspectionSettings.CodeInspections[0].Severity;
93+
94+
var updatedConfig = defaultConfig;
95+
updatedConfig.UserSettings.CodeInspectionSettings.CodeInspections[0].Severity =
96+
GetNondefaultConfig().UserSettings.CodeInspectionSettings.CodeInspections[0].Severity;
97+
98+
Assert.IsTrue(updatedConfig.UserSettings.CodeInspectionSettings.CodeInspections.SequenceEqual(
99+
viewModel.InspectionSettings.SourceCollection.OfType<CodeInspectionSetting>()));
100+
}
101+
}
102+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System.Linq;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Rubberduck.Settings;
4+
using Rubberduck.UI.Settings;
5+
using GeneralSettings = Rubberduck.Settings.GeneralSettings;
6+
7+
namespace RubberduckTests.Settings
8+
{
9+
[TestClass]
10+
public class GeneralSettingsTests
11+
{
12+
private Configuration GetDefaultConfig()
13+
{
14+
var generalSettings = new GeneralSettings
15+
{
16+
Language = new DisplayLanguageSetting("en-US"),
17+
HotkeySettings = new[]
18+
{
19+
new Hotkey{Name="IndentProcedure", IsEnabled=true, KeyDisplaySymbol="CTRL-P"},
20+
new Hotkey{Name="IndentModule", IsEnabled=true, KeyDisplaySymbol="CTRL-M"}
21+
}
22+
};
23+
24+
var userSettings = new UserSettings(generalSettings, null, null, null, null);
25+
return new Configuration(userSettings);
26+
}
27+
28+
private Configuration GetNondefaultConfig()
29+
{
30+
var generalSettings = new GeneralSettings
31+
{
32+
Language = new DisplayLanguageSetting("sv-SE"),
33+
HotkeySettings = new[]
34+
{
35+
new Hotkey{Name="IndentProcedure", IsEnabled=false, KeyDisplaySymbol="CTRL-C"},
36+
new Hotkey{Name="IndentModule", IsEnabled=false, KeyDisplaySymbol="CTRL-X"}
37+
}
38+
};
39+
40+
var userSettings = new UserSettings(generalSettings, null, null, null, null);
41+
return new Configuration(userSettings);
42+
}
43+
44+
[TestMethod]
45+
public void SaveConfigWorks()
46+
{
47+
var customConfig = GetNondefaultConfig();
48+
var viewModel = new GeneralSettingsViewModel(customConfig);
49+
50+
var config = GetDefaultConfig();
51+
viewModel.UpdateConfig(config);
52+
53+
MultiAssert.Aggregate(
54+
() => Assert.AreEqual(config.UserSettings.GeneralSettings.Language, viewModel.SelectedLanguage),
55+
() => Assert.IsTrue(config.UserSettings.GeneralSettings.HotkeySettings.SequenceEqual(viewModel.Hotkeys)));
56+
}
57+
58+
[TestMethod]
59+
public void SetDefaultsWorks()
60+
{
61+
var viewModel = new GeneralSettingsViewModel(GetNondefaultConfig());
62+
63+
var defaultConfig = GetDefaultConfig();
64+
viewModel.SetToDefaults(defaultConfig);
65+
66+
MultiAssert.Aggregate(
67+
() => Assert.AreEqual(defaultConfig.UserSettings.GeneralSettings.Language, viewModel.SelectedLanguage),
68+
() => Assert.IsTrue(defaultConfig.UserSettings.GeneralSettings.HotkeySettings.SequenceEqual(viewModel.Hotkeys)));
69+
}
70+
71+
[TestMethod]
72+
public void LanguageIsSetInCtor()
73+
{
74+
var defaultConfig = GetDefaultConfig();
75+
var viewModel = new GeneralSettingsViewModel(defaultConfig);
76+
77+
Assert.AreEqual(defaultConfig.UserSettings.GeneralSettings.Language, viewModel.SelectedLanguage);
78+
}
79+
80+
[TestMethod]
81+
public void HotkeysAreSetInCtor()
82+
{
83+
var defaultConfig = GetDefaultConfig();
84+
var viewModel = new GeneralSettingsViewModel(defaultConfig);
85+
86+
Assert.IsTrue(defaultConfig.UserSettings.GeneralSettings.HotkeySettings.SequenceEqual(viewModel.Hotkeys));
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)