Ejemplo n.º 1
0
        TestableXunitTestInvoker(
            _ITest test,
            IMessageBus messageBus,
            Type testClass,
            object?[] constructorArguments,
            MethodInfo testMethod,
            object?[]?testMethodArguments,
            IReadOnlyList <BeforeAfterTestAttribute> beforeAfterAttributes,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource,
            Action?lambda)
        {
            this.test                  = test;
            this.messageBus            = messageBus;
            this.testClass             = testClass;
            this.constructorArguments  = constructorArguments;
            this.testMethod            = testMethod;
            this.testMethodArguments   = testMethodArguments;
            this.beforeAfterAttributes = beforeAfterAttributes;
            this.lambda                = lambda;

            TestCase    = (IXunitTestCase)test.TestCase;
            Aggregator  = aggregator;
            TokenSource = cancellationTokenSource;
        }
Ejemplo n.º 2
0
        TestableTestRunner(
            _ITest test,
            IMessageBus messageBus,
            Type testClass,
            object?[] constructorArguments,
            MethodInfo testMethod,
            object?[]?testMethodArguments,
            string?skipReason,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource,
            decimal runTime,
            string output,
            Action?lambda)
        {
            this.test                 = test;
            this.messageBus           = messageBus;
            this.testClass            = testClass;
            this.constructorArguments = constructorArguments;
            this.testMethod           = testMethod;
            this.testMethodArguments  = testMethodArguments;
            this.skipReason           = skipReason;
            this.aggregator           = aggregator;
            TokenSource               = cancellationTokenSource;

            this.runTime = runTime;
            this.output  = output;
            this.lambda  = lambda;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XunitTestRunner"/> class.
 /// </summary>
 /// <param name="test">The test that this invocation belongs to.</param>
 /// <param name="messageBus">The message bus to report run status to.</param>
 /// <param name="testClass">The test class that the test method belongs to.</param>
 /// <param name="constructorArguments">The arguments to be passed to the test class constructor.</param>
 /// <param name="testMethod">The test method that will be invoked.</param>
 /// <param name="testMethodArguments">The arguments to be passed to the test method.</param>
 /// <param name="skipReason">The skip reason, if the test is to be skipped.</param>
 /// <param name="beforeAfterAttributes">The list of <see cref="BeforeAfterTestAttribute"/>s for this test.</param>
 /// <param name="aggregator">The exception aggregator used to run code and collect exceptions.</param>
 /// <param name="cancellationTokenSource">The task cancellation token source, used to cancel the test run.</param>
 public XunitTestRunner(
     _ITest test,
     IMessageBus messageBus,
     Type testClass,
     object?[] constructorArguments,
     MethodInfo testMethod,
     object?[]?testMethodArguments,
     string?skipReason,
     IReadOnlyList <BeforeAfterTestAttribute> beforeAfterAttributes,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource) :
     base(
         test,
         messageBus,
         testClass,
         constructorArguments,
         testMethod,
         testMethodArguments,
         skipReason,
         aggregator,
         cancellationTokenSource
         )
 {
     BeforeAfterAttributes = Guard.ArgumentNotNull(nameof(beforeAfterAttributes), beforeAfterAttributes);
 }
Ejemplo n.º 4
0
 public override void After(MethodInfo methodUnderTest, _ITest test)
 {
     if (workingDirectory != null)
     {
         Directory.SetCurrentDirectory(workingDirectory);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Stores the current <see cref="Thread.CurrentPrincipal" />
        /// <see cref="CultureInfo.CurrentCulture" /> and <see cref="CultureInfo.CurrentUICulture" />
        /// and replaces them with the new cultures defined in the constructor.
        /// </summary>
        /// <param name="methodUnderTest">The method under test</param>
        /// <param name="test">The current <see cref="_ITest"/></param>
        public override void Before(MethodInfo methodUnderTest, _ITest test)
        {
            originalCulture   = CultureInfo.CurrentCulture;
            originalUICulture = CultureInfo.CurrentUICulture;

            CultureInfo.CurrentCulture   = Culture;
            CultureInfo.CurrentUICulture = UICulture;
        }
Ejemplo n.º 6
0
 public override void After(
     MethodInfo methodUnderTest,
     _ITest test)
 {
     if (ThrowInAfter)
     {
         throw new AfterException();
     }
 }
Ejemplo n.º 7
0
 public override void Before(
     MethodInfo methodUnderTest,
     _ITest test)
 {
     if (ThrowInBefore)
     {
         throw new BeforeException();
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Restores the original <see cref="CultureInfo.CurrentCulture" /> and
 /// <see cref="CultureInfo.CurrentUICulture" /> to <see cref="Thread.CurrentPrincipal" />
 /// </summary>
 /// <param name="methodUnderTest">The method under test</param>
 /// <param name="test">The current <see cref="_ITest"/></param>
 public override void After(MethodInfo methodUnderTest, _ITest test)
 {
     if (originalCulture != null)
     {
         CultureInfo.CurrentCulture = originalCulture;
     }
     if (originalUICulture != null)
     {
         CultureInfo.CurrentUICulture = originalUICulture;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Initialize the test output helper with information about a test.
        /// </summary>
        public void Initialize(
            IMessageBus messageBus,
            _ITest test)
        {
            if (state != null)
            {
                throw new InvalidOperationException("Attempted to initialize a TestOutputHelper that has already been initialized");
            }

            state = new TestState(messageBus, test);
        }
Ejemplo n.º 10
0
 TestableTestInvoker(
     _ITest test,
     IMessageBus messageBus,
     Type testClass,
     MethodInfo testMethod,
     object?[]?testMethodArguments,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource) :
     base(test, messageBus, testClass, new object[0], testMethod, testMethodArguments, aggregator, cancellationTokenSource)
 {
     TestCase    = test.TestCase;
     Aggregator  = aggregator;
     TokenSource = cancellationTokenSource;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XunitTestInvokerContext"/> class.
 /// </summary>
 public XunitTestInvokerContext(
     _ITest test,
     Type testClass,
     object?[] constructorArguments,
     MethodInfo testMethod,
     object?[]?testMethodArguments,
     IMessageBus messageBus,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource,
     IReadOnlyCollection <BeforeAfterTestAttribute> beforeAfterTestAttributes) :
     base(test, testClass, constructorArguments, testMethod, testMethodArguments, messageBus, aggregator, cancellationTokenSource)
 {
     BeforeAfterTestAttributes = Guard.ArgumentNotNull(beforeAfterTestAttributes);
 }
Ejemplo n.º 12
0
            public TestState(
                IMessageBus messageBus,
                _ITest test)
            {
                Guard.ArgumentNotNull(nameof(test), test);

                this.messageBus = Guard.ArgumentNotNull(nameof(messageBus), messageBus);

                testAssemblyUniqueID   = test.TestCase.TestMethod.TestClass.TestCollection.TestAssembly.UniqueID;
                testCollectionUniqueID = test.TestCase.TestMethod.TestClass.TestCollection.UniqueID;
                testClassUniqueID      = test.TestCase.TestMethod.TestClass.UniqueID;
                testMethodUniqueID     = test.TestCase.TestMethod.UniqueID;
                testCaseUniqueID       = test.TestCase.UniqueID;
                testUniqueID           = test.UniqueID;
            }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestInvokerContext"/> class.
 /// </summary>
 public TestInvokerContext(
     _ITest test,
     Type testClass,
     object?[] constructorArguments,
     MethodInfo testMethod,
     object?[]?testMethodArguments,
     IMessageBus messageBus,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource) :
     base(messageBus, aggregator, cancellationTokenSource)
 {
     Test                 = Guard.ArgumentNotNull(test);
     TestClass            = Guard.ArgumentNotNull(testClass);
     ConstructorArguments = Guard.ArgumentNotNull(constructorArguments);
     TestMethod           = Guard.ArgumentNotNull(testMethod);
     TestMethodArguments  = testMethodArguments;
 }
Ejemplo n.º 14
0
        TestableTestInvoker(
            _ITest test,
            IMessageBus messageBus,
            Type testClass,
            MethodInfo testMethod,
            object?[]?testMethodArguments,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource)
        {
            this.test                = test;
            this.messageBus          = messageBus;
            this.testClass           = testClass;
            this.testMethod          = testMethod;
            this.testMethodArguments = testMethodArguments;

            Aggregator  = aggregator;
            TokenSource = cancellationTokenSource;
        }
Ejemplo n.º 15
0
        TestableTestRunner(
            _ITest test,
            IMessageBus messageBus,
            Type testClass,
            object?[] constructorArguments,
            MethodInfo testMethod,
            object?[]?testMethodArguments,
            string?skipReason,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource,
            decimal runTime,
            string output,
            Action?lambda) :
            base(test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, aggregator, cancellationTokenSource)
        {
            TestCase    = test.TestCase;
            TokenSource = cancellationTokenSource;

            this.runTime = runTime;
            this.output  = output;
            this.lambda  = lambda;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestInvoker{TTestCase}"/> class.
        /// </summary>
        /// <param name="test">The test that this invocation belongs to.</param>
        /// <param name="messageBus">The message bus to report run status to.</param>
        /// <param name="testClass">The test class that the test method belongs to.</param>
        /// <param name="constructorArguments">The arguments to be passed to the test class constructor.</param>
        /// <param name="testMethod">The test method that will be invoked.</param>
        /// <param name="testMethodArguments">The arguments to be passed to the test method.</param>
        /// <param name="aggregator">The exception aggregator used to run code and collect exceptions.</param>
        /// <param name="cancellationTokenSource">The task cancellation token source, used to cancel the test run.</param>
        protected TestInvoker(
            _ITest test,
            IMessageBus messageBus,
            Type testClass,
            object?[] constructorArguments,
            MethodInfo testMethod,
            object?[]?testMethodArguments,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource)
        {
            this.test                    = Guard.ArgumentNotNull(nameof(test), test);
            this.messageBus              = Guard.ArgumentNotNull(nameof(messageBus), messageBus);
            this.testClass               = Guard.ArgumentNotNull(nameof(testClass), testClass);
            this.constructorArguments    = Guard.ArgumentNotNull(nameof(constructorArguments), constructorArguments);
            this.testMethod              = Guard.ArgumentNotNull(nameof(testMethod), testMethod);
            this.aggregator              = Guard.ArgumentNotNull(nameof(aggregator), aggregator);
            this.cancellationTokenSource = Guard.ArgumentNotNull(nameof(cancellationTokenSource), cancellationTokenSource);

            TestMethodArguments = testMethodArguments;

            Guard.ArgumentValid("test", $"test.TestCase must implement {typeof(TTestCase).FullName}", test.TestCase is TTestCase);
        }
Ejemplo n.º 17
0
 public override void Before(MethodInfo methodUnderTest, _ITest test)
 {
     messages.Add("Before #" + identifier);
     base.Before(methodUnderTest, test);
 }
Ejemplo n.º 18
0
 public override void After(MethodInfo methodUnderTest, _ITest test)
 {
     messages.Add("After #" + identifier);
     base.After(methodUnderTest, test);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// This method is called before the test method is executed.
 /// </summary>
 /// <param name="methodUnderTest">The method under test</param>
 /// <param name="test">The current <see cref="_ITest"/></param>
 public virtual void Before(
     MethodInfo methodUnderTest,
     _ITest test)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// This method is called after the test method is executed.
 /// </summary>
 /// <param name="methodUnderTest">The method under test</param>
 /// <param name="test">The current <see cref="_ITest"/></param>
 public virtual void After(
     MethodInfo methodUnderTest,
     _ITest test)
 {
 }
Ejemplo n.º 21
0
 public override void Before(MethodInfo methodUnderTest, _ITest test)
 {
     workingDirectory = Directory.GetCurrentDirectory();
 }