Skip to content

Commit

Permalink
Refactor code / fix bugs / add exception handling / move import cover…
Browse files Browse the repository at this point in the history
…age button to the report tab if the test solution can be loaded / make it possible to generate HTML report from imported coverage reports
  • Loading branch information
axodox committed Jul 1, 2018
1 parent 8fa4a43 commit 18eef76
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 38 deletions.
16 changes: 13 additions & 3 deletions AxoCover/Models/Testing/Results/CoverageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class CoverageProvider : ICoverageProvider
private static readonly Regex _methodNameRegex = new Regex("^(?<returnType>[^ ]*) [^:]*::(?<methodName>[^\\(]*)\\((?<argumentList>[^\\)]*)\\)$", RegexOptions.Compiled);
private readonly Regex _visitorNameRegex = new Regex("^[^ ]* (?<visitorName>[^:]*::[^\\(]*)\\([^\\)]*\\)$", RegexOptions.Compiled);

public string ReportPath => _report?.FilePath;

public CoverageProvider(ITestProvider testProvider, ITestRunner testRunner, ITelemetryManager telemetryManager, IEditorContext editorContext)
{
_testRunner = testRunner;
Expand All @@ -40,10 +42,18 @@ public CoverageProvider(ITestProvider testProvider, ITestRunner testRunner, ITel
_editorContext.SolutionClosing += OnSolutionClosing;
}

public void OpenCoverageReport(string reportPath)
public bool TryOpenCoverageReport(string reportPath)
{
_report = GenericExtensions.ParseXml<CoverageSession>(reportPath);
CoverageUpdated?.Invoke(this, EventArgs.Empty);
try
{
_report = GenericExtensions.ParseXml<CoverageSession>(reportPath);
CoverageUpdated?.Invoke(this, EventArgs.Empty);
return true;
}
catch
{
return false;
}
}

private void OnSolutionClosing(object sender, EventArgs e)
Expand Down
4 changes: 3 additions & 1 deletion AxoCover/Models/Testing/Results/ICoverageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public interface ICoverageProvider
{
event EventHandler CoverageUpdated;

void OpenCoverageReport(string reportPath);
bool TryOpenCoverageReport(string reportPath);

string ReportPath { get; }

Task<FileCoverage> GetFileCoverageAsync(string filePath);

Expand Down
22 changes: 20 additions & 2 deletions AxoCover/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions AxoCover/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,15 @@
<value>Test anchors</value>
</data>
<data name="OpenCoverageReport" xml:space="preserve">
<value>Open report</value>
<value>Open external report</value>
</data>
<data name="OpenCoverageReportFilter" xml:space="preserve">
<value>Coverage reports (*.xml)|*.xml|All files (*.*)|*.*</value>
<value>OpenCover coverage reports (*.xml)|*.xml|All files (*.*)|*.*</value>
</data>
<data name="OpenReport" xml:space="preserve">
<value>Import</value>
</data>
<data name="OpenCoverageFailed" xml:space="preserve">
<value>Cannot import OpenCover coverage file {0}.</value>
</data>
</root>
28 changes: 28 additions & 0 deletions AxoCover/ViewModels/CoverageExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using AxoCover.Models.Testing.Results;
using AxoCover.Views;
using System;
using System.Windows;
using System.Windows.Input;

namespace AxoCover.ViewModels
Expand Down Expand Up @@ -91,6 +92,14 @@ public ICommand CollapseAllCommand
}
}

public ICommand OpenReportCommand
{
get
{
return new DelegateCommand(p => OpenCoverageReport());
}
}

public ICommand GenerateReportCommand
{
get
Expand Down Expand Up @@ -170,8 +179,27 @@ private void Update(CoverageItem resultSolution)

private async void OnCoverageUpdated(object sender, EventArgs e)
{
ReportPath = _coverageProvider.ReportPath;
var resultSolution = await _coverageProvider.GetCoverageAsync();
Update(resultSolution);
}

private void OpenCoverageReport()
{
var openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Title = Resources.OpenCoverageReport,
Filter = Resources.OpenCoverageReportFilter,
CheckFileExists = true
};

if (openFileDialog.ShowDialog() == true)
{
if(!_coverageProvider.TryOpenCoverageReport(openFileDialog.FileName))
{
MessageBox.Show(string.Format(Resources.OpenCoverageFailed, openFileDialog.FileName), Resources.OpenCoverageReport, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
}
28 changes: 21 additions & 7 deletions AxoCover/ViewModels/TestExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace AxoCover.ViewModels
Expand Down Expand Up @@ -297,7 +298,7 @@ public ICommand OpenCoverageReportCommand
{
get
{
return new DelegateCommand(OpenCoverageReport);
return new DelegateCommand(p => OpenCoverageReport());
}
}

Expand Down Expand Up @@ -430,14 +431,27 @@ private async void OnOptionChanged(object sender, PropertyChangedEventArgs e)

bool _suppressAutoLoadAndRun = false;

private async void OpenCoverageReport(object parameter)
private void OpenCoverageReport()
{
if (parameter == null) return ;
var openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Title = Resources.OpenCoverageReport,
Filter = Resources.OpenCoverageReportFilter,
CheckFileExists = true
};

_coverageProvider.OpenCoverageReport((string)parameter);
IsReportAvailable = true;
SetStateToReady();
IsReportTabSelected = true;
if (openFileDialog.ShowDialog() == true)
{
if(_coverageProvider.TryOpenCoverageReport(openFileDialog.FileName))
{
IsReportAvailable = true;
IsReportTabSelected = true;
}
else
{
MessageBox.Show(string.Format(Resources.OpenCoverageFailed, openFileDialog.FileName), Resources.OpenCoverageReport, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}

private async void RunTestItem(TestItemViewModel target, bool isCovering, bool isDebugging, bool isCoverAfterBuild = false)
Expand Down
4 changes: 4 additions & 0 deletions AxoCover/Views/CoverageExplorerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@

<DockPanel Visibility="{Binding ResultSolution, Converter={StaticResource NullToVisibilityConverter}}">
<UniformGrid Rows="1" DockPanel.Dock="Top">
<controls:ActionButton Text="{x:Static res:Resources.OpenReport}"
Icon="/AxoCover;component/Resources/open.png"
Command="{Binding OpenReportCommand}"/>

<controls:ActionButton Text="{x:Static res:Resources.GenerateReport}"
Icon="/AxoCover;component/Resources/export.png"
Command="{Binding GenerateReportCommand}"/>
Expand Down
16 changes: 4 additions & 12 deletions AxoCover/Views/TestExplorerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,6 @@
Icon="/AxoCover;component/Resources/collapse.png"
Command="{Binding CollapseAllCommand}"
Visibility="{Binding IsFiltering, Source={x:Reference _searchBox}, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"/>
<controls:ActionButton Text="{x:Static res:Resources.OpenCoverageReport}"
Icon="/AxoCover;component/Resources/open.png"
Command="{Binding OpenCoverageReportCommand}"
CommandParameter="{Binding Tag, RelativeSource={RelativeSource Self}}"
Click="OnOpenCoverageReportClick"/>
</UniformGrid>

<controls:SearchBox DockPanel.Dock="Top" x:Name="_searchBox"
Expand Down Expand Up @@ -280,13 +275,10 @@
Visibility="{Binding TestSolution.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock Text="{x:Static res:Resources.TestExplorerPlaceholder}"
TextWrapping="Wrap" Margin="12" HorizontalAlignment="Center" TextAlignment="Center"/>
<StackPanel Margin="12">
<controls:ActionButton Text="{x:Static res:Resources.OpenCoverageReport}"
Icon="/AxoCover;component/Resources/open.png"
Command="{Binding OpenCoverageReportCommand}"
CommandParameter="{Binding Tag, RelativeSource={RelativeSource Self}}"
Click="OnOpenCoverageReportClick"/>
</StackPanel>
<controls:ActionButton Text="{x:Static res:Resources.OpenCoverageReport}"
Icon="/AxoCover;component/Resources/open.png"
Command="{Binding OpenCoverageReportCommand}"
Margin="12" HorizontalAlignment="Center"/>
<StackPanel Margin="12">
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{x:Static res:Resources.SupportedTestFrameworks}" Margin="3"/>
<WrapPanel HorizontalAlignment="Center">
Expand Down
9 changes: 0 additions & 9 deletions AxoCover/Views/TestExplorerView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,5 @@ private void OnListTestItemMouseDown(object sender, MouseButtonEventArgs e)
e.Handled = true;
}
}

private void OnOpenCoverageReportClick(object sender, RoutedEventArgs e)
{
var ofd = new Microsoft.Win32.OpenFileDialog();
ofd.Filter = AxoCover.Resources.OpenCoverageReportFilter;
ofd.CheckFileExists = true;

((FrameworkElement)sender).Tag = ofd.ShowDialog() == true ? ofd.FileName : null;
}
}
}
5 changes: 4 additions & 1 deletion AxoCover/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
1.1.7
1.1.8
- Added ability to import externally generated OpenCover reports (thanks Anton Tykhyy)

1.1.7
- Coverage visualization is now tracking file changes
- Added test anchors for quick test access
- Provide PDB search paths to OpenCover
Expand Down
2 changes: 1 addition & 1 deletion AxoCover/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="26901782-38e1-48d4-94e9-557d44db052e" Version="1.1.6.14" Language="en-US" Publisher="Péter Major" />
<Identity Id="26901782-38e1-48d4-94e9-557d44db052e" Version="1.1.7.0" Language="en-US" Publisher="Péter Major" />
<DisplayName>AxoCover</DisplayName>
<Description xml:space="preserve">Nice and free .Net code coverage support for Visual Studio with OpenCover.</Description>
<MoreInfo>https://marketplace.visualstudio.com/items?itemName=axodox1.AxoCover</MoreInfo>
Expand Down

0 comments on commit 18eef76

Please sign in to comment.