Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ _NCrunch_TestStack.BDDfy/
TestStack.BDDfy.sln.ide/
src/packages/
src/.vs/
project.lock.json
5 changes: 2 additions & 3 deletions src/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<configuration>
<packageSources>
<!-- add key="CoreCLR Xunit" value="https://www.myget.org/F/coreclr-xunit/api/v3/index.json" / -->
<!-- add key="AspNet CI Feed" value="https://www.myget.org/F/aspnetcirelease/api/v3/index.json" /> -->
<add key="myget.org xunit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="myget.org xunit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
<add key="myget.org dotnet" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
</packageSources>
</configuration>
153 changes: 153 additions & 0 deletions src/Samples/TestStack.BDDfy.Samples/AssemblySetupFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using TestStack.BDDfy.Configuration;
using TestStack.BDDfy.Reporters.Html;
using TestStack.BDDfy.Samples;
using TestStack.BDDfy.Samples.Atm;
using Xunit.Abstractions;
using Xunit.Sdk;

// The custom test framework enables the support
[assembly: Xunit.TestFramework("TestStack.BDDfy.Samples.XunitTestFrameworkWithAssemblyFixture", "TestStack.BDDfy.Samples")]

// Add one of these for every fixture classes for the assembly.
// Just like other fixtures, you can implement IDisposable and it'll
// get cleaned up at the end of the test run.
[assembly: AssemblyFixture(typeof(AssemblySetupFixture))]

namespace TestStack.BDDfy.Samples
{
public class AssemblySetupFixture
{
public AssemblySetupFixture()
{
Configurator.Processors.Add(() => new CustomTextReporter());
Configurator.BatchProcessors.MarkDownReport.Enable();
Configurator.BatchProcessors.DiagnosticsReport.Enable();
Configurator.BatchProcessors.Add(new HtmlReporter(new AtmHtmlReportConfig(), new MetroReportBuilder()));
}
}

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class AssemblyFixtureAttribute : Attribute
{
public AssemblyFixtureAttribute(Type fixtureType)
{
FixtureType = fixtureType;
}

public Type FixtureType { get; private set; }
}

public class XunitTestFrameworkWithAssemblyFixture : XunitTestFramework
{
public XunitTestFrameworkWithAssemblyFixture(IMessageSink messageSink)
: base(messageSink)
{ }

protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
=> new XunitTestFrameworkExecutorWithAssemblyFixture(assemblyName, SourceInformationProvider, DiagnosticMessageSink);
}

public class XunitTestFrameworkExecutorWithAssemblyFixture : XunitTestFrameworkExecutor
{
public XunitTestFrameworkExecutorWithAssemblyFixture(AssemblyName assemblyName,
ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink)
: base(assemblyName, sourceInformationProvider, diagnosticMessageSink)
{
}

protected override async void RunTestCases(IEnumerable<IXunitTestCase> testCases,
IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions)
{
using (
var assemblyRunner = new XunitTestAssemblyRunnerWithAssemblyFixture(TestAssembly, testCases,
DiagnosticMessageSink, executionMessageSink, executionOptions))
await assemblyRunner.RunAsync();
}
}

public class XunitTestAssemblyRunnerWithAssemblyFixture : XunitTestAssemblyRunner
{
readonly Dictionary<Type, object> assemblyFixtureMappings = new Dictionary<Type, object>();

public XunitTestAssemblyRunnerWithAssemblyFixture(ITestAssembly testAssembly,
IEnumerable<IXunitTestCase> testCases,
IMessageSink diagnosticMessageSink,
IMessageSink executionMessageSink,
ITestFrameworkExecutionOptions executionOptions)
: base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions)
{ }

protected override async Task AfterTestAssemblyStartingAsync()
{
// Let everything initialize
await base.AfterTestAssemblyStartingAsync();

// Go find all the AssemblyFixtureAttributes adorned on the test assembly
Aggregator.Run(() =>
{
var fixturesAttrs = ((IReflectionAssemblyInfo)TestAssembly.Assembly).Assembly
.GetCustomAttributes(typeof(AssemblyFixtureAttribute))
.Cast<AssemblyFixtureAttribute>()
.ToList();

// Instantiate all the fixtures
foreach (var fixtureAttr in fixturesAttrs)
assemblyFixtureMappings[fixtureAttr.FixtureType] = Activator.CreateInstance(fixtureAttr.FixtureType);
});
}

protected override Task BeforeTestAssemblyFinishedAsync()
{
// Make sure we clean up everybody who is disposable, and use Aggregator.Run to isolate Dispose failures
foreach (var disposable in assemblyFixtureMappings.Values.OfType<IDisposable>())
Aggregator.Run(disposable.Dispose);

return base.BeforeTestAssemblyFinishedAsync();
}

protected override Task<RunSummary> RunTestCollectionAsync(IMessageBus messageBus,
ITestCollection testCollection,
IEnumerable<IXunitTestCase> testCases,
CancellationTokenSource cancellationTokenSource)
=> new XunitTestCollectionRunnerWithAssemblyFixture(assemblyFixtureMappings, testCollection, testCases, DiagnosticMessageSink, messageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), cancellationTokenSource).RunAsync();
}

public class XunitTestCollectionRunnerWithAssemblyFixture : XunitTestCollectionRunner
{
readonly Dictionary<Type, object> assemblyFixtureMappings;
readonly IMessageSink diagnosticMessageSink;

public XunitTestCollectionRunnerWithAssemblyFixture(Dictionary<Type, object> assemblyFixtureMappings,
ITestCollection testCollection,
IEnumerable<IXunitTestCase> testCases,
IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
ITestCaseOrderer testCaseOrderer,
ExceptionAggregator aggregator,
CancellationTokenSource cancellationTokenSource)
: base(testCollection, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource)
{
this.assemblyFixtureMappings = assemblyFixtureMappings;
this.diagnosticMessageSink = diagnosticMessageSink;
}

protected override Task<RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable<IXunitTestCase> testCases)
{
// Don't want to use .Concat + .ToDictionary because of the possibility of overriding types,
// so instead we'll just let collection fixtures override assembly fixtures.
var combinedFixtures = new Dictionary<Type, object>(assemblyFixtureMappings);
foreach (var kvp in CollectionFixtureMappings)
combinedFixtures[kvp.Key] = kvp.Value;

// We've done everything we need, so let the built-in types do the rest of the heavy lifting
return new XunitTestClassRunner(testClass, @class, testCases, diagnosticMessageSink, MessageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), CancellationTokenSource, combinedFixtures).RunAsync();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override int GetHashCode()

public override string ToString()
{
return Amount.ToString("C", CultureInfo.CreateSpecificCulture("EN-US"));
return Amount.ToString("C", new CultureInfo("EN-US"));
}
}
}
3 changes: 2 additions & 1 deletion src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace TestStack.BDDfy.Samples
Expand All @@ -17,7 +18,7 @@ private static string OutputDirectory
{
get
{
string codeBase = typeof(CustomTextReporter).Assembly.CodeBase;
string codeBase = typeof(CustomTextReporter).GetTypeInfo().Assembly.CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return System.IO.Path.GetDirectoryName(path);
Expand Down
4 changes: 0 additions & 4 deletions src/Samples/TestStack.BDDfy.Samples/FodyWeavers.xml

This file was deleted.

21 changes: 0 additions & 21 deletions src/Samples/TestStack.BDDfy.Samples/ModuleInitializer.cs

This file was deleted.

19 changes: 19 additions & 0 deletions src/Samples/TestStack.BDDfy.Samples/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestStack.BDDfy.Samples")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c45c458d-5e2d-4ea4-a4ea-bc1931ddf15b")]
111 changes: 0 additions & 111 deletions src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.csproj

This file was deleted.

This file was deleted.

Loading