Skip to content

Commit 14b4213

Browse files
committed
First pass at making coreclr compatible
1 parent bebe639 commit 14b4213

6 files changed

Lines changed: 78 additions & 55 deletions

File tree

src/TestStack.BDDfy/Engine.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32
using TestStack.BDDfy.Configuration;
43
using TestStack.BDDfy.Processors;
54

@@ -11,10 +10,16 @@ public class Engine
1110

1211
static Engine()
1312
{
14-
AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
13+
#if APPDOMAIN
14+
System.AppDomain.CurrentDomain.DomainUnload += (sender, e) => {
15+
InvokeBatchProcessors();
16+
};
17+
#else
18+
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += context => InvokeBatchProcessors();
19+
#endif
1520
}
1621

17-
static void CurrentDomain_DomainUnload(object sender, EventArgs e)
22+
static void InvokeBatchProcessors()
1823
{
1924
foreach (var batchProcessor in Configurator.BatchProcessors.GetProcessors())
2025
{

src/TestStack.BDDfy/Processors/ExceptionProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ExceptionProcessor : IProcessor
1616
static ExceptionProcessor()
1717
{
1818
var exceptionType = typeof(Exception);
19+
// No best guess for CORE Clr
20+
#if APPDOMAIN
1921
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
2022
{
2123
if(ExcludedAssemblies.Any(ex => assembly.GetName().FullName.StartsWith(ex)))
@@ -37,6 +39,7 @@ static ExceptionProcessor()
3739
}
3840
}
3941
}
42+
#endif
4043

4144
BestGuessInconclusiveAssertion = () => { throw new InconclusiveException(); };
4245
}

src/TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
1+
using System;
2+
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Linq;
45
using TestStack.BDDfy.Configuration;
56

67
namespace TestStack.BDDfy
@@ -36,12 +37,23 @@ private List<Step> CloneSteps(IEnumerable<Step> steps)
3637

3738
private static string GetTitleFromMethodNameInStackTrace(object testObject)
3839
{
39-
var trace = new StackTrace();
40+
// ReSharper disable once JoinDeclarationAndInitializer
41+
StackTrace trace;
42+
#if STACKTRACE
43+
trace = new StackTrace();
44+
#else
45+
try
46+
{
47+
throw new Exception();
48+
}
49+
catch (Exception e)
50+
{
51+
trace = new StackTrace(e, false);
52+
}
53+
#endif
4054
var frames = trace.GetFrames();
41-
if (frames == null)
42-
return null;
4355

44-
var initiatingFrame = frames.LastOrDefault(s => s.GetMethod().DeclaringType == testObject.GetType());
56+
var initiatingFrame = frames?.LastOrDefault(s => s.GetMethod().DeclaringType == testObject.GetType());
4557
if (initiatingFrame == null)
4658
return null;
4759

src/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy
3939
if (explicitStoryType != null)
4040
return explicitStoryType;
4141

42-
var stackTrace = new StackTrace();
42+
// ReSharper disable once JoinDeclarationAndInitializer
43+
StackTrace stackTrace;
44+
#if STACKTRACE
45+
stackTrace = new StackTrace();
46+
#else
47+
try
48+
{
49+
throw new Exception();
50+
}
51+
catch (Exception e)
52+
{
53+
stackTrace = new StackTrace(e, false);
54+
}
55+
#endif
4356
var frames = stackTrace.GetFrames();
4457
if (frames == null)
4558
return null;
46-
4759
var scenarioType = testObject.GetType();
4860
// This is assuming scenario and story live in the same assembly
4961
var firstFrame = frames.LastOrDefault(f => f.GetMethod().DeclaringType.Assembly() == scenarioType.Assembly());

src/TestStack.BDDfy/project.json

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
{
2-
"version": "1.0.0-*",
3-
"packOptions": {
4-
},
2+
"version": "1.0.0-*",
3+
"packOptions": {
4+
},
55

6-
"dependencies": {
6+
"dependencies": {
77

8-
},
8+
},
99

10-
"frameworks": {
11-
"net40": {
12-
"dependencies": {
10+
"frameworks": {
11+
"net40": {
12+
"dependencies": {
1313

14-
},
15-
"frameworkAssemblies": {
16-
"System.Web": "4.0.0.0",
17-
"System.Web.Extensions": "4.0.0.0"
18-
}
14+
},
15+
"frameworkAssemblies": {
16+
"System.Web": "4.0.0.0",
17+
"System.Web.Extensions": "4.0.0.0"
18+
},
19+
"compilationOptions": {
20+
"define": [
21+
"APPDOMAIN",
22+
"STACKTRACE"
23+
]
24+
}
25+
},
26+
"netstandard1.5": {
27+
"imports": "dnxcore50",
28+
"dependencies": {
29+
"NETStandard.Library": "1.5.0-rc2-24027",
30+
"Newtonsoft.Json": "9.0.1-beta1",
31+
"System.Diagnostics.StackTrace": "4.0.1-rc2-24027",
32+
"System.Linq.Expressions": "4.0.11-rc2-24027",
33+
"System.Reflection": "4.1.0-rc2-24027",
34+
"System.Reflection.TypeExtensions": "4.1.0-rc2-24027",
35+
"System.Runtime.Extensions": "4.1.0-rc2-24027",
36+
"System.Runtime.Loader": "4.0.0-rc3-23924",
37+
"System.Threading.ThreadPool": "4.0.10-rc2-24027"
38+
}
39+
}
1940
}
20-
//"netstandard1.5": {
21-
// "imports": "dnxcore50",
22-
// "dependencies": {
23-
// "NETStandard.Library": "1.5.0-rc2-24027",
24-
// "Newtonsoft.Json": "9.0.1-beta1",
25-
// "System.Linq.Expressions": "4.0.11-rc2-24027",
26-
// "System.Reflection": "4.1.0-rc2-24027",
27-
// "System.Reflection.TypeExtensions": "4.1.0-rc2-24027",
28-
// "System.Runtime.Extensions": "4.1.0-rc2-24027",
29-
// "System.Threading.ThreadPool": "4.0.10-rc2-24027"
30-
// }
31-
//}
32-
}
3341
}

src/TestStack.BDDfy/project.lock.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)