From ab94ca7e82627f1faed8b272343446673eb43a0c Mon Sep 17 00:00:00 2001 From: Chris Maddock Date: Fri, 6 Jan 2017 20:26:12 +0000 Subject: [PATCH] Add multiple assembly running --- .../nunit.runner.iOS/nunit.runner.iOS.csproj | 1 + .../nunit.runner.uwp.nuget.targets | 2 +- .../Extensions/XamarinExtensions.cs | 33 +++- .../{ViewModel => Helpers}/ResultSummary.cs | 167 +++++++++++++----- .../nunit.runner/Helpers/TestPackage.cs | 66 +++++++ .../nunit.runner/Helpers/TestRunResult.cs | 57 ++++++ .../nunit.runner/Messages/ErrorMessage.cs | 23 ++- .../Services/TcpWriterProcessor.cs | 11 +- .../Services/TestResultProcessor.cs | 7 +- .../nunit.runner/Services/XmlFileProcessor.cs | 33 ++-- .../nunit.runner/ViewModel/ResultViewModel.cs | 2 +- .../ViewModel/ResultsViewModel.cs | 11 +- .../ViewModel/SummaryViewModel.cs | 37 ++-- .../nunit.runner/ViewModel/TestViewModel.cs | 2 +- .../nunit.runner/nunit.runner.projitems | 4 +- .../nunit.runner.tests.uwp.nuget.targets | 2 +- 16 files changed, 343 insertions(+), 115 deletions(-) rename src/runner/nunit.runner/{ViewModel => Helpers}/ResultSummary.cs (52%) create mode 100644 src/runner/nunit.runner/Helpers/TestPackage.cs create mode 100644 src/runner/nunit.runner/Helpers/TestRunResult.cs diff --git a/src/runner/nunit.runner.iOS/nunit.runner.iOS.csproj b/src/runner/nunit.runner.iOS/nunit.runner.iOS.csproj index 43b0900..63e0ff4 100644 --- a/src/runner/nunit.runner.iOS/nunit.runner.iOS.csproj +++ b/src/runner/nunit.runner.iOS/nunit.runner.iOS.csproj @@ -54,6 +54,7 @@ + ..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll True diff --git a/src/runner/nunit.runner.uwp/nunit.runner.uwp.nuget.targets b/src/runner/nunit.runner.uwp/nunit.runner.uwp.nuget.targets index 75ebf70..a020972 100644 --- a/src/runner/nunit.runner.uwp/nunit.runner.uwp.nuget.targets +++ b/src/runner/nunit.runner.uwp/nunit.runner.uwp.nuget.targets @@ -4,6 +4,6 @@ $(UserProfile)\.nuget\packages\ - + \ No newline at end of file diff --git a/src/runner/nunit.runner/Extensions/XamarinExtensions.cs b/src/runner/nunit.runner/Extensions/XamarinExtensions.cs index 8653301..8a230c4 100644 --- a/src/runner/nunit.runner/Extensions/XamarinExtensions.cs +++ b/src/runner/nunit.runner/Extensions/XamarinExtensions.cs @@ -1,4 +1,27 @@ -using NUnit.Framework.Interfaces; +// *********************************************************************** +// Copyright (c) 2017 Charlie Poole +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// *********************************************************************** + +using NUnit.Framework.Interfaces; using Xamarin.Forms; namespace NUnit.Runner.Extensions @@ -10,18 +33,18 @@ namespace NUnit.Runner.Extensions /// /// /// - public static Color Color(this ITestResult result) + public static Color Color(this ResultState result) { - switch (result.ResultState.Status) + switch (result.Status) { case TestStatus.Passed: return Xamarin.Forms.Color.Green; case TestStatus.Skipped: return Xamarin.Forms.Color.FromRgb(206, 172, 0); // Dark Yellow case TestStatus.Failed: - if (result.ResultState == ResultState.Failure) + if (result == ResultState.Failure) return Xamarin.Forms.Color.Red; - if (result.ResultState == ResultState.NotRunnable) + if (result == ResultState.NotRunnable) return Xamarin.Forms.Color.FromRgb(255, 106, 0); // Orange return Xamarin.Forms.Color.FromRgb(170, 0, 0); // Dark Red diff --git a/src/runner/nunit.runner/ViewModel/ResultSummary.cs b/src/runner/nunit.runner/Helpers/ResultSummary.cs similarity index 52% rename from src/runner/nunit.runner/ViewModel/ResultSummary.cs rename to src/runner/nunit.runner/Helpers/ResultSummary.cs index cc4653d..4cd73bd 100644 --- a/src/runner/nunit.runner/ViewModel/ResultSummary.cs +++ b/src/runner/nunit.runner/Helpers/ResultSummary.cs @@ -1,5 +1,5 @@ // *********************************************************************** -// Copyright (c) 2014 Charlie Poole +// Copyright (c) 2017 Charlie Poole // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -21,32 +21,80 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // *********************************************************************** +using System.Collections.Generic; +using System.Globalization; +using System.Reflection; +using System.Xml.Linq; using NUnit.Framework.Interfaces; using NUnit.Runner.Extensions; using Xamarin.Forms; -namespace Nunit.Runner.ViewModel +namespace NUnit.Runner.Helpers { /// - /// Helper class used to summarize the result of a test run + /// Helper class used to summarize the result of a test run. /// - public class ResultSummary + internal class ResultSummary { + private readonly TestRunResult _results; + private XDocument _xmlResults; + #region Constructor - /// - /// Initializes a new instance of the class. - /// - /// The result. - public ResultSummary(ITestResult result) + public ResultSummary(TestRunResult results) { - TestResult = result; - InitializeCounters(); - Summarize(result); + _results = results; + Initialize(); + Summarize(results.TestResults); + } - OverallResult = result.ResultState.Status.ToString(); - if (OverallResult == "Skipped") - OverallResult = "Warning"; + #endregion + + #region Public Methods + /// + ///Gets all TestResults + /// + /// + public IReadOnlyCollection GetTestResults() + { + return _results.TestResults; + } + + /// + /// Summarizes all of the results and returns the test result xml document + /// + /// + public XDocument GetTestXml() + { + if (_xmlResults != null) + return _xmlResults; + + var test = new XElement("test-run"); + test.Add(new XAttribute("id", "0")); + test.Add(new XAttribute("testcasecount", TestCount)); + test.Add(new XAttribute("total", TestCount)); + test.Add(new XAttribute("passed", PassCount)); + test.Add(new XAttribute("failed", FailureCount)); + test.Add(new XAttribute("inconclusive", InconclusiveCount)); + test.Add(new XAttribute("skipped", SkipCount)); + test.Add(new XAttribute("asserts", AssertCount)); + test.Add(new XAttribute("result", OverallResult)); + + test.Add(new XAttribute("xamarin-runner-version", typeof(ResultSummary).GetTypeInfo().Assembly.GetName().Version.ToString())); + + var startTime = _results.StartTime; + var endTime = _results.EndTime; + var duration = endTime.Subtract(startTime).TotalSeconds; + + test.Add(new XAttribute("start-time", startTime.ToString("u"))); + test.Add(new XAttribute("end-time", endTime.ToString("u"))); + test.Add(new XAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo))); + + foreach (var result in _results.TestResults) + test.Add(XElement.Parse(result.ToXml(true).OuterXml)); + + _xmlResults = new XDocument(test); + return _xmlResults; } #endregion @@ -54,21 +102,16 @@ namespace Nunit.Runner.ViewModel #region Properties /// - /// Gets the test result this summary was created with + /// The overall result of the test run. /// - public ITestResult TestResult { get; private set; } - - /// - /// A string representation of the overall result of the test run. - /// - public string OverallResult { get; private set; } + public TestStatus OverallResult { get; private set; } /// /// Gets the color for the overall result. /// public Color OverallResultColor { - get { return TestResult.Color(); } + get { return new ResultState(OverallResult).Color(); } } /// @@ -78,17 +121,22 @@ namespace Nunit.Runner.ViewModel /// public int TestCount { get; private set; } + /// + /// Gets the number of asserts + /// + public int AssertCount { get; private set; } + /// /// Returns the number of test cases actually run. /// public int RunCount { get { return PassCount + FailureCount + ErrorCount + InconclusiveCount; } } - + /// /// Returns the number of test cases not run for any reason. /// public int NotRunCount { - get { return IgnoreCount + ExplicitCount + InvalidCount + SkipCount; } + get { return IgnoreCount + ExplicitCount + InvalidCount + SkipCount; } } /// @@ -137,7 +185,7 @@ namespace Nunit.Runner.ViewModel #region Helper Methods - private void InitializeCounters() + private void Initialize() { TestCount = 0; PassCount = 0; @@ -148,10 +196,19 @@ namespace Nunit.Runner.ViewModel IgnoreCount = 0; ExplicitCount = 0; InvalidCount = 0; + OverallResult = TestStatus.Inconclusive; + } + + private void Summarize(IEnumerable results) + { + foreach (var result in results) + Summarize(result); } private void Summarize(ITestResult result) { + var status = TestStatus.Inconclusive; + if (result.Test.IsSuite) { foreach (ITestResult r in result.Children) @@ -160,34 +217,52 @@ namespace Nunit.Runner.ViewModel else { TestCount++; + AssertCount += result.AssertCount; switch (result.ResultState.Status) { - case TestStatus.Passed: - PassCount++; + case TestStatus.Passed: + PassCount++; + if (status == TestStatus.Inconclusive) + status = TestStatus.Passed; + break; + case TestStatus.Failed: + status = TestStatus.Failed; + if (result.ResultState == ResultState.Failure) + FailureCount++; + else if (result.ResultState == ResultState.NotRunnable) + InvalidCount++; + else + ErrorCount++; + break; + case TestStatus.Skipped: + if (result.ResultState == ResultState.Ignored) + IgnoreCount++; + else if (result.ResultState == ResultState.Explicit) + ExplicitCount++; + else + SkipCount++; + break; + case TestStatus.Inconclusive: + InconclusiveCount++; + break; + } + + switch (OverallResult) + { + case TestStatus.Inconclusive: + OverallResult = status; break; - case TestStatus.Failed: - if (result.ResultState == ResultState.Failure) - FailureCount++; - else if (result.ResultState == ResultState.NotRunnable) - InvalidCount++; - else - ErrorCount++; + case TestStatus.Passed: + if (status == TestStatus.Failed) + OverallResult = status; break; case TestStatus.Skipped: - if (result.ResultState == ResultState.Ignored) - IgnoreCount++; - else if (result.ResultState == ResultState.Explicit) - ExplicitCount++; - else - SkipCount++; - break; - case TestStatus.Inconclusive: - InconclusiveCount++; + case TestStatus.Failed: + default: break; } } } - #endregion } -} +} \ No newline at end of file diff --git a/src/runner/nunit.runner/Helpers/TestPackage.cs b/src/runner/nunit.runner/Helpers/TestPackage.cs new file mode 100644 index 0000000..f0f0405 --- /dev/null +++ b/src/runner/nunit.runner/Helpers/TestPackage.cs @@ -0,0 +1,66 @@ +// *********************************************************************** +// Copyright (c) 2017 Charlie Poole +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// *********************************************************************** + +using System.Collections.Generic; +using System.Reflection; +using System.Threading.Tasks; +using NUnit.Framework.Api; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; + +namespace NUnit.Runner.Helpers +{ + /// + /// Contains all assemblies for a test run, and controls execution of tests and collection of results + /// + internal class TestPackage + { + private readonly List _testAssemblies = new List(); + + public void AddAssembly(Assembly testAssembly) + { + _testAssemblies.Add(testAssembly); + } + + public async Task ExecuteTests() + { + var resultPackage = new TestRunResult(); + + foreach (var assembly in _testAssemblies) + { + NUnitTestAssemblyRunner runner = await LoadTestAssemblyAsync(assembly).ConfigureAwait(false); + ITestResult result = await Task.Run(() => runner.Run(TestListener.NULL, TestFilter.Empty)).ConfigureAwait(false); + resultPackage.AddResult(result); + } + resultPackage.CompleteTestRun(); + return resultPackage; + } + + private static async Task LoadTestAssemblyAsync(Assembly assembly) + { + var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); + await Task.Run(() => runner.Load(assembly, new Dictionary())); + return runner; + } + } +} diff --git a/src/runner/nunit.runner/Helpers/TestRunResult.cs b/src/runner/nunit.runner/Helpers/TestRunResult.cs new file mode 100644 index 0000000..60b2bba --- /dev/null +++ b/src/runner/nunit.runner/Helpers/TestRunResult.cs @@ -0,0 +1,57 @@ +// *********************************************************************** +// Copyright (c) 2017 Charlie Poole +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// *********************************************************************** + +using System; +using System.Collections.Generic; +using NUnit.Framework.Interfaces; + +namespace NUnit.Runner.Helpers +{ + /// + /// Contains all results from all tests in a + /// + internal class TestRunResult + { + private readonly List _results = new List(); + + public DateTime StartTime { get; private set; } + public DateTime EndTime { get; private set; } + + public TestRunResult() + { + StartTime = DateTime.Now; + } + + public void AddResult(ITestResult result) + { + _results.Add(result); + } + + public void CompleteTestRun() + { + EndTime = DateTime.Now; + } + + public IReadOnlyCollection TestResults => _results; + } +} diff --git a/src/runner/nunit.runner/Messages/ErrorMessage.cs b/src/runner/nunit.runner/Messages/ErrorMessage.cs index a94090e..c0cb2ee 100644 --- a/src/runner/nunit.runner/Messages/ErrorMessage.cs +++ b/src/runner/nunit.runner/Messages/ErrorMessage.cs @@ -1,4 +1,25 @@ - +// *********************************************************************** +// Copyright (c) 2017 Charlie Poole +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// *********************************************************************** namespace NUnit.Runner.Messages { diff --git a/src/runner/nunit.runner/Services/TcpWriterProcessor.cs b/src/runner/nunit.runner/Services/TcpWriterProcessor.cs index 003b6a9..536a3e3 100644 --- a/src/runner/nunit.runner/Services/TcpWriterProcessor.cs +++ b/src/runner/nunit.runner/Services/TcpWriterProcessor.cs @@ -27,6 +27,7 @@ using System.Threading.Tasks; using NUnit.Framework.Interfaces; using Xamarin.Forms; using NUnit.Runner.Messages; +using NUnit.Runner.Helpers; namespace NUnit.Runner.Services { @@ -37,13 +38,13 @@ namespace NUnit.Runner.Services { } - public override async Task Process(ITestResult testResult) + public override async Task Process(ResultSummary result) { if (Options.TcpWriterParameters != null) { try { - await WriteResult(testResult); + await WriteResult(result); } catch (Exception exception) { @@ -54,16 +55,16 @@ namespace NUnit.Runner.Services if (Successor != null) { - await Successor.Process(testResult); + await Successor.Process(result); } } - private async Task WriteResult(ITestResult testResult) + private async Task WriteResult(ResultSummary testResult) { using (var tcpWriter = new TcpWriter(Options.TcpWriterParameters)) { await tcpWriter.Connect().ConfigureAwait(false); - tcpWriter.Write(testResult.ToXml(true).OuterXml); + tcpWriter.Write(testResult.GetTestXml()); } } } diff --git a/src/runner/nunit.runner/Services/TestResultProcessor.cs b/src/runner/nunit.runner/Services/TestResultProcessor.cs index 89d4545..1086380 100644 --- a/src/runner/nunit.runner/Services/TestResultProcessor.cs +++ b/src/runner/nunit.runner/Services/TestResultProcessor.cs @@ -22,8 +22,7 @@ // *********************************************************************** using System.Threading.Tasks; - -using NUnit.Framework.Interfaces; +using NUnit.Runner.Helpers; namespace NUnit.Runner.Services { @@ -36,9 +35,9 @@ namespace NUnit.Runner.Services protected TestOptions Options { get; private set; } - public TestResultProcessor Successor { get; set; } + protected TestResultProcessor Successor { get; private set; } - public abstract Task Process(ITestResult testResult); + public abstract Task Process(ResultSummary testResult); public static TestResultProcessor BuildChainOfResponsability(TestOptions options) { diff --git a/src/runner/nunit.runner/Services/XmlFileProcessor.cs b/src/runner/nunit.runner/Services/XmlFileProcessor.cs index 3fd4b21..917acc1 100644 --- a/src/runner/nunit.runner/Services/XmlFileProcessor.cs +++ b/src/runner/nunit.runner/Services/XmlFileProcessor.cs @@ -22,12 +22,13 @@ // *********************************************************************** using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; using NUnit.Framework.Interfaces; - +using NUnit.Runner.Helpers; using PCLStorage; using CreationCollisionOption = PCLStorage.CreationCollisionOption; using FileAccess = PCLStorage.FileAccess; @@ -39,28 +40,28 @@ namespace NUnit.Runner.Services public XmlFileProcessor(TestOptions options) : base(options) { } - public override async Task Process(ITestResult testResult) + public override async Task Process(ResultSummary result) { - if (Options.CreateXmlResultFile) + if (Options.CreateXmlResultFile == false) + return; + + try { - try - { - await WriteXmlResultFile(testResult).ConfigureAwait(false); - } - catch (Exception) - { - Debug.WriteLine("Fatal error while trying to write xml result file!"); - throw; - } + await WriteXmlResultFile(result).ConfigureAwait(false); + } + catch (Exception) + { + Debug.WriteLine("Fatal error while trying to write xml result file!"); + throw; } if (Successor != null) { - await Successor.Process(testResult).ConfigureAwait(false); + await Successor.Process(result).ConfigureAwait(false); } } - async Task WriteXmlResultFile(ITestResult testResult) + async Task WriteXmlResultFile(ResultSummary result) { string outputFolderName = Path.GetDirectoryName(Options.ResultFilePath); string outputXmlReportName = Path.GetFileName(Options.ResultFilePath); @@ -74,8 +75,8 @@ namespace NUnit.Runner.Services await outputFolder.CreateFileAsync(outputXmlReportName, CreationCollisionOption.ReplaceExisting); using (var resultFileStream = new StreamWriter(await xmlResultFile.OpenAsync(FileAccess.ReadAndWrite))) { - string xmlString = testResult.ToXml(true).OuterXml; - await resultFileStream.WriteAsync(xmlString); + var xml = result.GetTestXml().ToString(); + await resultFileStream.WriteAsync(xml); } } diff --git a/src/runner/nunit.runner/ViewModel/ResultViewModel.cs b/src/runner/nunit.runner/ViewModel/ResultViewModel.cs index 1f68bcd..0a1108a 100644 --- a/src/runner/nunit.runner/ViewModel/ResultViewModel.cs +++ b/src/runner/nunit.runner/ViewModel/ResultViewModel.cs @@ -49,7 +49,7 @@ namespace NUnit.Runner.ViewModel /// public Color Color { - get { return TestResult.Color(); } + get { return TestResult.ResultState.Color(); } } } } \ No newline at end of file diff --git a/src/runner/nunit.runner/ViewModel/ResultsViewModel.cs b/src/runner/nunit.runner/ViewModel/ResultsViewModel.cs index dfb4d88..b5f6e35 100644 --- a/src/runner/nunit.runner/ViewModel/ResultsViewModel.cs +++ b/src/runner/nunit.runner/ViewModel/ResultsViewModel.cs @@ -21,11 +21,9 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // *********************************************************************** +using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Windows.Input; using NUnit.Framework.Interfaces; -using NUnit.Runner.View; -using Xamarin.Forms; namespace NUnit.Runner.ViewModel { @@ -34,13 +32,14 @@ namespace NUnit.Runner.ViewModel /// /// Constructs the view model /// - /// The top level test results + /// The package of all results in run /// If true, views all tests, otherwise only shows those /// that did not pass - public ResultsViewModel(ITestResult testResult, bool viewAll) + public ResultsViewModel(IReadOnlyCollection results, bool viewAll) { Results = new ObservableCollection(); - AddTestResults(testResult, viewAll); + foreach (var result in results) + AddTestResults(result, viewAll); } /// diff --git a/src/runner/nunit.runner/ViewModel/SummaryViewModel.cs b/src/runner/nunit.runner/ViewModel/SummaryViewModel.cs index ef15abd..fe4e03a 100644 --- a/src/runner/nunit.runner/ViewModel/SummaryViewModel.cs +++ b/src/runner/nunit.runner/ViewModel/SummaryViewModel.cs @@ -21,18 +21,11 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // *********************************************************************** -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; using System.Threading.Tasks; using System.Windows.Input; - -using NUnit.Framework.Api; -using NUnit.Framework.Interfaces; -using NUnit.Framework.Internal; +using NUnit.Runner.Helpers; using NUnit.Runner.View; -using Nunit.Runner.ViewModel; using NUnit.Runner.Services; @@ -42,20 +35,20 @@ namespace NUnit.Runner.ViewModel { class SummaryViewModel : BaseViewModel { - readonly IList _testAssemblies; + readonly TestPackage _testPackage; ResultSummary _results; bool _running; TestResultProcessor _resultProcessor; public SummaryViewModel() { - _testAssemblies = new List(); + _testPackage = new TestPackage(); RunTestsCommand = new Command(async o => await ExecuteTestsAync(), o => !Running); ViewAllResultsCommand = new Command( - async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(Results.TestResult, true))), + async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(_results.GetTestResults(), true))), o => !HasResults); ViewFailedResultsCommand = new Command( - async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(Results.TestResult, false))), + async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(_results.GetTestResults(), false))), o => !HasResults); } @@ -122,25 +115,23 @@ namespace NUnit.Runner.ViewModel /// internal void AddTest(Assembly testAssembly) { - _testAssemblies.Add(testAssembly); + _testPackage.AddAssembly(testAssembly); } async Task ExecuteTestsAync() { Running = true; Results = null; - - var runner = await LoadTestAssembliesAsync().ConfigureAwait(false); - - ITestResult result = await Task.Run(() => runner.Run(TestListener.NULL, TestFilter.Empty)).ConfigureAwait(false); + TestRunResult results = await _testPackage.ExecuteTests(); + ResultSummary summary = new ResultSummary(results); _resultProcessor = TestResultProcessor.BuildChainOfResponsability(Options); - await _resultProcessor.Process(result).ConfigureAwait(false); + await _resultProcessor.Process(summary).ConfigureAwait(false); Device.BeginInvokeOnMainThread( () => { - Results = new ResultSummary(result); + Results = summary; Running = false; if (Options.TerminateAfterExecution) @@ -148,14 +139,6 @@ namespace NUnit.Runner.ViewModel }); } - async Task LoadTestAssembliesAsync() - { - var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); - foreach (var testAssembly in _testAssemblies) - await Task.Run(() => runner.Load(testAssembly, new Dictionary())); - return runner; - } - public static void TerminateWithSuccess() { #if __IOS__ diff --git a/src/runner/nunit.runner/ViewModel/TestViewModel.cs b/src/runner/nunit.runner/ViewModel/TestViewModel.cs index 7c63064..c0cc13d 100644 --- a/src/runner/nunit.runner/ViewModel/TestViewModel.cs +++ b/src/runner/nunit.runner/ViewModel/TestViewModel.cs @@ -61,7 +61,7 @@ namespace NUnit.Runner.ViewModel /// public Color Color { - get { return TestResult.Color(); } + get { return TestResult.ResultState.Color(); } } private string StringOrNone(string str) diff --git a/src/runner/nunit.runner/nunit.runner.projitems b/src/runner/nunit.runner/nunit.runner.projitems index ddeccf9..a261546 100644 --- a/src/runner/nunit.runner/nunit.runner.projitems +++ b/src/runner/nunit.runner/nunit.runner.projitems @@ -14,6 +14,8 @@ Code + + @@ -24,7 +26,7 @@ - + diff --git a/src/tests/nunit.runner.tests.uwp/nunit.runner.tests.uwp.nuget.targets b/src/tests/nunit.runner.tests.uwp/nunit.runner.tests.uwp.nuget.targets index 75ebf70..a020972 100644 --- a/src/tests/nunit.runner.tests.uwp/nunit.runner.tests.uwp.nuget.targets +++ b/src/tests/nunit.runner.tests.uwp/nunit.runner.tests.uwp.nuget.targets @@ -4,6 +4,6 @@ $(UserProfile)\.nuget\packages\ - + \ No newline at end of file