Skip to content

Commit 3626d9a

Browse files
committed
Merge pull request #1104 from Hosch250/BugBlipper
A few bug fixes and unit tests for the unit test settings
2 parents 23e706b + 45758e7 commit 3626d9a

File tree

12 files changed

+347
-22
lines changed

12 files changed

+347
-22
lines changed

RetailCoder.VBE/Inspections/IInspectionModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public interface IInspectionModel
2222
/// </summary>
2323
CodeInspectionType InspectionType { get; }
2424

25+
/// <summary>
26+
/// Gets a value indicating the default severity level of the code inspection.
27+
/// </summary>
28+
CodeInspectionSeverity DefaultSeverity { get; }
29+
2530
/// <summary>
2631
/// Gets a value indicating the severity level of the code inspection.
2732
/// </summary>

RetailCoder.VBE/Settings/CodeInspectionSettings.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class CodeInspectionSetting : IInspectionModel
3434
[XmlIgnore]
3535
public string AnnotationName { get; set; }
3636

37+
[XmlIgnore]
38+
public CodeInspectionSeverity DefaultSeverity { get; private set; }
39+
3740
[XmlAttribute]
3841
public CodeInspectionSeverity Severity { get; set; }
3942

@@ -76,16 +79,17 @@ public CodeInspectionSetting()
7679
//default constructor required for serialization
7780
}
7881

79-
public CodeInspectionSetting(string name, string description, CodeInspectionType type, CodeInspectionSeverity severity)
82+
public CodeInspectionSetting(string name, string description, CodeInspectionType type, CodeInspectionSeverity defaultSeverity, CodeInspectionSeverity severity)
8083
{
8184
Name = name;
8285
Description = description;
8386
InspectionType = type;
8487
Severity = severity;
88+
DefaultSeverity = defaultSeverity;
8589
}
8690

8791
public CodeInspectionSetting(IInspectionModel inspection)
88-
: this(inspection.Name, inspection.Description, inspection.InspectionType, inspection.Severity)
92+
: this(inspection.Name, inspection.Description, inspection.InspectionType, inspection.DefaultSeverity, inspection.Severity)
8993
{ }
9094
}
9195
}

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System.Text;
66
using System.Windows.Forms;
77
using Rubberduck.Inspections;
8-
using Rubberduck.SmartIndenter;
9-
using Rubberduck.ToDoItems;
108
using Rubberduck.UI;
119
using MessageBox = System.Windows.Forms.MessageBox;
1210

@@ -157,7 +155,9 @@ public ToDoMarker[] GetDefaultTodoMarkers()
157155
/// <returns> An array of Config.CodeInspection. </returns>
158156
public CodeInspectionSetting[] GetDefaultCodeInspections()
159157
{
160-
return _inspections.Select(x => new CodeInspectionSetting(x)).ToArray();
158+
return _inspections.Select(x =>
159+
new CodeInspectionSetting(x.Name, x.Description, x.InspectionType, x.DefaultSeverity,
160+
x.DefaultSeverity)).ToArray();
161161
}
162162

163163
public IndenterSettings GetDefaultIndenterSettings()

RetailCoder.VBE/UI/Settings/InspectionSettings.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
HeadersVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
5151
ColumnHeaderHeight="22" BorderThickness="0">
5252
<controls:GroupingGrid.Columns>
53-
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=NameLabelText}" Width="2.75*" IsReadOnly="True">
53+
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=NameLabelText}" Width="2.75*" IsReadOnly="True" SortMemberPath="{Binding Description}">
5454
<DataGridTemplateColumn.CellTemplate>
5555
<DataTemplate>
5656
<TextBlock Text="{Binding Description}">

RetailCoder.VBE/UI/Settings/SettingsControl.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
<DockPanel VerticalAlignment="Center" Height="40" Background="{x:Static SystemColors.ControlDarkBrush}">
7171
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
7272
<Button Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Settings_ResetSettings}" MinWidth="75" Height="20" HorizontalAlignment="Right" Margin="20,0" Command="{Binding RefreshButtonCommand}" />
73-
<Button Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CancelButtonText}" MinWidth="75" Height="20" HorizontalAlignment="Right" Margin="5, 0" Command="{Binding CancelButtonCommand}" />
74-
<Button Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=OK}" MinWidth="75" Height="20" HorizontalAlignment="Left" Margin="5, 0, 10, 0" Command="{Binding OKButtonCommand}" />
73+
<Button Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=OK}" MinWidth="75" Height="20" HorizontalAlignment="Left" Margin="5, 0" Command="{Binding OKButtonCommand}" />
74+
<Button Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CancelButtonText}" MinWidth="75" Height="20" HorizontalAlignment="Right" Margin="5, 0, 10, 0" Command="{Binding CancelButtonCommand}" />
7575
</StackPanel>
7676
</DockPanel>
7777
</Border>

RetailCoder.VBE/UI/Settings/TodoSettingsViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Linq;
33
using System.Windows.Input;
44
using Rubberduck.Settings;
5-
using Rubberduck.ToDoItems;
65
using Rubberduck.UI.Command;
76

87
namespace Rubberduck.UI.Settings

RetailCoder.VBE/UI/Settings/UnitTestSettings.xaml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
</UserControl.Resources>
3030
<Grid>
3131
<StackPanel Margin="5,5,5,0">
32-
<Label DockPanel.Dock="Top" Background="DarkGray" Foreground="White" FontWeight="SemiBold" Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_UnitTestSettings}" Margin="0,0,0,3">
32+
<Label DockPanel.Dock="Top"
33+
Background="DarkGray"
34+
Foreground="White"
35+
FontWeight="SemiBold"
36+
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_UnitTestSettings}"
37+
Margin="0,0,0,3">
3338
<Label.Style>
3439
<Style>
3540
<Style.Resources>
@@ -41,16 +46,36 @@
4146
</Label.Style>
4247
</Label>
4348

44-
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_BindingMode}" FontWeight="SemiBold" />
45-
<ComboBox Margin="5,0,0,5" Width="210" HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource BindingMode}, Converter={StaticResource BindingModeToText}, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding BindingMode, Converter={StaticResource BindingModeValueToText}}" />
49+
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_BindingMode}"
50+
FontWeight="SemiBold" />
51+
<ComboBox Margin="5,0,0,5"
52+
Width="210"
53+
HorizontalAlignment="Left"
54+
ItemsSource="{Binding Source={StaticResource BindingMode}, Converter={StaticResource BindingModeToText}, UpdateSourceTrigger=PropertyChanged}"
55+
SelectedItem="{Binding BindingMode, Converter={StaticResource BindingModeValueToText}}" />
4656

47-
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_AssertMode}" FontWeight="SemiBold" />
48-
<ComboBox Margin="5,0,0,5" Width="210" HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource AssertMode}, Converter={StaticResource AssertModeToText}, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding AssertMode, Converter={StaticResource AssertModeValueToText}}" />
57+
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_AssertMode}"
58+
FontWeight="SemiBold" />
59+
<ComboBox Margin="5,0,0,5"
60+
Width="210"
61+
HorizontalAlignment="Left"
62+
ItemsSource="{Binding Source={StaticResource AssertMode}, Converter={StaticResource AssertModeToText}, UpdateSourceTrigger=PropertyChanged}"
63+
SelectedItem="{Binding AssertMode, Converter={StaticResource AssertModeValueToText}}" />
4964

50-
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_TestModuleTemplateHeader}" FontWeight="SemiBold" />
51-
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_IncludeTestModuleInitCleanupPrompt}" IsChecked="{Binding ModuleInit, Mode=TwoWay}" Margin="5,0,0,5" HorizontalAlignment="Left" />
52-
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_IncludeTestMethodInitCleanupPrompt}" IsChecked="{Binding MethodInit, Mode=TwoWay}" Margin="5,0,0,5" HorizontalAlignment="Left" />
53-
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_IncludeTestMethodStubWhenCreatingModulePrompt}" IsChecked="{Binding DefaultTestStubInNewModule, Mode=TwoWay}" Margin="5,0,0,0" HorizontalAlignment="Left" />
65+
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_TestModuleTemplateHeader}"
66+
FontWeight="SemiBold" />
67+
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_IncludeTestModuleInitCleanupPrompt}"
68+
IsChecked="{Binding ModuleInit, Mode=TwoWay}"
69+
Margin="5,0,0,5"
70+
HorizontalAlignment="Left" />
71+
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_IncludeTestMethodInitCleanupPrompt}"
72+
IsChecked="{Binding MethodInit, Mode=TwoWay}"
73+
Margin="5,0,0,5"
74+
HorizontalAlignment="Left" />
75+
<CheckBox Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=UnitTestSettings_IncludeTestMethodStubWhenCreatingModulePrompt}"
76+
IsChecked="{Binding DefaultTestStubInNewModule, Mode=TwoWay}"
77+
Margin="5,0,0,0"
78+
HorizontalAlignment="Left" />
5479
</StackPanel>
5580
</Grid>
5681
</UserControl>

RubberduckTests/ConfigurationTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Moq;
33
using Rubberduck.Inspections;
44
using Rubberduck.Settings;
5-
using Rubberduck.ToDoItems;
65

76
namespace RubberduckTests
87
{
@@ -24,9 +23,9 @@ public void GetDefaultTodoMarkersTest()
2423
public void DefaultCodeInspectionsIsAsSpecified()
2524
{
2625
var inspection = new Mock<IInspection>();
27-
//inspection.SetupGet(m => m.Description).Returns("TestInspection");
28-
//inspection.SetupGet(m => m.Name).Returns("TestInspection");
29-
//inspection.SetupGet(m => m.Severity).Returns(CodeInspectionSeverity.DoNotShow);
26+
inspection.SetupGet(m => m.Description).Returns("TestInspection");
27+
inspection.SetupGet(m => m.Name).Returns("TestInspection");
28+
inspection.SetupGet(m => m.Severity).Returns(CodeInspectionSeverity.DoNotShow);
3029

3130
var expected = new[] { inspection.Object };
3231
var configService = new ConfigurationLoader(expected);

RubberduckTests/MultiAssert.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace RubberduckTests
7+
{
8+
// borrowed from https://blog.elgaard.com/2011/02/06/multiple-asserts-in-a-single-unit-test-method/
9+
public static class MultiAssert
10+
{
11+
public static void Aggregate(params Action[] actions)
12+
{
13+
var exceptions = new List<AssertFailedException>();
14+
15+
foreach (var action in actions)
16+
{
17+
try
18+
{
19+
action();
20+
}
21+
catch (AssertFailedException ex)
22+
{
23+
exceptions.Add(ex);
24+
}
25+
}
26+
27+
var assertionTexts =
28+
exceptions.Select(assertFailedException => assertFailedException.Message).ToList();
29+
if (0 != assertionTexts.Count)
30+
{
31+
throw new
32+
AssertFailedException(
33+
assertionTexts.Aggregate(
34+
(aggregatedMessage, next) => aggregatedMessage + Environment.NewLine + next));
35+
}
36+
}
37+
}
38+
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<Compile Include="Mocks\MockUserFormBuilder.cs" />
108108
<Compile Include="Mocks\MockVbeBuilder.cs" />
109109
<Compile Include="Mocks\MockWindowsCollection.cs" />
110+
<Compile Include="MultiAssert.cs" />
110111
<Compile Include="Refactoring\EncapsulateFieldTests.cs" />
111112
<Compile Include="Refactoring\ExtractMethodTests.cs" />
112113
<Compile Include="Refactoring\IntroduceFieldTests.cs" />
@@ -116,6 +117,8 @@
116117
<Compile Include="Refactoring\RenameTests.cs" />
117118
<Compile Include="Refactoring\ReorderParametersTests.cs" />
118119
<Compile Include="RubberduckParserTests.cs" />
120+
<Compile Include="Settings\TodoSettingsTests.cs" />
121+
<Compile Include="Settings\UnitTestSettingsTests.cs" />
119122
<Compile Include="SourceControlConfig.cs" />
120123
<Compile Include="SourceControl\BranchesPresenterTests.cs" />
121124
<Compile Include="SourceControl\ChangesPresenterTests.cs" />
@@ -142,6 +145,10 @@
142145
<Project>{a4a618e1-cbca-435f-9c6c-5181e030adfc}</Project>
143146
<Name>Rubberduck.Parsing</Name>
144147
</ProjectReference>
148+
<ProjectReference Include="..\Rubberduck.SmartIndenter\Rubberduck.SmartIndenter.csproj">
149+
<Project>{b9c0bf22-4d8a-4bf4-89f9-e789c0063deb}</Project>
150+
<Name>Rubberduck.SmartIndenter</Name>
151+
</ProjectReference>
145152
<ProjectReference Include="..\Rubberduck.SourceControl\Rubberduck.SourceControl.csproj">
146153
<Project>{0040e129-1aa2-459f-a59a-129fa4035e01}</Project>
147154
<Name>Rubberduck.SourceControl</Name>

0 commit comments

Comments
 (0)