示例#1
0
        //Helpers
        protected override void                     DetermineChildren()
        {
            //Delegate (add any nested testcases)
            base.DetermineChildren();

            //Dynamically figure out what functions are variations...
            foreach (MethodInfo method in this.GetType().GetMethods())
            {
                //Loop through the Attributes for method
                foreach (VariationAttribute attr in method.GetCustomAttributes(typeof(VariationAttribute), false /*inhert*/))
                {
                    //Every method that has a [Variation attribute] = a variation
                    //Add this variation to our array
                    TestFunc func = null;
                    try
                    {
                        func = (TestFunc)Delegate.CreateDelegate(typeof(TestFunc), this, method);
                    }
                    catch (Exception e)
                    {
                        e = new TestFailedException("Variation: '" + method + "' doesn't match expected signature of 'void func()', unable to add that variation.", null, null, e);
                        HandleException(e);
                        continue;
                    }

                    TestVariation var = this.CreateVariation(func);
                    attr.Name = func.Method.Name;                       //Name is always the function name (invoke)
                    if (attr.Desc == null)
                    {
                        attr.Desc = attr.Name;
                    }
                    var.Attribute = attr;
                    AddChild(var);
                }
            }

            //Sort
            //Default sort is based upon IComparable of each item
            Children.Sort();
        }
示例#2
0
		//Helpers
		protected override void		            DetermineChildren()
		{
            //Delegate (add any nested testcases)
            base.DetermineChildren();

			//Dynamically figure out what functions are variations...
			foreach(MethodInfo method in this.GetType().GetMethods())
			{
				//Loop through the Attributes for method
				foreach(VariationAttribute attr in method.GetCustomAttributes(typeof(VariationAttribute), false/*inhert*/)) 
				{
					//Every method that has a [Variation attribute] = a variation
					//Add this variation to our array
                    TestFunc func = null;
					try
                    {
                        func = (TestFunc)Delegate.CreateDelegate(typeof(TestFunc), this, method);
                    }
                    catch(Exception e)
                    {
                        e = new TestFailedException("Variation: '" + method + "' doesn't match expected signature of 'void func()', unable to add that variation.", null, null, e);
                        HandleException(e);
                        continue;
                    }

                    TestVariation var   = this.CreateVariation(func);
					attr.Name = func.Method.Name;	//Name is always the function name (invoke)
					if(attr.Desc == null)
						attr.Desc = attr.Name;
					var.Attribute = attr;
                    AddChild(var);
				}
			}	

            //Sort		
            //Default sort is based upon IComparable of each item	
		    Children.Sort();
		}
示例#3
0
        public virtual List <TestVariation> EnumerateVariations(TestCase testcase, MethodInfo method)
        {
            int             id   = StartingId;
            List <object[]> rows = new List <object[]>();
            List <MatrixColumnAttribute> matrixColumns = new List <MatrixColumnAttribute>();

            object [] attributes = method.GetCustomAttributes(false);
            List <MatrixSkipConstraintAttribute> skipAttributes     = new List <MatrixSkipConstraintAttribute>();
            List <MatrixPriorityFilterAttribute> priorityAttributes = new List <MatrixPriorityFilterAttribute>();

            foreach (MatrixColumnAttribute matrixColumn in attributes.OfType <MatrixColumnAttribute>())
            {
                matrixColumns.Insert(0, matrixColumn);
            }
            foreach (MatrixSkipConstraintAttribute skipConstraint in attributes.OfType <MatrixSkipConstraintAttribute>())
            {
                skipAttributes.Insert(0, skipConstraint);
            }
            foreach (MatrixPriorityFilterAttribute filter in attributes.OfType <MatrixPriorityFilterAttribute>())
            {
                // TODO: why aren't we just doing add? or .ToList()?
                priorityAttributes.Insert(0, filter);
            }

            //Verify that no ParamOrderId's match
            IEnumerable <IGrouping <int, MatrixColumnAttribute> > grouping = matrixColumns.GroupBy <MatrixColumnAttribute, int>(mc => mc.ParamOrderId);

            foreach (IGrouping <int, MatrixColumnAttribute> group in grouping)
            {
                if (group.Key != -1)
                {
                    if (group.Count() > 1)
                    {
                        throw new ArgumentException("For Matrix variation:" + this.PrefixName + " test method:" + method.Name + " Multiple MatrixColumnAttributes have the same ParamOrderId, this is invalid");
                    }
                }
            }
            //Sort it by ParamOrderId
            matrixColumns.Sort(CompareMatrixColumnParamId);
            foreach (MatrixColumnAttribute matrixColumn in matrixColumns)
            {
                rows = MultiplyMatrixRowsByColumn(matrixColumn, rows);
            }
            List <TestVariation> variations = new List <TestVariation>();

            foreach (object[] matrixRow in rows)
            {
                //Every method that has a [Variation attribute] = a variation
                //Add this variation to our array
                TestFunc func = null;
                try
                {
                    func = (TestFunc)Delegate.CreateDelegate(typeof(TestFunc), testcase, method);
                }
                catch (Exception e)
                {
                    e = new TestFailedException("Variation: '" + method + "' doesn't match expected signature of 'void func()', unable to add that variation.", null, null, e);
                    TestLog.HandleException(e);
                    continue;
                }
                int    i           = 0;
                string description = null;
                //Calling from the list to reverse the attribute order so its in the order
                //as its in the code
                foreach (MatrixColumnAttribute matrixColumn in matrixColumns)
                {
                    if (description == null)
                    {
                        description = this.PrefixName + " " + matrixColumn.Name + ":" + matrixRow[i].ToString();
                    }
                    else
                    {
                        description = description + " " + matrixColumn.Name + ":" + matrixRow[i].ToString();
                    }
                    i++;
                }
                if (!ShouldSkipVariation(testcase, matrixColumns, skipAttributes, matrixRow))
                {
                    TestVariation var = new TestVariation(description, func);

                    var.Params   = matrixRow;
                    var.Id       = id;
                    var.Desc     = description;
                    var.Priority = VariationPriority(testcase, matrixColumns, priorityAttributes, matrixRow);
                    variations.Add(var);
                    id++;
                }
            }
            return(variations);
        }
        public static void LogFailure(AstoriaResponse response, Exception ex, bool shouldThrow)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Response verification failed");
            builder.AppendLine("----------------------------------------");
            response.Request.LogRequest(builder, true, true);
            builder.AppendLine("----------------------------------------");
            response.LogResponse(builder, true, true);
            builder.AppendLine("----------------------------------------");

            string log = builder.ToString();
            ex = new TestFailedException(log, null, null, ex);
            if (shouldThrow)
                throw ex;
            else
                AstoriaTestLog.FailAndContinue(ex);
        }
        public static void ValidateCountException(AstoriaResponse response, AstoriaRequest request, TestFailedException tfe)
        {
            // Errors are expected for older versions.
            if (!Versioning.Server.SupportsV2Features)
            {
                if (request.URI.Contains("$inlinecount=allpages"))
                {
                    // Query parameter not recognized.
                    if (response.ActualStatusCode == System.Net.HttpStatusCode.BadRequest)
                        return;
                }
                //anything other than http 404 or 400 is an invalid status code for a count query 
                else if (
                    response.ActualStatusCode != System.Net.HttpStatusCode.BadRequest
                    || response.ActualStatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    throw tfe;
                }
                else
                {
                    // Resource segment $count not found.
                    if (response.ActualStatusCode == System.Net.HttpStatusCode.NotFound || response.ActualStatusCode == System.Net.HttpStatusCode.BadRequest)
                        return;
                }
            }

            LinqQueryBuilder linqBuilder = new LinqQueryBuilder(request.Workspace);
            linqBuilder.CountingMode = request.URI.Contains("$inlinecount=allpages");
            try
            {
                linqBuilder.Build(request.Query);
            }
            catch (KeyNotFoundException kfe)
            {
                if (!AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.NonClr))
                {
                    throw kfe;
                }
            }
            bool isInvalidError = true;
            if (response.ActualStatusCode == System.Net.HttpStatusCode.NotFound)
            {
                if (request.Query.Input is CountExpression)
                {
                    ExpNode internalQuery = ((CountExpression)request.Query.Input).ScanNode;
                    if (internalQuery is KeyExpression || internalQuery is PredicateExpression)
                    {
                        isInvalidError = false;
                    }
                }
                if (isInvalidError)
                {
                    if (CommonPayload.CreateList(linqBuilder.QueryResult).Count == 0)
                    {
                        isInvalidError = false;
                    }
                }
            }
            if (response.ActualStatusCode == System.Net.HttpStatusCode.BadRequest)
            {

                if (request.Query.Input is CountExpression)
                {
                    ExpNode internalQuery = ((CountExpression)request.Query.Input).ScanNode;
                    if (internalQuery is KeyExpression || internalQuery is PredicateExpression)
                    {
                        isInvalidError = false;
                    }
                }
                else if (request.Query.Input is KeyExpression)
                {
                    isInvalidError = false;
                }
            }

            if (isInvalidError)
            {
                throw tfe;
            }
        }
示例#6
0
        public virtual List<TestVariation> EnumerateVariations(TestCase testcase, MethodInfo method)
        {
            int id= StartingId;
            List<object[]> rows = new List<object[]>();
            List<MatrixColumnAttribute> matrixColumns = new List<MatrixColumnAttribute>();
            object []attributes = method.GetCustomAttributes(false);
            List<MatrixSkipConstraintAttribute> skipAttributes = new List<MatrixSkipConstraintAttribute>();
            List<MatrixPriorityFilterAttribute> priorityAttributes = new List<MatrixPriorityFilterAttribute>();

            foreach (MatrixColumnAttribute matrixColumn in attributes.OfType < MatrixColumnAttribute>())
            {
                matrixColumns.Insert(0,matrixColumn);
            }
            foreach (MatrixSkipConstraintAttribute skipConstraint in attributes.OfType<MatrixSkipConstraintAttribute>())
            {
                skipAttributes.Insert(0, skipConstraint);
            }
            foreach (MatrixPriorityFilterAttribute filter in attributes.OfType<MatrixPriorityFilterAttribute>())
            {
                // TODO: why aren't we just doing add? or .ToList()?
                priorityAttributes.Insert(0, filter);
            }

            //Verify that no ParamOrderId's match
            IEnumerable<IGrouping<int, MatrixColumnAttribute>> grouping = matrixColumns.GroupBy<MatrixColumnAttribute, int>(mc => mc.ParamOrderId);
            foreach (IGrouping<int, MatrixColumnAttribute> group in grouping)
            {
                if (group.Key != -1)
                {
                    if (group.Count() > 1)
                        throw new ArgumentException("For Matrix variation:" + this.PrefixName + " test method:" + method.Name + " Multiple MatrixColumnAttributes have the same ParamOrderId, this is invalid");
                }
            }
            //Sort it by ParamOrderId
            matrixColumns.Sort(CompareMatrixColumnParamId);
            foreach (MatrixColumnAttribute matrixColumn in matrixColumns)
            {
                rows = MultiplyMatrixRowsByColumn(matrixColumn, rows);
            }
            List<TestVariation> variations = new List<TestVariation>();
            foreach(object[] matrixRow in rows)
            {
                //Every method that has a [Variation attribute] = a variation
		        //Add this variation to our array
                TestFunc func = null;
		        try
                {
                    func = (TestFunc)Delegate.CreateDelegate(typeof(TestFunc), testcase, method);
                }
                catch(Exception e)
                {
                    e = new TestFailedException("Variation: '" + method + "' doesn't match expected signature of 'void func()', unable to add that variation.", null, null, e);
                    TestLog.HandleException(e);
                    continue;
                }
                int i = 0;
                string description = null;
                //Calling from the list to reverse the attribute order so its in the order
                //as its in the code
                foreach (MatrixColumnAttribute matrixColumn in matrixColumns)
                {
                    if (description == null)
                        description = this.PrefixName + " " + matrixColumn.Name + ":" + matrixRow[i].ToString();
                    else
                        description = description + " " + matrixColumn.Name + ":" + matrixRow[i].ToString();
                    i++;
                }
                if (!ShouldSkipVariation(testcase, matrixColumns, skipAttributes, matrixRow))
                {
                    TestVariation var = new TestVariation(description, func);

                    var.Params = matrixRow;
                    var.Id = id;
                    var.Desc = description;
                    var.Priority = VariationPriority(testcase, matrixColumns, priorityAttributes, matrixRow);
                    variations.Add(var);
                    id++;
                }
            }
            return variations;
        }