Skip to content

Commit cd113a8

Browse files
committed
Unit testing XAML bug fix.
1 parent 0650b07 commit cd113a8

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
<UserControl.Resources>
1818
<BitmapImage x:Key="SettingsImage" UriSource="../../Resources/gear.png" />
1919

20+
2021
<local:TestOutcomeImageSourceConverter x:Key="OutcomeIconConverter" />
21-
22+
23+
2224
<local:TestResultToOutcomeTextConverter x:Key="OutcomeTextConverter" />
23-
25+
2426
<BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
2527
<converters:InvertBoolValueConverter x:Key="InvertBoolValue" />
2628

@@ -272,9 +274,9 @@
272274
<componentModel:SortDescription PropertyName="Result.Outcome" />
273275
</CollectionViewSource.SortDescriptions>
274276
<CollectionViewSource.GroupDescriptions>
275-
<!--
277+
276278
<PropertyGroupDescription PropertyName="Result" Converter="{StaticResource OutcomeTextConverter}" />
277-
-->
279+
278280
</CollectionViewSource.GroupDescriptions>
279281
</CollectionViewSource>
280282
<SolidColorBrush x:Key="ToolBarToggleButtonVerticalBackground" Color="#FFEEF5FD"/>
@@ -610,7 +612,6 @@
610612
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
611613
</DataGrid.Columns>
612614
</controls:GroupingGrid>
613-
<!--
614615
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByModule}}"
615616
SelectedItem="{Binding SelectedTest}"
616617
ShowGroupingItemCount="True"
@@ -629,7 +630,7 @@
629630
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
630631
</DataGrid.Columns>
631632
</controls:GroupingGrid>
632-
-->
633+
633634
</Grid>
634635
</ScrollViewer>
635636
</Border>

RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ public TestExplorerControl()
1818
_dispatcher = Dispatcher.CurrentDispatcher;
1919
}
2020

21-
void TestExplorerControl_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
21+
private void TestExplorerControl_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
2222
{
23-
var oldContext = e.OldValue as TestExplorerViewModel;
24-
if (oldContext != null)
23+
if (e.OldValue is TestExplorerViewModel oldContext)
2524
{
2625
oldContext.TestCompleted -= OnTestCompleted;
2726
}
2827

29-
var context = e.NewValue as TestExplorerViewModel;
30-
if (context != null)
28+
if (e.NewValue is TestExplorerViewModel context)
3129
{
3230
context.TestCompleted += OnTestCompleted;
3331
}
@@ -37,8 +35,7 @@ private void OnTestCompleted(object sender, EventArgs eventArgs)
3735
{
3836
_dispatcher.Invoke(() =>
3937
{
40-
var resource = FindResource("ResultsByOutcome") as CollectionViewSource;
41-
if (resource != null)
38+
if (FindResource("ResultsByOutcome") is CollectionViewSource resource)
4239
{
4340
resource.View.Refresh();
4441
}

RetailCoder.VBE/UI/UnitTesting/TestExplorerModel.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void Refresh()
114114
private int _executedCount;
115115
public int ExecutedCount
116116
{
117-
get { return _executedCount; }
117+
get => _executedCount;
118118
private set
119119
{
120120
_executedCount = value;
@@ -125,7 +125,7 @@ private set
125125
private Color _progressBarColor = Colors.DimGray;
126126
public Color ProgressBarColor
127127
{
128-
get { return _progressBarColor; }
128+
get => _progressBarColor;
129129
set
130130
{
131131
_progressBarColor = value;
@@ -136,7 +136,7 @@ public Color ProgressBarColor
136136
private bool _isBusy;
137137
public bool IsBusy
138138
{
139-
get { return _isBusy; }
139+
get => _isBusy;
140140
set
141141
{
142142
_isBusy = value;
@@ -149,7 +149,7 @@ public bool IsBusy
149149
private bool _isReady = true;
150150
public bool IsReady
151151
{
152-
get { return _isReady; }
152+
get => _isReady;
153153
private set
154154
{
155155
_isReady = value;
@@ -160,8 +160,7 @@ private set
160160
public event EventHandler<EventArgs> TestsRefreshed;
161161
private void OnTestsRefreshed()
162162
{
163-
var handler = TestsRefreshed;
164-
handler?.Invoke(this, EventArgs.Empty);
163+
TestsRefreshed?.Invoke(this, EventArgs.Empty);
165164
}
166165

167166
public void Dispose()

RetailCoder.VBE/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ private void TestEngineTestCompleted(object sender, EventArgs e)
115115
handler?.Invoke(sender, e);
116116
}
117117

118-
public INavigateSource SelectedItem { get { return SelectedTest; } }
118+
public INavigateSource SelectedItem => SelectedTest;
119119

120120
private TestMethod _selectedTest;
121121
public TestMethod SelectedTest
122122
{
123-
get { return _selectedTest; }
123+
get => _selectedTest;
124124
set
125125
{
126126
_selectedTest = value;
@@ -131,28 +131,32 @@ public TestMethod SelectedTest
131131
private bool _groupByOutcome = true;
132132
public bool GroupByOutcome
133133
{
134-
get { return _groupByOutcome; }
134+
get => _groupByOutcome;
135135
set
136136
{
137-
if (_groupByOutcome != value)
137+
if (_groupByOutcome == value)
138138
{
139-
_groupByOutcome = value;
140-
OnPropertyChanged();
139+
return;
141140
}
141+
142+
_groupByOutcome = value;
143+
OnPropertyChanged();
142144
}
143145
}
144146

145147
private bool _groupByLocation;
146148
public bool GroupByLocation
147149
{
148-
get { return _groupByLocation; }
150+
get => _groupByLocation;
149151
set
150152
{
151-
if (_groupByLocation != value)
153+
if (_groupByLocation == value)
152154
{
153-
_groupByLocation = value;
154-
OnPropertyChanged();
155+
return;
155156
}
157+
158+
_groupByLocation = value;
159+
OnPropertyChanged();
156160
}
157161
}
158162

@@ -351,15 +355,15 @@ private void ExecuteCopyResultsCommand(object parameter)
351355

352356
var aResults = Model.Tests.Select(test => test.ToArray()).ToArray();
353357

354-
var resource = "Rubberduck Test Results - {0}";
358+
const string resource = "Rubberduck Test Results - {0}";
355359
var title = string.Format(resource, DateTime.Now.ToString(CultureInfo.InvariantCulture));
356360

357361
//var textResults = title + Environment.NewLine + string.Join("", _results.Select(result => result.ToString() + Environment.NewLine).ToArray());
358362
var csvResults = ExportFormatter.Csv(aResults, title, ColumnInfos);
359363
var htmlResults = ExportFormatter.HtmlClipboardFragment(aResults, title, ColumnInfos);
360364
var rtfResults = ExportFormatter.RTF(aResults, title);
361365

362-
MemoryStream strm1 = ExportFormatter.XmlSpreadsheetNew(aResults, title, ColumnInfos);
366+
var strm1 = ExportFormatter.XmlSpreadsheetNew(aResults, title, ColumnInfos);
363367
//Add the formats from richest formatting to least formatting
364368
_clipboard.AppendStream(DataFormats.GetDataFormat(XML_SPREADSHEET_DATA_FORMAT).Name, strm1);
365369
_clipboard.AppendString(DataFormats.Rtf, rtfResults);

RetailCoder.VBE/UI/UnitTesting/TestOutcomeImageSourceConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class TestOutcomeImageSourceConverter : IValueConverter
2424

2525
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
2626
{
27-
if (value.GetType() != typeof (TestOutcome))
27+
if (value?.GetType() != typeof(TestOutcome))
2828
{
29-
throw new ArgumentException("value must be a TestOutcome");
29+
return null;
3030
}
3131

3232
var outcome = (TestOutcome)value;

RetailCoder.VBE/UI/UnitTesting/TestResultToOutcomeTextConverter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ public class TestResultToOutcomeTextConverter : IValueConverter
99
{
1010
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1111
{
12-
var result = value as TestResult;
13-
if (result != null)
12+
if (value is TestResult result)
1413
{
1514
return RubberduckUI.ResourceManager.GetString("TestOutcome_" + result.Outcome, CultureInfo.CurrentUICulture);
1615
}
1716

18-
throw new ArgumentException("value is not a TestResult object.", "value");
17+
return null;
1918
}
2019

2120
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
2221
{
2322
throw new NotImplementedException();
2423
}
2524
}
26-
}
25+
}

0 commit comments

Comments
 (0)