public IEnumerable<IXunitTestCase> Discover (ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
		{
			var defaultMethodDisplay = discoveryOptions.MethodDisplayOrDefault ();
			if (testMethod.Method.GetParameters ().Any ()) {
				return new IXunitTestCase[] {
					new ExecutionErrorTestCase (messageSink, defaultMethodDisplay, testMethod,  "[VsixFact] methods are not allowed to have parameters.")
				};
			} else {
				var vsVersions = VsVersions.GetFinalVersions(testMethod.GetComputedProperty<string[]>(factAttribute, SpecialNames.VsixAttribute.VisualStudioVersions));
				// Process VS-specific traits.
				var suffix = testMethod.GetComputedArgument<string>(factAttribute, SpecialNames.VsixAttribute.RootSuffix) ?? "Exp";
				var newInstance = testMethod.GetComputedArgument<bool?>(factAttribute, SpecialNames.VsixAttribute.NewIdeInstance);
				var timeout = testMethod.GetComputedArgument<int?>(factAttribute, SpecialNames.VsixAttribute.TimeoutSeconds).GetValueOrDefault(XunitExtensions.DefaultTimeout);

				var testCases = new List<IXunitTestCase>();

				// Add invalid VS versions.
				testCases.AddRange (vsVersions
					.Where (v => !VsVersions.InstalledVersions.Contains (v))
					.Select (v => new ExecutionErrorTestCase (messageSink, defaultMethodDisplay, testMethod,
						string.Format ("Cannot execute test for specified {0}={1} because there is no VSSDK installed for that version.", SpecialNames.VsixAttribute.VisualStudioVersions, v))));

				testCases.AddRange (vsVersions
					.Where (v => VsVersions.InstalledVersions.Contains (v))
					.Select (v => new VsixTestCase (messageSink, defaultMethodDisplay, testMethod, v, suffix, newInstance, timeout)));

				return testCases;
			}
		}
Ejemplo n.º 2
0
        public static IVsixAttribute GetVsixAttribute(this ITestMethod testMethod, IAttributeInfo vsixAttribute)
        {
            var vsVersions = testMethod.GetComputedProperty <string[]>(vsixAttribute, nameof(IVsixAttribute.VisualStudioVersions));
            var minVersion = testMethod.GetComputedProperty <string>(vsixAttribute, nameof(IVsixAttribute.MinimumVisualStudioVersion));
            var maxVersion = testMethod.GetComputedProperty <string>(vsixAttribute, nameof(IVsixAttribute.MaximumVisualStudioVersion));

            var finalVersions = VsVersions.GetFinalVersions(vsVersions, minVersion, maxVersion);

            // Process VS-specific traits.
            var suffix = testMethod.GetComputedArgument <string>(vsixAttribute, nameof(IVsixAttribute.RootSuffix)) ?? "Exp";

            if (suffix == ".")
            {
                suffix = "";
            }

            var newInstance = testMethod.GetComputedArgument <bool?>(vsixAttribute, nameof(IVsixAttribute.NewIdeInstance));
            var timeout     = testMethod.GetComputedArgument <int?>(vsixAttribute, nameof(IVsixAttribute.TimeoutSeconds)).GetValueOrDefault(DefaultTimeout);
            var recycle     = testMethod.GetComputedArgument <bool?>(vsixAttribute, nameof(IVsixAttribute.RecycleOnFailure));
            var uiThread    = testMethod.GetComputedArgument <bool?>(vsixAttribute, nameof(IVsixAttribute.RunOnUIThread));

            return(new VsixAttribute(finalVersions)
            {
                MinimumVisualStudioVersion = minVersion,
                MaximumVisualStudioVersion = maxVersion,
                RootSuffix = suffix,
                NewIdeInstance = newInstance.GetValueOrDefault(),
                TimeoutSeconds = timeout,
                RecycleOnFailure = recycle.GetValueOrDefault(),
                RunOnUIThread = uiThread.GetValueOrDefault()
            });
        }