Beispiel #1
0
        private VariationTestItem InvokeMatrixCombinationCallback(MethodInfo method, VariationTestItem variation, VariationAttribute attribute)
        {
            var callbackAttr = (TestMatrixCombinationCallbackAttribute)method.GetCustomAttributes(typeof(TestMatrixCombinationCallbackAttribute), false).SingleOrDefault();

            if (callbackAttr != null)
            {
                var callbackMethod = this.GetType().GetMethod(callbackAttr.CallbackMethodName, true, false);
                ExceptionUtilities.CheckObjectNotNull(callbackMethod, "Could not find instance method '{0}' on type '{1}'", callbackAttr.CallbackMethodName, this.GetType());
                ExceptionUtilities.Assert(typeof(VariationTestItem).IsAssignableFrom(callbackMethod.ReturnType), "Matrix combination callback '{0}' returns unexpected type '{1}'", callbackMethod.Name, callbackMethod.ReturnType);

                var arguments = new object[attribute.Parameters.Length + 1];
                arguments[0] = variation;
                Array.Copy(attribute.Parameters, 0, arguments, 1, attribute.Parameters.Length);

                variation = (VariationTestItem)callbackMethod.Invoke(this, arguments);
            }

            return(variation);
        }
Beispiel #2
0
        private void GenerateVariations(List <TestItem> result)
        {
            // add methods with [Variation] or [TestMatrix]
            foreach (MethodInfo mi in this.GetType().GetMethods())
            {
                // get any [___Bug] attributes
                var allBugs = ((BugAttribute[])mi.GetCustomAttributes(typeof(BugAttribute), false)).Union(this.bugs).ToList();

                // get any [Variation] attributes
                var variationAttributes = mi.GetCustomAttributes(typeof(VariationAttribute), false).Cast <VariationAttribute>().ToList();

                // get the [TestMatrix] if it exists
                var matrixAttribute = (TestMatrixAttribute)mi.GetCustomAttributes(typeof(TestMatrixAttribute), false).SingleOrDefault();
                if (matrixAttribute != null)
                {
                    var dimensionAttributes = mi.GetCustomAttributes(typeof(TestMatrixDimensionAttribute), false).Cast <TestMatrixDimensionAttribute>();
                    var constraintsInfo     = this.GetConstraintsInfo(mi);
                    variationAttributes.AddRange(this.GenerateTestAttributesFromMatrix <VariationAttribute>(matrixAttribute, dimensionAttributes, constraintsInfo));
                }

                foreach (VariationAttribute varAttr in variationAttributes)
                {
                    VariationTestItem variation = new VariationTestItem(this, mi, varAttr);
                    variation.SetTestItemFilter(this.GetTestItemFilter());

                    foreach (BugAttribute attr in allBugs)
                    {
                        variation.Bugs.Add(attr);
                    }

                    if (matrixAttribute != null)
                    {
                        variation = this.InvokeMatrixCombinationCallback(mi, variation, varAttr);
                        this.AssertTestItemIsNotSkippedWhenExplorationIsNotExhaustive(variation, matrixAttribute);
                    }

                    if (variation != null)
                    {
                        result.Add(variation);
                    }
                }
            }
        }