Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
                    }
                };
            }
        }
Ejemplo n.º 3
0
 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)
 {
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
 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();
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 public WhensShouldBePublic(ScenarioTest test, MethodBase nonPublicGiven)
     : base(test, string.Format("'{0}' is not public", nonPublicGiven.Name))
 {
 }
Ejemplo n.º 8
0
 public FixtureShouldHaveWhens(ScenarioTest test)
     : base(test, string.Format("No whens found; whens should be parameterless public methods that use the [When] attribute"))
 {
 }
Ejemplo n.º 9
0
 public GivenFailed(ScenarioTest test, MethodBase stepMethod, Exception innerException)
     : base(test, string.Format("'{0}' failed", stepMethod.Name), innerException)
 {
 }
Ejemplo n.º 10
0
 public ScenarioStepMethodsShouldNotHaveParameters(ScenarioTest test, string message) :
     base(test, message)
 {
 }
Ejemplo n.º 11
0
 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))
 {
 }
Ejemplo n.º 13
0
 public ExpectedExceptionNotCaught(ScenarioTest test, Exception exception) :
     base(test, string.Format("Exception was expected (via [Throws]), but Catch<{0}>() was not called", exception.GetType()), exception)
 {
 }
Ejemplo n.º 14
0
 public ScenarioTestException(ScenarioTest test, string message, Exception innerException) :
     base(string.Format("Error in '{0}':\r\n{1}", test.GetType().Name, message), innerException)
 {
     Test = test;
 }
Ejemplo n.º 15
0
 public FixtureShouldHaveWhens(ScenarioTest test)
     : base(test, string.Format("No whens found; whens should be parameterless public methods that use the [When] attribute"))
 {
 }
Ejemplo n.º 16
0
 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)
 {
 }
Ejemplo n.º 17
0
 public GivenFailed(ScenarioTest test, MethodBase stepMethod, Exception innerException) :
     base(test, string.Format("'{0}' failed", stepMethod.Name), innerException)
 {
 }
Ejemplo n.º 18
0
 public FixtureShouldNotUseTestAttribute(ScenarioTest test, MethodBase method) : base(test, string.Format("{0} should use [Then] rather than [Test]", method.Name))
 {
 }
Ejemplo n.º 19
0
 public NoExceptionThrown(
     ScenarioTest test,
     Type expectedExceptionType) :
     base(test, string.Format("No exception was thrown, but was looking for '{0}'", expectedExceptionType), null)
 {
 }
Ejemplo n.º 20
0
 public ScenarioTestException(ScenarioTest test, string message, Exception innerException)
     : base(string.Format("Error in '{0}':\r\n{1}", test.GetType().Name, message), innerException)
 {
     Test = test;
 }
Ejemplo n.º 21
0
 public NoExceptionThrown(
     ScenarioTest test) :
     base(test, "No exception was thrown, but was expected as indicated by [Throws]", null)
 {
 }
Ejemplo n.º 22
0
 public ScenarioTestException(ScenarioTest test, string message) :
     this(test, message, null)
 {
 }
Ejemplo n.º 23
0
 public NoExceptionThrown(
     ScenarioTest test,
     Type expectedExceptionType)
     : base(test, string.Format("No exception was thrown, but was looking for '{0}'", expectedExceptionType), null)
 {
 }
Ejemplo n.º 24
0
 public GivensShouldBePublic(ScenarioTest test, MethodBase nonPublicGiven)
     : base(test, string.Format("'{0}' is not public", nonPublicGiven.Name))
 {
 }
Ejemplo n.º 25
0
 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)
 {
 }
Ejemplo n.º 26
0
 public NoExceptionThrown(
     ScenarioTest test)
     : base(test, "No exception was thrown, but was expected as indicated by [Throws]", null)
 {
 }
Ejemplo n.º 27
0
 public ScenarioTestException(ScenarioTest test, string message)
     : this(test, message, null)
 {
 }
 public ScenarioStepMethodsShouldNotHaveParameters(ScenarioTest test, string message)
     : base(test, message)
 {
 }