Exemplo n.º 1
0
 public IntegrationTestClusterAttribute(Type clusterType)
 {
     if (!TestAssemblyRunner.IsAnIntegrationTestClusterType(clusterType))
     {
         throw new ArgumentException($"Cluster must be subclass of {nameof(XunitClusterBase)} or {nameof(XunitClusterBase)}<>");
     }
     this.ClusterType = clusterType;
 }
        protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
        {
            var classOfMethod = Type.GetType(testMethod.TestClass.Class.Name, true, true);
            //in mixed mode we do not want to run any api tests for plugins when running against a snapshot
            //because the client is "hot"
            var collectionType = TestAssemblyRunner.GetClusterForCollection(testMethod.TestClass?.TestCollection);

            return(TestClient.Configuration.RunIntegrationTests && RequiresPluginButRunningAgainstSnapshot(classOfMethod, collectionType));
        }
        protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
        {
            var classOfMethod = Type.GetType(testMethod.TestClass.Class.Name, true, true);
            var method        = classOfMethod.GetMethod(testMethod.Method.Name, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public)
                                ?? testMethod.Method.ToRuntimeMethod();

            var collectionType = TestAssemblyRunner.GetClusterForCollection(testMethod.TestClass?.TestCollection);

            return(TypeSkipVersionAttributeSatisfies(classOfMethod) ||
                   MethodSkipVersionAttributeSatisfies(method) ||
                   RequiresPluginButRunningAgainstSnapshot(classOfMethod, collectionType));
        }
		/// <inheritdoc />
		protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, out string skipReason)
		{
			skipReason = null;
			var runIntegrationTests = discoveryOptions.GetValue<bool>(nameof(ElasticXunitRunOptions.RunIntegrationTests));
			if (!runIntegrationTests) return true;

			var cluster = TestAssemblyRunner.GetClusterForClass(testMethod.TestClass.Class);
			if (cluster == null)
			{
				skipReason += $"{testMethod.TestClass.Class.Name} does not define a cluster through IClusterFixture or {nameof(IntegrationTestClusterAttribute)}";
				return true;
			}

			var elasticsearchVersion = discoveryOptions.GetValue<ElasticVersion>(nameof(ElasticXunitRunOptions.Version));

			// Skip if the version we are testing against is attributed to be skipped do not run the test nameof(SkipVersionAttribute.Ranges)
			var skipVersionAttribute = GetAttributes<SkipVersionAttribute>(testMethod).FirstOrDefault();
			if (skipVersionAttribute != null)
			{
				var skipVersionRanges = skipVersionAttribute.GetNamedArgument<IList<Range>>(nameof(SkipVersionAttribute.Ranges)) ?? new List<Range>();
				if (elasticsearchVersion == null && skipVersionRanges.Count > 0)
                {
                    skipReason = $"{nameof(SkipVersionAttribute)} has ranges defined for this test but " +
                                 $"no {nameof(ElasticXunitRunOptions.Version)} has been provided to {nameof(ElasticXunitRunOptions)}";
                    return true;
                }

				if (elasticsearchVersion != null)
				{
					var reason = skipVersionAttribute.GetNamedArgument<string>(nameof(SkipVersionAttribute.Reason));
					for (var index = 0; index < skipVersionRanges.Count; index++)
					{
						var range = skipVersionRanges[index];
						if (!range.IsSatisfied(elasticsearchVersion)) continue;
						skipReason = $"{nameof(SkipVersionAttribute)} has range {range} that {elasticsearchVersion} satisfies";
						if (!string.IsNullOrWhiteSpace(reason)) skipReason += $": {reason}";
						return true;
					}
				}
			}

			var skipTests = GetAttributes<SkipTestAttributeBase>(testMethod)
				.FirstOrDefault(a=>a.GetNamedArgument<bool>(nameof(SkipTestAttributeBase.Skip)));

			if (skipTests == null) return false;

			skipReason = skipTests.GetNamedArgument<string>(nameof(SkipTestAttributeBase.Reason));
			return true;
		}