当前位置: 首页>>代码示例>>C#>>正文


C# IMessageBus.QueueMessage方法代码示例

本文整理汇总了C#中IMessageBus.QueueMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageBus.QueueMessage方法的具体用法?C# IMessageBus.QueueMessage怎么用?C# IMessageBus.QueueMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessageBus的用法示例。


在下文中一共展示了IMessageBus.QueueMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunTestsAsync

        /// <inheritdoc/>
        protected override Task RunTestsAsync(IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
        {
            if (!messageBus.QueueMessage(new TestStarting(this, DisplayName)))
                cancellationTokenSource.Cancel();
            else
            {
                try
                {
                    lambda();

                    if (!messageBus.QueueMessage(new TestPassed(this, DisplayName, 0, null)))
                        cancellationTokenSource.Cancel();
                }
                catch (Exception ex)
                {
                    if (!messageBus.QueueMessage(new TestFailed(this, DisplayName, 0, null, ex)))
                        cancellationTokenSource.Cancel();
                }
            }

            if (!messageBus.QueueMessage(new TestFinished(this, DisplayName, 0, null)))
                cancellationTokenSource.Cancel();

            return Task.FromResult(0);
        }
开发者ID:PKRoma,项目名称:xunit-codeplex,代码行数:26,代码来源:LambdaTestCase.cs

示例2: CreateTestClass

    /// <summary>
    /// Creates an instance of the test class for the given test case. Sends the <see cref="ITestClassConstructionStarting"/>
    /// and <see cref="ITestClassConstructionFinished"/> messages as appropriate.
    /// </summary>
    /// <param name="testCase">The test case</param>
    /// <param name="testClassType">The type of the test class</param>
    /// <param name="constructorArguments">The constructor arguments for the test class</param>
    /// <param name="displayName">The display name of the test case</param>
    /// <param name="messageBus">The message bus used to send the test messages</param>
    /// <param name="timer">The timer used to measure the time taken for construction</param>
    /// <param name="cancellationTokenSource">The cancellation token source</param>
    /// <returns></returns>
    public static object CreateTestClass(this ITestCase testCase,
                                         Type testClassType,
                                         object[] constructorArguments,
                                         string displayName,
                                         IMessageBus messageBus,
                                         ExecutionTimer timer,
                                         CancellationTokenSource cancellationTokenSource)
    {
        object testClass = null;

        if (!messageBus.QueueMessage(new TestClassConstructionStarting(testCase, displayName)))
            cancellationTokenSource.Cancel();

        try
        {
            if (!cancellationTokenSource.IsCancellationRequested)
                timer.Aggregate(() => testClass = Activator.CreateInstance(testClassType, constructorArguments));
        }
        finally
        {
            if (!messageBus.QueueMessage(new TestClassConstructionFinished(testCase, displayName)))
                cancellationTokenSource.Cancel();
        }

        return testClass;
    }
开发者ID:ansarisamer,项目名称:xunit,代码行数:38,代码来源:ReflectionAbstractionExtensions.cs

示例3: RunTestsOnMethodAsync

        protected override async Task RunTestsOnMethodAsync(IMessageBus messageBus,
                                                            Type classUnderTest,
                                                            object[] constructorArguments,
                                                            MethodInfo methodUnderTest,
                                                            List<BeforeAfterTestAttribute> beforeAfterAttributes,
                                                            ExceptionAggregator aggregator,
                                                            CancellationTokenSource cancellationTokenSource)
        {
            var executionTime = 0M;
            var originalCulture = Thread.CurrentThread.CurrentCulture;
            var originalUICulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                var cultureInfo = CultureInfo.GetCultureInfo(culture);
                Thread.CurrentThread.CurrentCulture = cultureInfo;
                Thread.CurrentThread.CurrentUICulture = cultureInfo;

                executionTime =
                    await RunTestWithArgumentsAsync(messageBus,
                                                    classUnderTest,
                                                    constructorArguments,
                                                    methodUnderTest,
                                                    null,
                                                    DisplayName,
                                                    beforeAfterAttributes,
                                                    aggregator,
                                                    cancellationTokenSource);
            }
            catch (Exception ex)
            {
                if (!messageBus.QueueMessage(new Xunit.Sdk.TestStarting(this, DisplayName)))
                    cancellationTokenSource.Cancel();
                else
                {
                    if (!messageBus.QueueMessage(new Xunit.Sdk.TestFailed(this, DisplayName, executionTime, null, ex.Unwrap())))
                        cancellationTokenSource.Cancel();
                }

                if (!messageBus.QueueMessage(new Xunit.Sdk.TestFinished(this, DisplayName, executionTime, null)))
                    cancellationTokenSource.Cancel();
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
                Thread.CurrentThread.CurrentUICulture = originalUICulture;
            }
        }
开发者ID:kerryjiang,项目名称:xunit,代码行数:48,代码来源:CulturedXunitTestCase.cs

示例4: RunTestAsyncCore

        private static async Task<RunSummary> RunTestAsyncCore(XunitTestRunner runner,
                                                               IMessageBus messageBus,
                                                               ExceptionAggregator aggregator,
                                                               bool disableRetry)
        {
            try
            {
                DelayedMessageBus delayedMessageBus = null;
                RunSummary summary = null;

                // First run
                if (!disableRetry)
                {
                    // This is really the only tricky bit: we need to capture and delay messages (since those will
                    // contain run status) until we know we've decided to accept the final result;
                    delayedMessageBus = new DelayedMessageBus(messageBus);

                    runner.SetMessageBus(delayedMessageBus);
                    summary = await RunTestInternalAsync(runner);

                    // if succeeded
                    if (summary.Failed == 0 || aggregator.HasExceptions)
                    {
                        delayedMessageBus.Flush(false);
                        return summary;
                    }
                }

                // Final run
                runner.SetMessageBus(new KuduTraceMessageBus(messageBus));
                summary = await RunTestInternalAsync(runner);

                // flush delay messages
                if (delayedMessageBus != null)
                {
                    delayedMessageBus.Flush(summary.Failed == 0 && !aggregator.HasExceptions);
                }

                return summary;
            }
            catch (Exception ex)
            {
                // this is catastrophic
                messageBus.QueueMessage(new TestFailed(runner.GetTest(), 0, null, ex));

                return new RunSummary { Failed = 1, Total = 1 };
            }
            finally
            {
                // set to original
                runner.SetMessageBus(messageBus);
            }
        }
开发者ID:nikolayvoronchikhin,项目名称:kudu,代码行数:53,代码来源:KuduXunitTestRunnerUtils.cs

示例5: BeforeFinished

        public bool BeforeFinished(IMessageBus messageBus, TestCaseFinished message)
        {
            if (UIThreadHelper.Instance.Invoke(() => ThreadHelper.CheckAccess()))
            {
                return true;
            }

            // Try to restore service provider and original thread.
            // Terminate test execution if not succeeded
            try
            {
                UIThreadHelper.Instance.Invoke(() => ServiceProvider.CreateFromSetSite(_oleServiceProvider));
            }
            catch (Exception ex)
            {
                messageBus.QueueMessage(new TestCaseCleanupFailure(message.TestCase, ex));
                return false;
            }

            InvalidOperationException exception = new InvalidOperationException("Test changes or accesses ServiceProvider.GlobalProvider from non-UI thread. Try annotate it with ThreadType.UI");
            return messageBus.QueueMessage(new TestCaseCleanupFailure(message.TestCase, exception));
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:22,代码来源:VerifyGlobalProviderMessageBusInjection.cs

示例6: DisposeTestClass

    /// <summary>
    /// Disposes the test class instance. Sends the <see cref="ITestClassDisposeStarting"/> and <see cref="ITestClassDisposeFinished"/>
    /// messages as appropriate.
    /// </summary>
    /// <param name="test">The test</param>
    /// <param name="testClass">The test class instance to be disposed</param>
    /// <param name="messageBus">The message bus used to send the test messages</param>
    /// <param name="timer">The timer used to measure the time taken for construction</param>
    /// <param name="cancellationTokenSource">The cancellation token source</param>
    public static void DisposeTestClass(this ITest test,
                                        object testClass,
                                        IMessageBus messageBus,
                                        ExecutionTimer timer,
                                        CancellationTokenSource cancellationTokenSource)
    {
        var disposable = testClass as IDisposable;
        if (disposable == null)
            return;

        if (!messageBus.QueueMessage(new TestClassDisposeStarting(test)))
            cancellationTokenSource.Cancel();

        try
        {
            timer.Aggregate(disposable.Dispose);
        }
        finally
        {
            if (!messageBus.QueueMessage(new TestClassDisposeFinished(test)))
                cancellationTokenSource.Cancel();
        }
    }
开发者ID:Tofudebeast,项目名称:xunit,代码行数:32,代码来源:ReflectionAbstractionExtensions.cs

示例7: BeforeFinished

        public bool BeforeFinished(IMessageBus messageBus, TestFinished message)
        {
            var testMethod = message.TestMethod.Method.ToRuntimeMethod();

            foreach (BeforeCtorAfterDisposeAttribute beforeAfterTestCaseAttribute in _attributesStack)
            {
                try
                {
                    _timer.Aggregate(() => beforeAfterTestCaseAttribute.After(testMethod));
                }
                catch (Exception e)
                {
                    _exceptions.Add(e);
                }
            }

            if (_exceptions.Any())
            {
                return messageBus.QueueMessage(new TestCleanupFailure(message.Test, new AggregateException(_exceptions)));
            }

            return true;
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:23,代码来源:ExecuteBeforeAfterAttributesMessageBusInjection.cs

示例8: ReportDiscoveredTestCase

        /// <summary>
        /// Reports a discovered test case to the message bus, after updating the source code information
        /// (if desired).
        /// </summary>
        /// <param name="testCase"></param>
        /// <param name="includeSourceInformation"></param>
        /// <param name="messageBus"></param>
        /// <returns></returns>
        protected bool ReportDiscoveredTestCase(ITestCase testCase, bool includeSourceInformation, IMessageBus messageBus)
        {
            if (includeSourceInformation && SourceProvider != null)
                testCase.SourceInformation = SourceProvider.GetSourceInformation(testCase);

            return messageBus.QueueMessage(new TestCaseDiscoveryMessage(testCase));
        }
开发者ID:ansarisamer,项目名称:xunit,代码行数:15,代码来源:TestFrameworkDiscoverer.cs

示例9: RunTestClassAsync

        private static async Task RunTestClassAsync(IMessageBus messageBus,
                                                    ITestCollection collection,
                                                    Dictionary<Type, object> collectionFixtureMappings,
                                                    IReflectionTypeInfo testClass,
                                                    IEnumerable<XunitTestCase> testCases,
                                                    ITestCaseOrderer orderer,
                                                    RunSummary classSummary,
                                                    ExceptionAggregator aggregator,
                                                    CancellationTokenSource cancellationTokenSource)
        {
            var testClassType = testClass.Type;
            var fixtureMappings = new Dictionary<Type, object>();
            var constructorArguments = new List<object>();

            var ordererAttribute = testClass.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault();
            if (ordererAttribute != null)
                orderer = GetTestCaseOrderer(ordererAttribute);

            if (testClassType.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollectionFixture<>)))
                aggregator.Add(new TestClassException("A test class may not be decorated with ICollectionFixture<> (decorate the test collection class instead)."));

            foreach (var interfaceType in testClassType.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IClassFixture<>)))
                CreateFixture(interfaceType, aggregator, fixtureMappings);

            if (collection.CollectionDefinition != null)
            {
                var declarationType = ((IReflectionTypeInfo)collection.CollectionDefinition).Type;
                foreach (var interfaceType in declarationType.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IClassFixture<>)))
                    CreateFixture(interfaceType, aggregator, fixtureMappings);
            }

            var isStaticClass = testClassType.IsAbstract && testClassType.IsSealed;
            if (!isStaticClass)
            {
                var ctors = testClassType.GetConstructors();
                if (ctors.Length != 1)
                {
                    aggregator.Add(new TestClassException("A test class may only define a single public constructor."));
                }
                else
                {
                    var ctor = ctors.Single();
                    var unusedArguments = new List<string>();

                    foreach (var paramInfo in ctor.GetParameters())
                    {
                        object fixture;

                        if (fixtureMappings.TryGetValue(paramInfo.ParameterType, out fixture) || collectionFixtureMappings.TryGetValue(paramInfo.ParameterType, out fixture))
                            constructorArguments.Add(fixture);
                        else
                            unusedArguments.Add(String.Format("{0} {1}", paramInfo.ParameterType.Name, paramInfo.Name));
                    }

                    if (unusedArguments.Count > 0)
                        aggregator.Add(new TestClassException("The following constructor arguments did not have matching fixture data: " + String.Join(", ", unusedArguments)));
                }
            }

            var orderedTestCases = orderer.OrderTestCases(testCases);
            var methodGroups = orderedTestCases.GroupBy(tc => tc.Method);

            foreach (var method in methodGroups)
            {
                if (!messageBus.QueueMessage(new TestMethodStarting(collection, testClass.Name, method.Key.Name)))
                    cancellationTokenSource.Cancel();
                else
                    await RunTestMethodAsync(messageBus, constructorArguments.ToArray(), method, classSummary, aggregator, cancellationTokenSource);

                if (!messageBus.QueueMessage(new TestMethodFinished(collection, testClass.Name, method.Key.Name)))
                    cancellationTokenSource.Cancel();

                if (cancellationTokenSource.IsCancellationRequested)
                    break;
            }

            foreach (var fixture in fixtureMappings.Values.OfType<IDisposable>())
            {
                try
                {
                    fixture.Dispose();
                }
                catch (Exception ex)
                {
                    if (!messageBus.QueueMessage(new ErrorMessage(ex.Unwrap())))
                        cancellationTokenSource.Cancel();
                }
            }
        }
开发者ID:valmaev,项目名称:xunit,代码行数:89,代码来源:XunitTestFrameworkExecutor.cs

示例10: FindImpl

        /// <summary>
        /// Core implementation to discover unit tests in a given test class.
        /// </summary>
        /// <param name="type">The test class.</param>
        /// <param name="includeSourceInformation">Set to <c>true</c> to attempt to include source information.</param>
        /// <param name="messageBus">The message sink to send discovery messages to.</param>
        /// <returns>Returns <c>true</c> if discovery should continue; <c>false</c> otherwise.</returns>
        protected virtual bool FindImpl(ITypeInfo type, bool includeSourceInformation, IMessageBus messageBus)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            var testCollection = TestCollectionFactory.Get(type);

            try
            {
                if (!String.IsNullOrEmpty(assemblyInfo.AssemblyPath))
                    Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyInfo.AssemblyPath));

                foreach (var method in type.GetMethods(includePrivateMethods: true))
                {
                    var factAttribute = method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
                    if (factAttribute != null)
                    {
                        var discovererAttribute = factAttribute.GetCustomAttributes(typeof(TestCaseDiscovererAttribute)).FirstOrDefault();
                        if (discovererAttribute != null)
                        {
                            var args = discovererAttribute.GetConstructorArguments().Cast<string>().ToList();
                            var discovererType = Reflector.GetType(args[1], args[0]);
                            if (discovererType != null)
                            {
                                var discoverer = GetDiscoverer(discovererType);

                                if (discoverer != null)
                                    foreach (var testCase in discoverer.Discover(testCollection, assemblyInfo, type, method, factAttribute))
                                        if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(UpdateTestCaseWithSourceInfo(testCase, includeSourceInformation))))
                                            return false;
                            }
                            else
                                messageAggregator.Add(new EnvironmentalWarning { Message = String.Format("Could not create discoverer type '{0}, {1}'", args[0], args[1]) });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                messageAggregator.Add(new EnvironmentalWarning { Message = String.Format("Exception during discovery:{0}{1}", Environment.NewLine, ex) });
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }

            return true;
        }
开发者ID:PKRoma,项目名称:xunit-codeplex,代码行数:53,代码来源:XunitTestFrameworkDiscoverer.cs

示例11: RunAsync

        /// <inheritdoc/>
        public virtual async Task<RunSummary> RunAsync(IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
        {
            var summary = new RunSummary();

            if (!messageBus.QueueMessage(new TestCaseStarting(this)))
                cancellationTokenSource.Cancel();
            else
            {
                using (var delegatingBus = new DelegatingMessageBus(messageBus,
                    msg =>
                    {
                        if (msg is ITestResultMessage)
                        {
                            summary.Total++;
                            summary.Time += ((ITestResultMessage)msg).ExecutionTime;
                        }
                        if (msg is ITestFailed)
                            summary.Failed++;
                        if (msg is ITestSkipped)
                            summary.Skipped++;
                    }))
                {
                    await RunTestsAsync(delegatingBus, constructorArguments, aggregator, cancellationTokenSource);
                }
            }

            if (!messageBus.QueueMessage(new TestCaseFinished(this, summary.Time, summary.Total, summary.Failed, summary.Skipped)))
                cancellationTokenSource.Cancel();

            return summary;
        }
开发者ID:vkomarovsky-sugarcrm,项目名称:xunit,代码行数:32,代码来源:XunitTestCase.cs

示例12: RunTestCollectionAsync

        private async Task<RunSummary> RunTestCollectionAsync(IMessageBus messageBus,
                                                              ITestCollection collection,
                                                              IEnumerable<XunitTestCase> testCases,
                                                              ITestCaseOrderer orderer,
                                                              CancellationTokenSource cancellationTokenSource)
        {
            var collectionSummary = new RunSummary();
            var collectionFixtureMappings = new Dictionary<Type, object>();
            var aggregator = new ExceptionAggregator();

            if (collection.CollectionDefinition != null)
            {
                var declarationType = ((IReflectionTypeInfo)collection.CollectionDefinition).Type;
                foreach (var interfaceType in declarationType.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollectionFixture<>)))
                    CreateFixture(interfaceType, aggregator, collectionFixtureMappings);

                var ordererAttribute = collection.CollectionDefinition.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault();
                if (ordererAttribute != null)
                    orderer = GetTestCaseOrderer(ordererAttribute);
            }

            if (messageBus.QueueMessage(new TestCollectionStarting(collection)))
            {
                foreach (var testCasesByClass in testCases.GroupBy(tc => tc.Class))
                {
                    var classSummary = new RunSummary();

                    if (!messageBus.QueueMessage(new TestClassStarting(collection, testCasesByClass.Key.Name)))
                        cancellationTokenSource.Cancel();
                    else
                    {
                        await RunTestClassAsync(messageBus, collection, collectionFixtureMappings, (IReflectionTypeInfo)testCasesByClass.Key, testCasesByClass, orderer, classSummary, aggregator, cancellationTokenSource);
                        collectionSummary.Aggregate(classSummary);
                    }

                    if (!messageBus.QueueMessage(new TestClassFinished(collection, testCasesByClass.Key.Name, classSummary.Time, classSummary.Total, classSummary.Failed, classSummary.Skipped)))
                        cancellationTokenSource.Cancel();

                    if (cancellationTokenSource.IsCancellationRequested)
                        break;
                }
            }

            foreach (var fixture in collectionFixtureMappings.Values.OfType<IDisposable>())
            {
                try
                {
                    fixture.Dispose();
                }
                catch (Exception ex)
                {
                    if (!messageBus.QueueMessage(new ErrorMessage(ex.Unwrap())))
                        cancellationTokenSource.Cancel();
                }
            }

            messageBus.QueueMessage(new TestCollectionFinished(collection, collectionSummary.Time, collectionSummary.Total, collectionSummary.Failed, collectionSummary.Skipped));
            return collectionSummary;
        }
开发者ID:valmaev,项目名称:xunit,代码行数:59,代码来源:XunitTestFrameworkExecutor.cs

示例13: RunAsync

		public async Task<RunSummary> RunAsync (VsixTestCase testCase, IMessageBus messageBus, ExceptionAggregator aggregator, object[] constructorArguments)
		{
			if (Process == null) {
				if (!Start ()) {
					Stop ();
					if (!Start ()) {
						Stop ();

						messageBus.QueueMessage (new TestFailed (new XunitTest (testCase, testCase.DisplayName), 0,
							string.Format ("Failed to start Visual Studio {0}{1}.", visualStudioVersion, rootSuffix),
							new TimeoutException ()));

						return new RunSummary {
							Failed = 1,
						};
					}
				}
			}

			if (runner == null) {
				var hostUrl = RemotingUtil.GetHostUri (pipeName);
				var clientPipeName = Guid.NewGuid ().ToString ("N");

				clientChannel = RemotingUtil.CreateChannel (Constants.ClientChannelName + clientPipeName, clientPipeName);

				try {
					runner = (IVsRemoteRunner)RemotingServices.Connect (typeof (IVsRemoteRunner), hostUrl);
					// We don't require restart anymore since we write to the registry directly the binding paths,
					// rather than installing a VSIX
					//if (runner.ShouldRestart ()) {
					//    Stop ();
					//    return await RunAsync (testCase, messageBus, aggregator, constructorArguments);
					//}

					if (Debugger.IsAttached) {
						// Add default trace listeners to the remote process.
						foreach (var listener in Trace.Listeners.OfType<TraceListener> ()) {
							runner.AddListener (listener);
						}
					}

				} catch (Exception ex) {
					messageBus.QueueMessage (new TestFailed (new XunitTest (testCase, testCase.DisplayName), 0, ex.Message, ex));
					return new RunSummary {
						Failed = 1
					};
				}
			}

			var xunitTest = new XunitTest (testCase, testCase.DisplayName);

			try {
				var outputHelper = constructorArguments.OfType<TestOutputHelper> ().FirstOrDefault ();
				if (outputHelper != null)
					outputHelper.Initialize (messageBus, xunitTest);

				// Special case for test output, since it's not MBR.
				var args = constructorArguments.Select (arg => {
					var helper = arg as ITestOutputHelper;
					if (helper != null) {
						var remoteHeper = new RemoteTestOutputHelper (helper);
						remoteObjects.Add (remoteHeper);
						return remoteHeper;
					}

					return arg;
				}).ToArray ();

				var remoteBus = new RemoteMessageBus (messageBus);
				remoteObjects.Add (remoteBus);

				var summary = await System.Threading.Tasks.Task.Run (
					() => runner.Run (testCase, remoteBus, args))
					.TimeoutAfter (testCase.TimeoutSeconds * 1000);

				// Dump output only if a debugger is attached, meaning that most likely
				// there is a single test being run/debugged.
				if (Debugger.IsAttached && outputHelper != null && !string.IsNullOrEmpty (outputHelper.Output)) {
					Trace.WriteLine (outputHelper.Output);
					Debugger.Log (0, "", outputHelper.Output);
					Console.WriteLine (outputHelper.Output);
				}

				if (summary.Exception != null)
					aggregator.Add (summary.Exception);

				return summary.ToRunSummary ();
			} catch (Exception ex) {
				aggregator.Add (ex);
				messageBus.QueueMessage (new TestFailed (xunitTest, 0, ex.Message, ex));
				return new RunSummary {
					Failed = 1
				};
			} finally {
				var outputHelper = constructorArguments.OfType<TestOutputHelper> ().FirstOrDefault ();
				if (outputHelper != null)
					outputHelper.Uninitialize ();
			}
		}
开发者ID:victorgarciaaprea,项目名称:xunit.vsix,代码行数:99,代码来源:VsClient.cs

示例14: RunTestWithArgumentsAsync

        /// <summary>
        /// Runs a single test for a given test method.
        /// </summary>
        /// <param name="messageBus">The message bus to send results to.</param>
        /// <param name="classUnderTest">The class under test.</param>
        /// <param name="constructorArguments">The arguments to pass to the constructor.</param>
        /// <param name="methodUnderTest">The method under test.</param>
        /// <param name="testMethodArguments">The arguments to pass to the test method.</param>
        /// <param name="displayName">The display name for the test.</param>
        /// <param name="beforeAfterAttributes">The <see cref="BeforeAfterTestAttribute"/> instances attached to the test.</param>
        /// <param name="parentAggregator">The parent aggregator that contains the exceptions up to this point.</param>
        /// <param name="cancellationTokenSource">The cancellation token source that indicates whether cancellation has been requested.</param>
        protected async Task<decimal> RunTestWithArgumentsAsync(IMessageBus messageBus,
                                                                Type classUnderTest,
                                                                object[] constructorArguments,
                                                                MethodInfo methodUnderTest,
                                                                object[] testMethodArguments,
                                                                string displayName,
                                                                List<BeforeAfterTestAttribute> beforeAfterAttributes,
                                                                ExceptionAggregator parentAggregator,
                                                                CancellationTokenSource cancellationTokenSource)
        {
            var executionTime = 0M;
            var aggregator = new ExceptionAggregator(parentAggregator);
            var output = String.Empty;  // TODO: Add output facilities for v2

            if (!messageBus.QueueMessage(new TestStarting(this, displayName)))
                cancellationTokenSource.Cancel();
            else
            {
                if (!String.IsNullOrEmpty(SkipReason))
                {
                    if (!messageBus.QueueMessage(new TestSkipped(this, displayName, SkipReason)))
                        cancellationTokenSource.Cancel();
                }
                else
                {
                    var beforeAttributesRun = new Stack<BeforeAfterTestAttribute>();
                    var stopwatch = Stopwatch.StartNew();

                    if (!aggregator.HasExceptions)
                        await aggregator.RunAsync(async () =>
                        {
                            object testClass = null;

                            if (!methodUnderTest.IsStatic)
                            {
                                if (!messageBus.QueueMessage(new TestClassConstructionStarting(this, displayName)))
                                    cancellationTokenSource.Cancel();

                                try
                                {
                                    if (!cancellationTokenSource.IsCancellationRequested)
                                        testClass = Activator.CreateInstance(classUnderTest, constructorArguments);
                                }
                                finally
                                {
                                    if (!messageBus.QueueMessage(new TestClassConstructionFinished(this, displayName)))
                                        cancellationTokenSource.Cancel();
                                }
                            }

                            if (!cancellationTokenSource.IsCancellationRequested)
                            {
                                await aggregator.RunAsync(async () =>
                                {
                                    foreach (var beforeAfterAttribute in beforeAfterAttributes)
                                    {
                                        var attributeName = beforeAfterAttribute.GetType().Name;
                                        if (!messageBus.QueueMessage(new BeforeTestStarting(this, displayName, attributeName)))
                                            cancellationTokenSource.Cancel();
                                        else
                                        {
                                            try
                                            {
                                                beforeAfterAttribute.Before(methodUnderTest);
                                                beforeAttributesRun.Push(beforeAfterAttribute);
                                            }
                                            finally
                                            {
                                                if (!messageBus.QueueMessage(new BeforeTestFinished(this, displayName, attributeName)))
                                                    cancellationTokenSource.Cancel();
                                            }
                                        }

                                        if (cancellationTokenSource.IsCancellationRequested)
                                            return;
                                    }

                                    if (!cancellationTokenSource.IsCancellationRequested)
                                    {
                                        var parameterTypes = methodUnderTest.GetParameters().Select(p => p.ParameterType).ToArray();
                                        var oldSyncContext = SynchronizationContext.Current;

                                        try
                                        {
                                            var asyncSyncContext = new AsyncTestSyncContext();
                                            SetSynchronizationContext(asyncSyncContext);

                                            await aggregator.RunAsync(async () =>
//.........这里部分代码省略.........
开发者ID:valmaev,项目名称:xunit,代码行数:101,代码来源:XunitTestCase.cs

示例15: RunSummary

 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
 public override async Task<RunSummary> RunAsync
 #pragma warning restore CS1998
   ( IMessageSink diagnosticMessageSink
   , IMessageBus bus
   , object[] constructorArguments
   , ExceptionAggregator aggregator
   , CancellationTokenSource cancellationTokenSource
   )
 {   var summary = new RunSummary();
     var test = new XunitTest(this, DisplayName);
     if (Inv == null)
     {   var msg = "Return Type must be Invariant.";
         bus.QueueMessage
           ( new TestFailed(test, 0, null, new Exception(msg))
           );
         summary.Aggregate(new RunSummary { Total = 1, Failed = 1 });
         return summary;
     }
     var output = new TestOutputHelper();
     var timer = new ExecutionTimer();
     output.Initialize(bus, test);
     bus.QueueMessage(new TestStarting(test));
     InvariantResult result;
     timer.Aggregate(() => result = Inv.Results(Config(output)).First());
     var xresult = ToXunitResult(test, result, timer.Total);
     bus.QueueMessage(xresult.Item1);
     summary.Aggregate(xresult.Item2);
     return summary;
 }
开发者ID:sharper-library,项目名称:Sharper.C.Testing,代码行数:30,代码来源:InvariantTestCase.cs


注:本文中的IMessageBus.QueueMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。