コード例 #1
0
        internal static IEnumerable <Instance> GetInstances(IEnumerable <VsInstallation> installations, ITestMethod testMethod, VsTestSettings testSettings, ConcurrentDictionary <string, Instance> instances)
        {
            var output = new StringBuilder();

            installations = FilterInstallations(installations, testSettings, output, ParentVsProcess.Value.GetMainModuleFileName());

            if (!installations.Any())
            {
                throw new InvalidOperationException("Cannot find a viable Visual Studio Instance for the specified test case.\r\n" + output);
            }

            foreach (var installation in installations)
            {
                var instanceId = $"{VersionUtil.GetYear(installation.Version)} {testSettings.RootSuffix}";
                if (!testSettings.ReuseInstance)
                {
                    var fullMethodName = testMethod.TestClass.Class.ToRuntimeType() + testMethod.Method.Name;
                    instanceId += string.Format(" {0:X}", fullMethodName.GetHashCode()).ToLower();
                }

                yield return(instances.GetOrAdd(instanceId, id => new Instance(id, installation.ApplicationPath, testMethod.TestClass.TestCollection.TestAssembly)));
            }
        }
コード例 #2
0
        internal static IEnumerable <VsInstallation> FilterInstallations(IEnumerable <VsInstallation> installations, VsTestSettings settings, StringBuilder output = null, string preferedAppPath = null)
        {
            foreach (var group in installations.GroupBy(i => i.Version.Major).OrderBy(g => g.Key))
            {
                foreach (var installation in group
                         .OrderBy(i => !i.ApplicationPath.Equals(preferedAppPath, StringComparison.OrdinalIgnoreCase))
                         .ThenBy(i => i.Name.Contains("-pre")))
                {
                    if (!settings.SupportedVersionRanges.Any(range => installation.Version >= range.Minimum && installation.Version <= range.Maximum))
                    {
                        output?.AppendLine($"Skipping {installation.Path} because the version {installation.Version} is not within any specified version range {string.Join(";", settings.SupportedVersionRanges)}.");
                        continue;
                    }

                    yield return(installation);

                    break;
                }
            }
        }