Exemple #1
0
        protected override object[] GetTestMethodArguments()
        {
            var testMethodArgumentType = (Type)TestMethodArguments.First();
            var testMethodArgument     = Activator.CreateInstance(testMethodArgumentType);

            return(new[] { testMethodArgument });
        }
Exemple #2
0
        protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator)
        {
            CompatibilityLevel?oldCompatibilityLevel = null;

            try
            {
                await SyncRoot.WaitAsync(CancellationTokenSource.Token);

                var compatibilityLevel = (CompatibilityLevel)TestMethodArguments[TestMethodArguments.Length - 1];
                TestMethodArguments = TestMethodArguments.Take(TestMethodArguments.Length - 1).ToArray();

                oldCompatibilityLevel = GlobalConfiguration.CompatibilityLevel;
                GlobalConfiguration.CompatibilityLevel = compatibilityLevel;

                return(await base.InvokeTestAsync(aggregator));
            }
            finally
            {
                if (oldCompatibilityLevel.HasValue)
                {
                    GlobalConfiguration.CompatibilityLevel = oldCompatibilityLevel.Value;
                }
                SyncRoot.Release();
            }
        }
Exemple #3
0
        public override Task <RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
        {
            Type   testMethodArgumentType = (Type)TestMethodArguments.First();
            object testMethodArgument     = Activator.CreateInstance(testMethodArgumentType);

            return(new XunitTestCaseRunner(this, DisplayName, SkipReason, constructorArguments, new [] { testMethodArgument }, messageBus, aggregator, cancellationTokenSource).RunAsync());
        }
Exemple #4
0
 /// <inheritdoc/>
 public virtual void Dispose()
 {
     if (TestMethodArguments != null)
     {
         foreach (var disposable in TestMethodArguments.OfType <IDisposable>())
         {
             disposable.Dispose();
         }
     }
 }
Exemple #5
0
        protected override object CoreRunTest(TestExecutionContext context)
        {
            try {
                var args = TestMethodArguments.Select(a => RebindDelegates(context.TestObject, a)).ToArray();

                return(InvokeMethodHelper(context.TestObject, args));
            }
            catch (TargetParameterCountException) {
                throw SpecFailure.WrongNumberOfTheoryArguments(TypeName, MethodName, _index);
            }
        }
        protected override object CreateTestClass()
        {
            var testClass = base.CreateTestClass();

            if (testClass is LoggedTest loggedTestClass)
            {
                var classType         = loggedTestClass.GetType();
                var logLevelAttribute = TestMethod.GetCustomAttribute <LogLevelAttribute>() as LogLevelAttribute;
                var testName          = TestMethodArguments.Aggregate(TestMethod.Name, (a, b) => $"{a}-{(b ?? "null")}");

                // Try resolving ITestOutputHelper from constructor arguments
                loggedTestClass.TestOutputHelper = ConstructorArguments?.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper;

                var useShortClassName = TestMethod.DeclaringType.GetCustomAttribute <ShortClassNameAttribute>()
                                        ?? TestMethod.DeclaringType.Assembly.GetCustomAttribute <ShortClassNameAttribute>();
                var resolvedClassName = useShortClassName == null ? classType.FullName : classType.Name;
                // None resolved so create a new one and retain a reference to it for initialization/uninitialization
                if (loggedTestClass.TestOutputHelper == null)
                {
                    loggedTestClass.TestOutputHelper = _output = new TestOutputHelper();
                    _output.Initialize(MessageBus, Test);
                }

                AssemblyTestLog
                .ForAssembly(classType.GetTypeInfo().Assembly)
                .StartTestLog(
                    loggedTestClass.TestOutputHelper,
                    resolvedClassName,
                    out var loggerFactory,
                    logLevelAttribute?.LogLevel ?? LogLevel.Trace,
                    out var resolvedTestName,
                    testName);

                // internal for testing
                loggedTestClass.ResolvedTestMethodName = resolvedTestName;
                loggedTestClass.ResolvedTestClassName  = resolvedClassName;

                loggedTestClass.LoggerFactory = loggerFactory;
                loggedTestClass.Logger        = loggerFactory.CreateLogger(classType);
                loggedTestClass.TestSink      = new TestSink();
                loggerFactory.AddProvider(new TestLoggerProvider(loggedTestClass.TestSink));

                loggedTestClass.AdditionalSetup();
            }

            return(testClass);
        }
Exemple #7
0
        protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator)
        {
            string output = string.Empty;

            var testOutputHelper = TestMethodArguments.OfType <TestOutputHelper>().FirstOrDefault();

            if (testOutputHelper == null)
            {
                testOutputHelper = ConstructorArguments.OfType <TestOutputHelper>().FirstOrDefault();
            }

            if (testOutputHelper == null)
            {
                testOutputHelper = new TestOutputHelper();
            }

            testOutputHelper?.Initialize(MessageBus, Test);

            decimal item = await InvokeTestMethodAsync(aggregator);

            if (testOutputHelper != null)
            {
                output = testOutputHelper.Output;

                var scenarioRunOutput = RenderScenarioReport(Scenario);
                if (scenarioRunOutput != null)
                {
                    if (output.Length == 0)
                    {
                        scenarioRunOutput = scenarioRunOutput.Trim();
                    }

                    output += scenarioRunOutput;
                }

                testOutputHelper.Uninitialize();
            }

            return(Tuple.Create(item, output));
        }