private static void BuildScenario <TGiven, TWhen, TThen>(ReflectionBasedScenarioRunner <TGiven, TWhen, TThen> scenarioRunner, Action <IDefine <TGiven, TWhen, TThen> > define, string title) { if (scenarioRunner.Title == null) { scenarioRunner.Title = title; } scenarioRunner.Scope = scenarioRunner.Scope ?? ScenarioScope.CurrentValue(); scenarioRunner.Group = scenarioRunner.Group ?? ScenarioGroup.CurrentValue(); var builder = ReflectionBasedScenarioRunner <TGiven, TWhen, TThen> .ScenarioDefinition.Builder; define(builder); scenarioRunner.Definition = builder.Build(); }
protected override object CallTestMethod(object testClassInstance) { object result = null; var testMethodName = ((ScenarioReportingXunitTestCase)TestCase).TestMethodName; try { using (ScenarioScope.Push(TestCase.DisplayName)) using (ScenarioGroup.Push(TestClass.FullName)) using (ReportContext.Set(_report)) { result = base.CallTestMethod(testClassInstance); } //TODO: the base class has support for f# types async results, do we need to unwrap this? if (result is Task && result.GetType().IsConstructedGenericType) { var resultType = result.GetType(); var returnType = resultType.GetGenericArguments()[0]; if (typeof(ScenarioRunResult).IsAssignableFrom(returnType)) { //Convert to scenarioRunner task var closedVerify = _openVerify.MakeGenericMethod(returnType); return(closedVerify.Invoke(this, new[] { result, TestCase.DisplayName })); } } else if (result is ScenarioRunResult) { var scenario = (ScenarioRunResult)result; VerifyAndReportScenario(scenario, TestCase.DisplayName, TestClass.FullName); } if (_scenarioRunner != null) { _scenarioRunner.AddResult(testMethodName, TestCase.DisplayName); } return(result); } catch (Exception e) { if (_scenarioRunner != null && !(e is ScenarioVerificationException)) { _scenarioRunner.AddResult(testMethodName, TestCase.DisplayName, e.Unwrap()); } Aggregator.Add(e.Unwrap()); return(result); } }