/// <summary> /// Creates a copy of the test package. /// </summary> /// <returns>The new copy.</returns> public TestPackage Copy() { TestPackage copy = new TestPackage() { testFrameworkOptions = testFrameworkOptions != null?testFrameworkOptions.Copy() : null, isTestFrameworkOptionsSpecified = isTestFrameworkOptionsSpecified, testFrameworkFallbackMode = testFrameworkFallbackMode, isTestFrameworkFallbackModeSpecified = isTestFrameworkFallbackModeSpecified, applicationBaseDirectory = applicationBaseDirectory, isApplicationBaseDirectorySpecified = isApplicationBaseDirectorySpecified, debuggerSetup = debuggerSetup != null?debuggerSetup.Copy() : null, isDebuggerSetupSpecified = isDebuggerSetupSpecified, runtimeVersion = runtimeVersion, isRuntimeVersionSpecified = isRuntimeVersionSpecified, shadowCopy = shadowCopy, isShadowCopySpecified = isShadowCopySpecified, workingDirectory = workingDirectory, isWorkingDirectorySpecified = isWorkingDirectorySpecified }; copy.excludedTestFrameworkIds.AddRange(excludedTestFrameworkIds); copy.files.AddRange(files); copy.hintDirectories.AddRange(hintDirectories); copy.properties.AddAll(properties); return(copy); }
private TestFrameworkSelection GetFallbackSelection( Dictionary <object, TestFrameworkSelection> selections, IList <AssemblyName> assemblyReferences, IEnumerable <ComponentHandle <ITestFramework, TestFrameworkTraits> > filteredTestFrameworkHandlesWithoutFallback, TestFrameworkOptions testFrameworkOptions, TestFrameworkFallbackMode testFrameworkFallbackMode) { // Strict fallback mode. if (testFrameworkFallbackMode == TestFrameworkFallbackMode.Strict) { return(null); } // Approximate fallback mode. if (assemblyReferences != null) { HashSet <string> matchingReferences = null; HashSet <string> matchingSignatures = null; foreach (var testFrameworkHandle in filteredTestFrameworkHandlesWithoutFallback) { IList <AssemblySignature> assemblySignatures = testFrameworkHandle.GetTraits().FrameworkAssemblies; foreach (AssemblyName assemblyName in assemblyReferences) { foreach (AssemblySignature assemblySignature in assemblySignatures) { if (assemblySignature.Name == assemblyName.Name) { if (matchingReferences == null) { matchingReferences = new HashSet <string>(); matchingSignatures = new HashSet <string>(); } matchingReferences.Add(assemblyName.FullName); matchingSignatures.Add(assemblySignature.ToString()); } } } } if (matchingReferences != null) { StringBuilder fallbackExplanationBuilder = new StringBuilder(); fallbackExplanationBuilder.Append("Detected a probable test framework assembly version mismatch.\n"); fallbackExplanationBuilder.Append("Referenced test frameworks: "); AppendQuotedItems(fallbackExplanationBuilder, matchingReferences); fallbackExplanationBuilder.Append(".\n"); fallbackExplanationBuilder.Append("Supported test frameworks: "); AppendQuotedItems(fallbackExplanationBuilder, matchingSignatures); fallbackExplanationBuilder.Append("."); string fallbackExplanation = fallbackExplanationBuilder.ToString(); return(GetOrCreateSelectionIfAbsent(selections, fallbackExplanation, () => { TestFrameworkOptions fallbackTestFrameworkOptions = testFrameworkOptions.Copy(); fallbackTestFrameworkOptions.AddProperty(FallbackTestFramework.FallbackExplanationKey, fallbackExplanation); return new TestFrameworkSelection(fallbackTestFrameworkHandle, fallbackTestFrameworkOptions, true); })); } } if (testFrameworkFallbackMode == TestFrameworkFallbackMode.Approximate) { return(null); } // Default fallback mode. return(GetOrCreateSelectionIfAbsent(selections, DefaultFallbackSelectionKey, () => new TestFrameworkSelection(fallbackTestFrameworkHandle, testFrameworkOptions, true))); }