/// <inheritdoc/> public void FindAndRun( _IMessageSink messageSink, FrontControllerFindAndRunSettings settings) { Guard.NotNull($"This instance of {typeof(Xunit2).FullName} was created for discovery only; execution-related operations cannot be performed.", remoteExecutor); Guard.ArgumentNotNull(messageSink); Guard.ArgumentNotNull(settings); if (settings.Filters.Empty) { remoteExecutor.RunAll( CreateOptimizedRemoteMessageSink(messageSink), Xunit2OptionsAdapter.Adapt(settings.DiscoveryOptions), Xunit2OptionsAdapter.Adapt(settings.ExecutionOptions) ); return; } using var discoverySink = new Xunit2DiscoverySink(settings.Filters); remoteDiscoverer.Find( includeSourceInformation: false, discoverySink, Xunit2OptionsAdapter.Adapt(settings.DiscoveryOptions) ); discoverySink.Finished.WaitOne(); remoteExecutor.RunTests( discoverySink.TestCases, CreateOptimizedRemoteMessageSink(messageSink), Xunit2OptionsAdapter.Adapt(settings.ExecutionOptions) ); }
// Factory methods /// <summary> /// Returns an implementation of <see cref="IFrontController"/> which can be used /// for both discovery and execution of xUnit.net v1 tests. /// </summary> /// <param name="projectAssembly">The test project assembly.</param> /// <param name="sourceInformationProvider">The optional source information provider.</param> /// <param name="diagnosticMessageSink">The optional message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> public static IFrontController ForDiscoveryAndExecution( XunitProjectAssembly projectAssembly, _ISourceInformationProvider?sourceInformationProvider = null, _IMessageSink?diagnosticMessageSink = null) { Guard.ArgumentNotNull(nameof(projectAssembly), projectAssembly); var assemblyFileName = projectAssembly.AssemblyFilename; Guard.ArgumentNotNull($"{nameof(projectAssembly)}.{nameof(XunitProjectAssembly.AssemblyFilename)}", assemblyFileName); if (diagnosticMessageSink == null) { diagnosticMessageSink = new _NullMessageSink(); } return(new Xunit1( diagnosticMessageSink, projectAssembly.Configuration.AppDomainOrDefault, #if NETSTANDARD sourceInformationProvider ?? _NullSourceInformationProvider.Instance, #else sourceInformationProvider ?? new VisualStudioSourceInformationProvider(assemblyFileName, diagnosticMessageSink), #endif assemblyFileName, projectAssembly.ConfigFilename, projectAssembly.Configuration.ShadowCopyOrDefault, projectAssembly.Configuration.ShadowCopyFolder )); }
public DelegatingExecutionSummarySinkTests() { innerSink = Substitute.For <_IMessageSink>(); innerSink.OnMessage(null !).ReturnsForAnyArgs(true); testMessage = new _MessageSinkMessage(); }
/// <summary> /// Initializes a new instance of the <see cref="DelegatingMessageSink"/> class. /// </summary> /// <param name="innerSink">The inner message sink.</param> /// <param name="callback">The callback.</param> public DelegatingMessageSink( _IMessageSink innerSink, Action <_MessageSinkMessage>?callback = null) { this.innerSink = Guard.ArgumentNotNull(innerSink); this.callback = callback; }
public AppDomainManager_AppDomain( string assemblyFileName, string?configFileName, bool shadowCopy, string?shadowCopyFolder, _IMessageSink diagnosticMessageSink) { Guard.ArgumentNotNullOrEmpty(assemblyFileName); assemblyFileName = Path.GetFullPath(assemblyFileName); Guard.FileExists(assemblyFileName); if (configFileName == null) { configFileName = GetDefaultConfigFile(assemblyFileName); } if (configFileName != null) { configFileName = Path.GetFullPath(configFileName); } AssemblyFileName = assemblyFileName; ConfigFileName = configFileName; this.diagnosticMessageSink = diagnosticMessageSink; AppDomain = CreateAppDomain(assemblyFileName, configFileName, shadowCopy, shadowCopyFolder); }
public ClassFixtureWithMessageSinkDependency(_IMessageSink messageSink) { MessageSink = messageSink; MessageSink.OnMessage(new _DiagnosticMessage { Message = "ClassFixtureWithMessageSinkDependency constructor message" }); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFramework"/> class. /// </summary> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> /// <param name="configFileName">The test configuration file.</param> public XunitTestFramework( _IMessageSink diagnosticMessageSink, string?configFileName) : base(diagnosticMessageSink) { this.configFileName = configFileName; }
/// <summary> /// INTERNAL METHOD, FOR TESTING PURPOSES ONLY. DO NOT CALL. /// </summary> protected void FindAndRun( _IMessageSink messageSink, bool includeSourceInformation, Predicate <_TestCaseDiscovered>?filter) { Guard.ArgumentNotNull(nameof(messageSink), messageSink); var testCases = new List <Xunit1TestCase>(); Find(includeSourceInformation, testCase => { var include = true; if (filter != null) { var msg = testCase.ToTestCaseDiscovered(includeSerialization: false); include = filter(msg); } if (include) { testCases.Add(testCase); } }); Run(testCases, messageSink); }
public FilteringMessageSink( _IMessageSink innerMessageSink, Predicate <_TestCaseDiscovered> filter) { this.innerMessageSink = innerMessageSink; this.filter = filter; }
/// <summary> /// Initializes a new instance of the <see cref="VisualStudioSourceInformationProvider" /> class. /// </summary> /// <param name="assemblyFileName">The assembly file name.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> public VisualStudioSourceInformationProvider( string assemblyFileName, _IMessageSink diagnosticMessageSink) { Guard.ArgumentNotNullOrEmpty(assemblyFileName); session = new DiaSessionWrapper(assemblyFileName, diagnosticMessageSink); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestAssemblyRunnerContext"/> class. /// </summary> public XunitTestAssemblyRunnerContext( _ITestAssembly testAssembly, IReadOnlyCollection <IXunitTestCase> testCases, _IMessageSink executionMessageSink, _ITestFrameworkExecutionOptions executionOptions) : base(testAssembly, testCases, executionMessageSink, executionOptions) { }
/// <summary> /// Gets the test collection definitions for the given assembly. /// </summary> /// <param name="assemblyInfo">The assembly.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> /// <returns>A list of mappings from test collection name to test collection definitions (as <see cref="_ITypeInfo"/></returns> public static Dictionary <string, _ITypeInfo> GetTestCollectionDefinitions( _IAssemblyInfo assemblyInfo, _IMessageSink diagnosticMessageSink) { var attributeTypesByName = assemblyInfo .GetTypes(false) .Select(type => new { Type = type, Attribute = type.GetCustomAttributes(typeof(CollectionDefinitionAttribute).AssemblyQualifiedName !).FirstOrDefault() })
TestableXunitDelayEnumeratedTheoryTestCaseRunner( IXunitTestCase testCase, string displayName, _IMessageSink diagnosticMessageSink, IMessageBus messageBus) : base(testCase, displayName, null, new object[0], diagnosticMessageSink, messageBus, new ExceptionAggregator(), new CancellationTokenSource()) { }
/// <inheritdoc/> public virtual void Find( _IMessageSink messageSink, FrontControllerFindSettings settings) { Guard.ArgumentNotNull(messageSink); Guard.ArgumentNotNull(settings); innerDiscoverer.Find(messageSink, settings); }
/// <summary> /// Initializes a new instance of the <see cref="Xunit2MessageSink"/> class. /// </summary> /// <param name="v3MessageSink">The v3 message sink to which to report the messages</param> /// <param name="assemblyUniqueID">The unique ID of the assembly these message belong to</param> /// <param name="discoverer">The discoverer used to serialize test cases</param> public Xunit2MessageSink( _IMessageSink v3MessageSink, string?assemblyUniqueID = null, ITestFrameworkDiscoverer?discoverer = null) { this.v3MessageSink = Guard.ArgumentNotNull(nameof(v3MessageSink), v3MessageSink); adapter = new Xunit2MessageAdapter(assemblyUniqueID, discoverer); }
/// <summary> /// Initializes a new instance of the <see cref="TestFrameworkExecutor{TTestCase}"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceInformationProvider">The source line number information provider.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> protected TestFrameworkExecutor( _IReflectionAssemblyInfo assemblyInfo, _ISourceInformationProvider sourceInformationProvider, _IMessageSink diagnosticMessageSink) { this.assemblyInfo = Guard.ArgumentNotNull(nameof(assemblyInfo), assemblyInfo); this.sourceInformationProvider = Guard.ArgumentNotNull(nameof(sourceInformationProvider), sourceInformationProvider); this.diagnosticMessageSink = Guard.ArgumentNotNull(nameof(diagnosticMessageSink), diagnosticMessageSink); }
/// <inheritdoc/> public void Run( _IMessageSink messageSink, FrontControllerRunSettings settings) { Guard.ArgumentNotNull(nameof(messageSink), messageSink); Guard.ArgumentNotNull(nameof(settings), settings); Run(settings.SerializedTestCases.Select(tc => Deserialize(tc)).WhereNotNull(), messageSink); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestAssemblyRunner"/> class. /// </summary> /// <param name="testAssembly">The assembly that contains the tests to be run.</param> /// <param name="testCases">The test cases to be run.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> /// <param name="executionMessageSink">The message sink to report run status to.</param> /// <param name="executionOptions">The user's requested execution options.</param> public XunitTestAssemblyRunner( _ITestAssembly testAssembly, IEnumerable <IXunitTestCase> testCases, _IMessageSink diagnosticMessageSink, _IMessageSink executionMessageSink, _ITestFrameworkExecutionOptions executionOptions) : base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="ExecutionErrorTestCase"/> class. /// </summary> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> /// <param name="defaultMethodDisplay">Default method display to use (when not customized).</param> /// <param name="defaultMethodDisplayOptions">Default method display options to use (when not customized).</param> /// <param name="testMethod">The test method.</param> /// <param name="errorMessage">The error message to report for the test.</param> public ExecutionErrorTestCase( _IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, _ITestMethod testMethod, string errorMessage) : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod) { this.errorMessage = Guard.ArgumentNotNull(nameof(errorMessage), errorMessage); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkExecutor"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="configFileName">The test configuration file.</param> /// <param name="sourceInformationProvider">The source line number information provider.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> public XunitTestFrameworkExecutor( _IReflectionAssemblyInfo assemblyInfo, string?configFileName, _ISourceInformationProvider sourceInformationProvider, _IMessageSink diagnosticMessageSink) : base(assemblyInfo, sourceInformationProvider, diagnosticMessageSink) { testAssembly = new TestAssembly(AssemblyInfo, configFileName, assemblyInfo.Assembly.GetName().Version); discoverer = new Lazy <XunitTestFrameworkDiscoverer>(() => new XunitTestFrameworkDiscoverer(AssemblyInfo, configFileName, SourceInformationProvider, DiagnosticMessageSink)); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionPerClassTestCollectionFactory" /> class. /// </summary> /// <param name="testAssembly">The assembly info.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> public CollectionPerClassTestCollectionFactory( _ITestAssembly testAssembly, _IMessageSink diagnosticMessageSink) { Guard.ArgumentNotNull(nameof(diagnosticMessageSink), diagnosticMessageSink); this.testAssembly = Guard.ArgumentNotNull(nameof(testAssembly), testAssembly); collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(testAssembly.Assembly, diagnosticMessageSink); }
/// <summary/> public MessageBus( _IMessageSink messageSink, bool stopOnFail = false) { this.messageSink = messageSink; this.stopOnFail = stopOnFail; reporterThread = new Thread(ReporterWorker); reporterThread.Start(); }
TestableXunitTestAssemblyRunner( _ITestAssembly testAssembly, IEnumerable <IXunitTestCase> testCases, List <_MessageSinkMessage> diagnosticMessages, _IMessageSink executionMessageSink, _ITestFrameworkExecutionOptions executionOptions) : base(testAssembly, testCases, SpyMessageSink.Create(messages: diagnosticMessages), executionMessageSink, executionOptions) { DiagnosticMessages = diagnosticMessages; }
/// <summary> /// INTERNAL METHOD, FOR TESTING PURPOSES ONLY. DO NOT CALL. /// </summary> protected void Run( IEnumerable <Xunit1TestCase> testCases, _IMessageSink messageSink) { var results = new Xunit1RunSummary(); var environment = $"{IntPtr.Size * 8}-bit .NET {Environment.Version}"; var testCasesList = testCases.ToList(); var testAssemblyStartingMessage = new _TestAssemblyStarting { AssemblyName = testAssemblyName, AssemblyPath = assemblyFileName, AssemblyUniqueID = TestAssemblyUniqueID, ConfigFilePath = configFileName, StartTime = DateTimeOffset.Now, TestEnvironment = environment, TestFrameworkDisplayName = TestFrameworkDisplayName, }; if (messageSink.OnMessage(testAssemblyStartingMessage)) { try { if (testCasesList.Count != 0) { results = RunTestCollection(testCasesList, messageSink); } } catch (Exception ex) { var errorMetadata = Xunit1ExceptionUtility.ConvertToErrorMetadata(ex); var errorMessage = new _ErrorMessage { ExceptionParentIndices = errorMetadata.ExceptionParentIndices, ExceptionTypes = errorMetadata.ExceptionTypes, Messages = errorMetadata.Messages, StackTraces = errorMetadata.StackTraces }; messageSink.OnMessage(errorMessage); } finally { var assemblyFinished = new _TestAssemblyFinished { AssemblyUniqueID = testAssemblyStartingMessage.AssemblyUniqueID, ExecutionTime = results.Time, TestsFailed = results.Failed, TestsRun = results.Total, TestsSkipped = results.Skipped }; messageSink.OnMessage(assemblyFinished); } } }
public DiaSessionWrapper( string assemblyFilename, _IMessageSink diagnosticMessageSink) { session = new DiaSession(assemblyFilename); var assemblyFileName = typeof(DiaSessionWrapperHelper).Assembly.GetLocalCodeBase(); appDomainManager = new AppDomainManager_AppDomain(assemblyFileName, null, true, null, diagnosticMessageSink); helper = appDomainManager.CreateObject <DiaSessionWrapperHelper>(typeof(DiaSessionWrapperHelper).Assembly.GetName(), typeof(DiaSessionWrapperHelper).FullName, assemblyFilename); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionPerAssemblyTestCollectionFactory" /> class. /// </summary> /// <param name="testAssembly">The assembly.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> public CollectionPerAssemblyTestCollectionFactory( _ITestAssembly testAssembly, _IMessageSink diagnosticMessageSink) { Guard.ArgumentNotNull(nameof(diagnosticMessageSink), diagnosticMessageSink); this.testAssembly = Guard.ArgumentNotNull(nameof(testAssembly), testAssembly); defaultCollection = new TestCollection(testAssembly, null, "Test collection for " + Path.GetFileName(testAssembly.Assembly.AssemblyPath)); collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(testAssembly.Assembly, diagnosticMessageSink); }
/// <inheritdoc/> public void Run( _IMessageSink messageSink, FrontControllerRunSettings settings) { Guard.NotNull($"This instance of {typeof(XunitFrontController).FullName} is for discovery only", innerController); Guard.ArgumentNotNull(messageSink); Guard.ArgumentNotNull(settings); innerController.Run(messageSink, settings); }
/// <summary> /// Initializes a new instance of the <see cref="DelegatingExecutionSummarySink"/> class. /// </summary> /// <param name="innerSink">The inner sink to pass messages to.</param> /// <param name="cancelThunk">The optional callback used to determine if execution should be canceled</param> /// <param name="completionCallback">The optional callback called when assembly execution is complete</param> public DelegatingExecutionSummarySink( _IMessageSink innerSink, Func <bool>?cancelThunk = null, DelegatingExecutionSummarySinkCallback?completionCallback = null) { Guard.ArgumentNotNull(nameof(innerSink), innerSink); this.innerSink = innerSink; this.cancelThunk = cancelThunk ?? (() => false); this.completionCallback = completionCallback; }
TestableXunitTestAssemblyRunner( _ITestAssembly testAssembly, IReadOnlyCollection <IXunitTestCase> testCases, _IMessageSink executionMessageSink, _ITestFrameworkExecutionOptions executionOptions) { this.testAssembly = testAssembly; this.testCases = testCases; this.executionMessageSink = executionMessageSink; this.executionOptions = executionOptions; }
/// <summary> /// Initializes a new instance of the <see cref="TestAssemblyRunnerContext{TTestCase}"/> class. /// </summary> public TestAssemblyRunnerContext( _ITestAssembly testAssembly, IReadOnlyCollection <TTestCase> testCases, _IMessageSink executionMessageSink, _ITestFrameworkExecutionOptions executionOptions) { TestAssembly = Guard.ArgumentNotNull(testAssembly); TestCases = Guard.ArgumentNotNull(testCases); ExecutionMessageSink = Guard.ArgumentNotNull(executionMessageSink); ExecutionOptions = Guard.ArgumentNotNull(executionOptions); }