Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
axodox committed Jul 2, 2018
2 parents cd5caa1 + 18eef76 commit 67524de
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 4 deletions.
16 changes: 16 additions & 0 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,6 +42,20 @@ public CoverageProvider(ITestProvider testProvider, ITestRunner testRunner, ITel
_editorContext.SolutionClosing += OnSolutionClosing;
}

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

private void OnSolutionClosing(object sender, EventArgs e)
{
_report = null;
Expand Down
4 changes: 4 additions & 0 deletions AxoCover/Models/Testing/Results/ICoverageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public interface ICoverageProvider
{
event EventHandler CoverageUpdated;

bool TryOpenCoverageReport(string reportPath);

string ReportPath { get; }

Task<FileCoverage> GetFileCoverageAsync(string filePath);

Task<CoverageItem> GetCoverageAsync();
Expand Down
38 changes: 37 additions & 1 deletion AxoCover/Resources.Designer.cs

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

14 changes: 13 additions & 1 deletion AxoCover/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
<value>Test execution started.</value>
</data>
<data name="TestExplorerPlaceholder" xml:space="preserve">
<value>Hmm... AxoCover found no unit tests in this solution. Maybe you wanted to add a new unit test project and some tests?</value>
<value>Hmm... AxoCover found no unit tests in this solution. Maybe you wanted to add a new unit test project and some tests? Or, open an existing coverage report:</value>
</data>
<data name="IsCoveringByTest" xml:space="preserve">
<value>Calculate coverage of each test separately</value>
Expand Down Expand Up @@ -660,4 +660,16 @@
<data name="ShowAnchors" xml:space="preserve">
<value>Test anchors</value>
</data>
<data name="OpenCoverageReport" xml:space="preserve">
<value>Open external report</value>
</data>
<data name="OpenCoverageReportFilter" xml:space="preserve">
<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);
}
}
}
}
}
34 changes: 34 additions & 0 deletions AxoCover/ViewModels/TestExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace AxoCover.ViewModels
{
public class TestExplorerViewModel : ViewModel
{
private readonly ICoverageProvider _coverageProvider;
private readonly IEditorContext _editorContext;
private readonly ITestProvider _testProvider;
private readonly ITestRunner _testRunner;
Expand Down Expand Up @@ -292,6 +294,14 @@ public ICommand CollapseAllCommand
}
}

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

public ICommand RunTestsCommand
{
get
Expand Down Expand Up @@ -371,6 +381,7 @@ public TestExplorerViewModel(
};
SearchViewModel = new CodeItemSearchViewModel<TestItemViewModel, TestItem>();

_coverageProvider = coverageProvider;
_editorContext = editorContext;
_testProvider = testProvider;
_testRunner = testRunner;
Expand Down Expand Up @@ -420,6 +431,29 @@ private async void OnOptionChanged(object sender, PropertyChangedEventArgs e)

bool _suppressAutoLoadAndRun = false;

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))
{
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)
{
if (target == null) return;
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
4 changes: 4 additions & 0 deletions AxoCover/Views/TestExplorerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@
Visibility="{Binding TestSolution.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock Text="{x:Static res:Resources.TestExplorerPlaceholder}"
TextWrapping="Wrap" Margin="12" HorizontalAlignment="Center" TextAlignment="Center"/>
<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
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 67524de

Please sign in to comment.