// Factory methods /// <summary> /// Returns an implementation of <see cref="IFrontControllerDiscoverer"/> which can be /// used to discovery tests, including source-based discovery (note that xUnit.net v1 /// does not support source-based discovery). /// </summary> /// <param name="assemblyInfo">The assembly to use for discovery</param> /// <param name="projectAssembly">The test project assembly.</param> /// <param name="referenceList">The full path names of all referenced assemblies. This is used to /// search for references to specific xUnit.net reference assemblies to determine which version /// of xUnit.net the tests were written against.</param> /// <param name="sourceInformationProvider">The optional source information provider.</param> /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param> /// <returns></returns> public static IFrontControllerDiscoverer ForDiscovery( _IAssemblyInfo assemblyInfo, XunitProjectAssembly projectAssembly, IReadOnlyCollection <string> referenceList, _ISourceInformationProvider?sourceInformationProvider = null, _IMessageSink?diagnosticMessageSink = null) { Guard.ArgumentNotNull(assemblyInfo); Guard.ArgumentNotNull(projectAssembly); Guard.ArgumentNotNull(referenceList); var innerDiscoverer = default(IFrontControllerDiscoverer); var assemblyFileName = projectAssembly.AssemblyFileName; if (diagnosticMessageSink == null) { diagnosticMessageSink = _NullMessageSink.Instance; } if (sourceInformationProvider == null) { sourceInformationProvider = _NullSourceInformationProvider.Instance; #if NETFRAMEWORK if (assemblyFileName != null) { sourceInformationProvider = new VisualStudioSourceInformationProvider(assemblyFileName, diagnosticMessageSink); } #endif } var v2PathPattern = new Regex(@"^xunit\.execution\..*\.dll$"); var v2ExecutionReference = referenceList.FirstOrDefault(reference => v2PathPattern.IsMatch(Path.GetFileNameWithoutExtension(reference))); if (v2ExecutionReference != null) { innerDiscoverer = Xunit2.ForDiscovery(assemblyInfo, projectAssembly, v2ExecutionReference, sourceInformationProvider, diagnosticMessageSink); } #if NETFRAMEWORK if (referenceList.Any(reference => Path.GetFileNameWithoutExtension(reference) == "xunit.dll")) { innerDiscoverer = Xunit1.ForDiscoveryAndExecution(projectAssembly, sourceInformationProvider, diagnosticMessageSink); } #endif if (innerDiscoverer == null) { throw new InvalidOperationException($"Unknown test framework: could not find xunit.dll (v1) or xunit.execution.*.dll (v2) in assembly reference list"); } return(new XunitFrontController(innerDiscoverer)); }
// Discovery controller XunitFrontController(IFrontControllerDiscoverer innerDiscoverer) { this.innerDiscoverer = Guard.ArgumentNotNull(innerDiscoverer); }