protected ScenarioTestRunnerMock CreateRunner(Type testClass, string testMethodName) { var testCaseDiscoverer = new ScenarioExpectationDiscovererTests.TestableScenarioExpectationDiscoverer(new NullMessageSink()) { PreEnumerateTestCases = true }; var testMethod = XunitMocks.TestMethod(testClass, testMethodName); var expectThatAttribute = XunitMocks.ExpectThatAttribute(); var testCases = testCaseDiscoverer.Discover(new TestFrameworkOptions(), testMethod, expectThatAttribute); var testCase = testCases.SingleOrDefault() as ScenarioTestCase; if (testCase == null) { throw new NotSupportedException("Test case is not a ScenarioTestCase"); } var test = new ScenarioTest(testCase, testCase.DisplayName); var runner = new ScenarioTestRunnerMock(test, new NullMessageSink(), MessageBus.Object, test.TestCase.TestMethod.TestClass.Class.ToRuntimeType(), new object[0], test.TestCase.Method.ToRuntimeMethod(), new object[0], testCase.SkipReason, new BeforeAfterTestAttribute[0], Aggregator, new CancellationTokenSource() ); return(runner); }
private void PreIteration(ScenarioTest scenario) { PrintHeader("Setting up data standard output/error process handlers."); _stderr.Clear(); _stdout.Clear(); if (scenario.Process.StartInfo.RedirectStandardError) { scenario.Process.ErrorDataReceived += (object sender, DataReceivedEventArgs errorLine) => { if (!string.IsNullOrEmpty(errorLine.Data)) { _stderr.AppendLine(errorLine.Data); } }; } if (scenario.Process.StartInfo.RedirectStandardInput) { throw new NotImplementedException("RedirectStandardInput has not been implemented yet."); } if (scenario.Process.StartInfo.RedirectStandardOutput) { scenario.Process.OutputDataReceived += (object sender, DataReceivedEventArgs outputLine) => { if (!string.IsNullOrEmpty(outputLine.Data)) { _stdout.AppendLine(outputLine.Data); } }; } }
public ScenarioTestRunnerMock(ScenarioTest test, IMessageSink diagnosticMessageSink, IMessageBus messageBus, Type testClass, object[] constructorArguments, MethodInfo testMethod, object[] testMethodArguments, string skipReason, IReadOnlyList <BeforeAfterTestAttribute> beforeAfterTestAttributes, ExceptionAggregator exceptionAggregator, CancellationTokenSource cancellationTokenSource) : base(test, diagnosticMessageSink, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterTestAttributes, exceptionAggregator, cancellationTokenSource) { }
public WrongExceptionType( ScenarioTest test, Type expectedExceptionType, Exception innerException) : base(test, string.Format("Expected '{0}', but was '{1}'", expectedExceptionType.Name, innerException.GetType().Name), innerException) { ExpectedExceptionType = expectedExceptionType; ActualExceptionType = innerException.GetType(); }
public WrongExceptionType( ScenarioTest test, Type expectedExceptionType, Exception innerException) : base( test, string.Format("Expected '{0}', but was '{1}'", expectedExceptionType.Name, innerException.GetType().Name), innerException) { ExpectedExceptionType = expectedExceptionType; ActualExceptionType = innerException.GetType(); }
public static ScenarioTestMetadata Map(ScenarioTest test) { _test = test; var type = _test.GetType(); var scenario = new ScenarioTestMetadata(type); var ctor = type.GetConstructors().SingleOrDefault(); if (ctor != null) { foreach (var parameter in ctor.GetParameters()) { var backedField = type .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .SingleOrDefault( p => string.Compare(p.Name.TrimStart('_'), parameter.Name, StringComparison.InvariantCultureIgnoreCase) == 0); if (backedField != null) { string value; try { value = backedField.GetValue(_test).ToString(); } catch { value = "UNKNOWN!"; } scenario.Parameters.Add(parameter.Name.ToUpper(), value); } } } var methods = GetPotentialStepMethods(type); scenario.GivenMethods = ValidateAndBuildGivenMethods(methods); scenario.WhenMethods = ValidateAndBuildWhenMethod(methods); scenario.ThenMethods = ValidateAndBuildThenMethods(methods); return(scenario); }
public WhensShouldBePublic(ScenarioTest test, MethodBase nonPublicGiven) : base(test, string.Format("'{0}' is not public", nonPublicGiven.Name)) { }
public FixtureShouldHaveWhens(ScenarioTest test) : base(test, string.Format("No whens found; whens should be parameterless public methods that use the [When] attribute")) { }
public GivenFailed(ScenarioTest test, MethodBase stepMethod, Exception innerException) : base(test, string.Format("'{0}' failed", stepMethod.Name), innerException) { }
public ScenarioStepMethodsShouldNotHaveParameters(ScenarioTest test, string message) : base(test, message) { }
public ExpectedExceptionNotCaught(ScenarioTest test, Exception exception) : base(test, string.Format("Exception was expected (via [Throws]), but Catch<{0}>() was not called", exception.GetType()), exception) { }
public FixtureShouldNotUseTestAttribute(ScenarioTest test, MethodBase method) : base(test, string.Format("{0} should use [Then] rather than [Test]", method.Name)) { }
public ExpectedExceptionNotCaught(ScenarioTest test, Exception exception) : base(test, string.Format("Exception was expected (via [Throws]), but Catch<{0}>() was not called", exception.GetType()), exception) { }
public ScenarioTestException(ScenarioTest test, string message, Exception innerException) : base(string.Format("Error in '{0}':\r\n{1}", test.GetType().Name, message), innerException) { Test = test; }
public FixtureShouldHaveWhens(ScenarioTest test) : base(test, string.Format("No whens found; whens should be parameterless public methods that use the [When] attribute")) { }
public WhenFailed(ScenarioTest test, MethodBase stepMethod, Exception innerException) : base(test, string.Format("'{0}' threw an exception. If this is expected behavior use [Throws] attribute and add test(s) with Catch<>", stepMethod.Name), innerException) { }
public GivenFailed(ScenarioTest test, MethodBase stepMethod, Exception innerException) : base(test, string.Format("'{0}' failed", stepMethod.Name), innerException) { }
public FixtureShouldNotUseTestAttribute(ScenarioTest test, MethodBase method) : base(test, string.Format("{0} should use [Then] rather than [Test]", method.Name)) { }
public NoExceptionThrown( ScenarioTest test, Type expectedExceptionType) : base(test, string.Format("No exception was thrown, but was looking for '{0}'", expectedExceptionType), null) { }
public ScenarioTestException(ScenarioTest test, string message, Exception innerException) : base(string.Format("Error in '{0}':\r\n{1}", test.GetType().Name, message), innerException) { Test = test; }
public NoExceptionThrown( ScenarioTest test) : base(test, "No exception was thrown, but was expected as indicated by [Throws]", null) { }
public ScenarioTestException(ScenarioTest test, string message) : this(test, message, null) { }
public NoExceptionThrown( ScenarioTest test, Type expectedExceptionType) : base(test, string.Format("No exception was thrown, but was looking for '{0}'", expectedExceptionType), null) { }
public GivensShouldBePublic(ScenarioTest test, MethodBase nonPublicGiven) : base(test, string.Format("'{0}' is not public", nonPublicGiven.Name)) { }
public WhenFailed(ScenarioTest test, MethodBase stepMethod, Exception innerException) : base(test, string.Format("'{0}' threw an exception. If this is expected behavior use [Throws] attribute and add test(s) with Catch<>", stepMethod.Name), innerException) { }
public NoExceptionThrown( ScenarioTest test) : base(test, "No exception was thrown, but was expected as indicated by [Throws]", null) { }
public ScenarioTestException(ScenarioTest test, string message) : this(test, message, null) { }
public ScenarioStepMethodsShouldNotHaveParameters(ScenarioTest test, string message) : base(test, message) { }