Skip to content

Commit

Permalink
Unit testing XAML bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
IvenBach committed Nov 17, 2017
1 parent 0650b07 commit cd113a8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
13 changes: 7 additions & 6 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml
Expand Up @@ -17,10 +17,12 @@
<UserControl.Resources>
<BitmapImage x:Key="SettingsImage" UriSource="../../Resources/gear.png" />


<local:TestOutcomeImageSourceConverter x:Key="OutcomeIconConverter" />



<local:TestResultToOutcomeTextConverter x:Key="OutcomeTextConverter" />

<BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
<converters:InvertBoolValueConverter x:Key="InvertBoolValue" />

Expand Down Expand Up @@ -272,9 +274,9 @@
<componentModel:SortDescription PropertyName="Result.Outcome" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<!--

<PropertyGroupDescription PropertyName="Result" Converter="{StaticResource OutcomeTextConverter}" />
-->

</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<SolidColorBrush x:Key="ToolBarToggleButtonVerticalBackground" Color="#FFEEF5FD"/>
Expand Down Expand Up @@ -610,7 +612,6 @@
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
</DataGrid.Columns>
</controls:GroupingGrid>
<!--
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByModule}}"
SelectedItem="{Binding SelectedTest}"
ShowGroupingItemCount="True"
Expand All @@ -629,7 +630,7 @@
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
</DataGrid.Columns>
</controls:GroupingGrid>
-->

</Grid>
</ScrollViewer>
</Border>
Expand Down
11 changes: 4 additions & 7 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml.cs
Expand Up @@ -18,16 +18,14 @@ public TestExplorerControl()
_dispatcher = Dispatcher.CurrentDispatcher;
}

void TestExplorerControl_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
private void TestExplorerControl_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
var oldContext = e.OldValue as TestExplorerViewModel;
if (oldContext != null)
if (e.OldValue is TestExplorerViewModel oldContext)
{
oldContext.TestCompleted -= OnTestCompleted;
}

var context = e.NewValue as TestExplorerViewModel;
if (context != null)
if (e.NewValue is TestExplorerViewModel context)
{
context.TestCompleted += OnTestCompleted;
}
Expand All @@ -37,8 +35,7 @@ private void OnTestCompleted(object sender, EventArgs eventArgs)
{
_dispatcher.Invoke(() =>
{
var resource = FindResource("ResultsByOutcome") as CollectionViewSource;
if (resource != null)
if (FindResource("ResultsByOutcome") is CollectionViewSource resource)
{
resource.View.Refresh();
}
Expand Down
11 changes: 5 additions & 6 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerModel.cs
Expand Up @@ -114,7 +114,7 @@ public void Refresh()
private int _executedCount;
public int ExecutedCount
{
get { return _executedCount; }
get => _executedCount;
private set
{
_executedCount = value;
Expand All @@ -125,7 +125,7 @@ private set
private Color _progressBarColor = Colors.DimGray;
public Color ProgressBarColor
{
get { return _progressBarColor; }
get => _progressBarColor;
set
{
_progressBarColor = value;
Expand All @@ -136,7 +136,7 @@ public Color ProgressBarColor
private bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
get => _isBusy;
set
{
_isBusy = value;
Expand All @@ -149,7 +149,7 @@ public bool IsBusy
private bool _isReady = true;
public bool IsReady
{
get { return _isReady; }
get => _isReady;
private set
{
_isReady = value;
Expand All @@ -160,8 +160,7 @@ private set
public event EventHandler<EventArgs> TestsRefreshed;
private void OnTestsRefreshed()
{
var handler = TestsRefreshed;
handler?.Invoke(this, EventArgs.Empty);
TestsRefreshed?.Invoke(this, EventArgs.Empty);
}

public void Dispose()
Expand Down
28 changes: 16 additions & 12 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerViewModel.cs
Expand Up @@ -115,12 +115,12 @@ private void TestEngineTestCompleted(object sender, EventArgs e)
handler?.Invoke(sender, e);
}

public INavigateSource SelectedItem { get { return SelectedTest; } }
public INavigateSource SelectedItem => SelectedTest;

private TestMethod _selectedTest;
public TestMethod SelectedTest
{
get { return _selectedTest; }
get => _selectedTest;
set
{
_selectedTest = value;
Expand All @@ -131,28 +131,32 @@ public TestMethod SelectedTest
private bool _groupByOutcome = true;
public bool GroupByOutcome
{
get { return _groupByOutcome; }
get => _groupByOutcome;
set
{
if (_groupByOutcome != value)
if (_groupByOutcome == value)
{
_groupByOutcome = value;
OnPropertyChanged();
return;
}

_groupByOutcome = value;
OnPropertyChanged();
}
}

private bool _groupByLocation;
public bool GroupByLocation
{
get { return _groupByLocation; }
get => _groupByLocation;
set
{
if (_groupByLocation != value)
if (_groupByLocation == value)
{
_groupByLocation = value;
OnPropertyChanged();
return;
}

_groupByLocation = value;
OnPropertyChanged();
}
}

Expand Down Expand Up @@ -351,15 +355,15 @@ private void ExecuteCopyResultsCommand(object parameter)

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

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

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

MemoryStream strm1 = ExportFormatter.XmlSpreadsheetNew(aResults, title, ColumnInfos);
var strm1 = ExportFormatter.XmlSpreadsheetNew(aResults, title, ColumnInfos);
//Add the formats from richest formatting to least formatting
_clipboard.AppendStream(DataFormats.GetDataFormat(XML_SPREADSHEET_DATA_FORMAT).Name, strm1);
_clipboard.AppendString(DataFormats.Rtf, rtfResults);
Expand Down
Expand Up @@ -24,9 +24,9 @@ public class TestOutcomeImageSourceConverter : IValueConverter

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value.GetType() != typeof (TestOutcome))
if (value?.GetType() != typeof(TestOutcome))
{
throw new ArgumentException("value must be a TestOutcome");
return null;
}

var outcome = (TestOutcome)value;
Expand Down
Expand Up @@ -9,18 +9,17 @@ public class TestResultToOutcomeTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var result = value as TestResult;
if (result != null)
if (value is TestResult result)
{
return RubberduckUI.ResourceManager.GetString("TestOutcome_" + result.Outcome, CultureInfo.CurrentUICulture);
}

throw new ArgumentException("value is not a TestResult object.", "value");
return null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}

0 comments on commit cd113a8

Please sign in to comment.