Skip to content

Commit

Permalink
Merge branch 'feature/Embeding_NBi_(#404)' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Sep 4, 2018
2 parents b3387c0 + eb15aeb commit b9f461a
Show file tree
Hide file tree
Showing 25 changed files with 598 additions and 135 deletions.
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);

}
}
50 changes: 50 additions & 0 deletions NBi.NUnit.Runtime/Embed/Engine.cs
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;
}


}
}
17 changes: 17 additions & 0 deletions NBi.NUnit.Runtime/Embed/Filter/NBiNameFilter.cs
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}")
{ }
}
}
46 changes: 46 additions & 0 deletions NBi.NUnit.Runtime/Embed/Filter/PropertyFilter.cs
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}";

}
}
24 changes: 24 additions & 0 deletions NBi.NUnit.Runtime/Embed/NBiPackage.cs
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;
}
}
}
22 changes: 22 additions & 0 deletions NBi.NUnit.Runtime/Embed/Result/AggregatedResult.cs
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;
}
}
}
14 changes: 14 additions & 0 deletions NBi.NUnit.Runtime/Embed/Result/DetailledResult.cs
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; }
}
}
44 changes: 44 additions & 0 deletions NBi.NUnit.Runtime/Embed/Result/FlatResultBuilder.cs
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
};
}
}
}
14 changes: 14 additions & 0 deletions NBi.NUnit.Runtime/Embed/Result/ScoreResult.cs
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; }
}
}
27 changes: 22 additions & 5 deletions NBi.NUnit.Runtime/NBi.NUnit.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,19 @@
<Reference Include="Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.3.3.4\lib\net45\Ninject.dll</HintPath>
</Reference>
<Reference Include="nunit.core">
<HintPath>..\Librairies\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces">
<HintPath>..\Librairies\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Librairies\nunit.util.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
Expand All @@ -62,17 +72,26 @@
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="CategoryHelper.cs" />
<Compile Include="Embed\Engine.cs" />
<Compile Include="Embed\Filter\NBiNameFilter.cs" />
<Compile Include="Embed\Filter\PropertyFilter.cs" />
<Compile Include="Embed\NBiPackage.cs" />
<Compile Include="Embed\Result\AggregatedResult.cs" />
<Compile Include="Embed\Result\DetailledResult.cs" />
<Compile Include="Embed\Result\FlatResultBuilder.cs" />
<Compile Include="Embed\Result\ScoreResult.cs" />
<Compile Include="NullConfigurationProvider.cs" />
<Compile Include="Configuration\FailureReportProfileElement.cs" />
<Compile Include="Configuration\ExtensionCollection.cs" />
<Compile Include="Configuration\ExtensionElement.cs" />
<Compile Include="ConnectionStringsFinder.cs" />
<Compile Include="ConfigurationFinder.cs" />
<Compile Include="ConfigurationProvider.cs" />
<Compile Include="CustomStackTraceErrorException.cs" />
<Compile Include="CustomStackTraceAssertionException.cs" />
<Compile Include="Configuration\NBiSection.cs" />
<Compile Include="TestSuite.cs" />
<Compile Include="Properties\ProjectAssemblyInfo.cs" />
<Compile Include="TestSuiteFinder.cs" />
<Compile Include="TestSuiteProvider.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down Expand Up @@ -105,9 +124,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="Runner\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Q /Y "$(SolutionDir)NBi.Core\$(OutDir)Microsoft.AnalysisServices.AdomdClient.dll" "$(TargetDir)"
Expand Down
14 changes: 14 additions & 0 deletions NBi.NUnit.Runtime/NullConfigurationProvider.cs
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();
}
}
Loading

0 comments on commit b9f461a

Please sign in to comment.