-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/Embeding_NBi_(#404)' into develop
- Loading branch information
Showing
25 changed files
with
598 additions
and
135 deletions.
There are no files selected for viewing
62 changes: 33 additions & 29 deletions
62
NBi.NUnit.Runtime/ConfigurationFinder.cs → NBi.NUnit.Runtime/ConfigurationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
using NBi.NUnit.Runtime.Configuration; | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace NBi.NUnit.Runtime | ||
{ | ||
public class ConfigurationFinder | ||
{ | ||
protected internal virtual NBiSection Find() | ||
{ | ||
string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; | ||
//Try to find a config file, if existing take the path inside for the TestSuite | ||
if (File.Exists(configFile)) | ||
{ | ||
//line bellow to avoid .Net framework bug: http://support.microsoft.com/kb/2580188/en-us | ||
var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | ||
|
||
var section = (NBiSection)(configuration.GetSection("nbi")); | ||
if (section != null) | ||
return section; | ||
|
||
} | ||
return new NBiSection(); | ||
} | ||
} | ||
} | ||
using NBi.NUnit.Runtime.Configuration; | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace NBi.NUnit.Runtime | ||
{ | ||
public class ConfigurationProvider | ||
{ | ||
public virtual NBiSection GetSection() | ||
{ | ||
string configFile = GetFileName(); | ||
//Try to find a config file, if existing take the path inside for the TestSuite | ||
if (File.Exists(configFile)) | ||
{ | ||
//line bellow to avoid .Net framework bug: http://support.microsoft.com/kb/2580188/en-us | ||
var configuration = Open(); | ||
|
||
var section = (NBiSection)(configuration.GetSection("nbi")); | ||
if (section != null) | ||
return section; | ||
|
||
} | ||
return new NBiSection(); | ||
} | ||
|
||
protected virtual string GetFileName() => AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; | ||
protected virtual System.Configuration.Configuration Open() => ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using NBi.NUnit.Runtime.Embed.Result; | ||
using NBi.NUnit.Runtime; | ||
using NBi.Xml; | ||
using NUnit.Core; | ||
using NUnit.Core.Filters; | ||
using NUnit.Util; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed | ||
{ | ||
public class Engine | ||
{ | ||
protected string BinPath { get; } | ||
|
||
public TestResult Execute(string configFileName) => Execute(configFileName, TestFilter.Empty); | ||
|
||
public TestResult Execute(string configFileName, ITestFilter filter) | ||
{ | ||
if (ServiceManager.Services.GetService(typeof(DomainManager))==null) | ||
{ | ||
ServiceManager.Services.AddService(new DomainManager()); | ||
ServiceManager.Services.InitializeServices(); | ||
} | ||
|
||
var package = new NBiPackage(BinPath, configFileName); | ||
|
||
var runner = new TestDomain(); | ||
runner.Load(package); | ||
var testResult = runner.Run(new NullListener(), filter, false, LoggingThreshold.Warn); | ||
|
||
return testResult; | ||
} | ||
|
||
public Engine() | ||
{ | ||
BinPath = string.Empty; | ||
} | ||
|
||
public Engine(string binPath) | ||
{ | ||
BinPath = binPath; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NUnit.Core.Filters; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed.Filter | ||
{ | ||
[Serializable] | ||
public class NBiNameFilter : SimpleNameFilter | ||
{ | ||
public NBiNameFilter(string name) | ||
: base($@"NBi.NUnit.Runtime.TestSuite.{name}") | ||
{ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using NUnit.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed.Filter | ||
{ | ||
[Serializable] | ||
public class PropertyFilter : TestFilter | ||
{ | ||
protected string Name { get; } | ||
protected string Value { get; } | ||
|
||
public PropertyFilter(string name, string value) | ||
{ | ||
Name = name; | ||
Value = value; | ||
} | ||
|
||
/// <summary> | ||
/// Check whether the filter matches a test | ||
/// </summary> | ||
/// <param name="test">The test to be matched</param> | ||
/// <returns></returns> | ||
public override bool Match(ITest test) | ||
{ | ||
if (test.Properties == null) | ||
return false; | ||
if (!test.Properties.Contains(Name)) | ||
return false; | ||
if (test.Properties[Name] as string == Value) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Return the string representation of a property filter | ||
/// </summary> | ||
/// <returns></returns> | ||
public override string ToString() => $"{Name}::{Value}"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using NUnit.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed | ||
{ | ||
|
||
[Serializable] | ||
class NBiPackage : TestPackage | ||
{ | ||
public NBiPackage(string configFile) | ||
: this(string.Empty, configFile) | ||
{ } | ||
|
||
public NBiPackage(string binPath, string configFile) | ||
: base($@"{AppDomain.CurrentDomain.SetupInformation.ApplicationBase}{binPath}\NBi.NUnit.Runtime.dll") | ||
{ | ||
ConfigurationFile = configFile; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed.Result | ||
{ | ||
public class AggregatedResult | ||
{ | ||
public IEnumerable<DetailledResult> Details { get; } | ||
|
||
public int Count => Details.Count(); | ||
public int Successes => Details.Count(r => r.IsSuccess); | ||
public int Failures => Details.Count(r => !r.IsSuccess); | ||
|
||
public AggregatedResult(IEnumerable<DetailledResult> details) | ||
{ | ||
Details = details; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed.Result | ||
{ | ||
public class DetailledResult | ||
{ | ||
public bool IsSuccess { get; set; } | ||
public string Message { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using NUnit.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed.Result | ||
{ | ||
public class FlatResultBuilder | ||
{ | ||
public AggregatedResult Execute(TestResult nunitResult) | ||
{ | ||
var details = ParseChild(Enumerable.Repeat(nunitResult, 1)); | ||
var aggregated = new AggregatedResult(details); | ||
return aggregated; | ||
} | ||
|
||
private IEnumerable<DetailledResult> ParseChild(IEnumerable<TestResult> nunitResults) | ||
{ | ||
var childResults = new List<DetailledResult>(); | ||
foreach (var r in nunitResults) | ||
{ | ||
if (r.Test.IsSuite) | ||
{ | ||
var results = ParseChild(r.Results.Cast<TestResult>()); | ||
childResults.AddRange(results); | ||
} | ||
else | ||
childResults.Add(ParseElement(r)); | ||
} | ||
return childResults; | ||
} | ||
|
||
private DetailledResult ParseElement(TestResult nunitResult) | ||
{ | ||
return new DetailledResult() | ||
{ | ||
IsSuccess = nunitResult.IsSuccess, | ||
Message = nunitResult.Message | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBi.NUnit.Runtime.Embed.Result | ||
{ | ||
public class ScoreResult : DetailledResult | ||
{ | ||
public decimal Score { get; set; } | ||
public decimal Threshold { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NBi.NUnit.Runtime.Configuration; | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace NBi.NUnit.Runtime | ||
{ | ||
public class NullConfigurationProvider : ConfigurationProvider | ||
{ | ||
public override NBiSection GetSection() => new NBiSection(); | ||
} | ||
} |
Oops, something went wrong.