Ejemplo n.º 1
0
        public override List<TestVariation> EnumerateVariations(TestCase testcase, MethodInfo method) {

            // build data 
            var columnAttrs = method.GetCustomAttributes(typeof(MatrixColumnAttribute), false) as MatrixColumnAttribute[];
            Debug.Assert(columnAttrs.Length > 0);

            object[][] inputMatrix = new object[columnAttrs.Length][];

            Dictionary<string, int> columnName2PositionMap = new Dictionary<string, int>();
            foreach (var inputColumn in columnAttrs) {
                #region Asserts
                Debug.Assert(inputMatrix[inputColumn.ParamOrderId] == null);
                Debug.Assert(!columnName2PositionMap.ContainsKey(inputColumn.Name));
                Debug.Assert(!columnName2PositionMap.ContainsValue(inputColumn.ParamOrderId));
                #endregion
                inputMatrix[inputColumn.ParamOrderId] = inputColumn.Values;
                columnName2PositionMap[inputColumn.Name] = inputColumn.ParamOrderId;
            }



            // Build Skip filters
            List<object[]> skipConstraints = CreateSkipConstraints(method, columnName2PositionMap);

            // Build Priority filters + default filter
            Dictionary<int, List<object[]>> priFilters = CreatePriorityConstraints(method, Priority, columnName2PositionMap);

            // Create Pairwise combinations based on the pri filters
            Dictionary<int, List<object[]>> combinations = Pairwise(inputMatrix, skipConstraints, priFilters);

            List<TestVariation> variations = new List<TestVariation>();
            int variationCounter = 0;

            //string orderedColumnNames = string.Concat(columnName2PositionMap.OrderBy(p => p.Value).Select((p, i) => i == 0 ? p.Key : string.Concat(",", p.Key)).ToArray());

            foreach (int priority in combinations.Keys) {
                foreach (object[] line in combinations[priority]) {
                    string name = GetVariationName(columnName2PositionMap, line);
                    TestVariation tv = new TestVariation(name, (TestFunc)Delegate.CreateDelegate(typeof(TestFunc), testcase, method));
                    tv.Priority = priority;

                    //// the last element in params will contain the parameter names (we need it to be able perform filters on the silverlight side);
                    //object[] linePlusNames = new object[line.Length + 1];
                    //Array.Copy(line, linePlusNames, line.Length);
                    //linePlusNames[line.Length] = orderedColumnNames ;
                    //tv.Params = linePlusNames;

                    tv.Params = line;
                    tv.Id = ++variationCounter;
                    variations.Add(tv);
                }
            }

            return variations;
        }
Ejemplo n.º 2
0
        public TestVariation GenerateVariation(TestCase testcase, MethodInfo method, VariationAttribute testVarAttrib)
        {
            //do not generate variations for tests which have KeepInContent set to false and the version is not V2
            if (!this.KeepInContent && !Versioning.Server.SupportsV2Features)
            {
                return null;
            }

            TestVariation ffTestVariation;
            MethodInfo generateEpmMappingsMethod = testcase.GetType().GetMethod("GenerateEpmMappings");
            FilterResourcesLambda = GenerateLambda();

            TestFunc testMethodAction = delegate()
            {
                bool thisTestFailed = true;

                SkipInvalidRuns();

                try
                {
                    generateEpmMappingsMethod.Invoke(testcase, new object[]{
                    KeepInContent,//bool pKeepInContent,
                    RemoveUnEligibleTypes,//bool pRemoveUnEligibleTypes,
                    GenerateClientTypes,//bool pGenerateClientTypes,
                    MapToAtomElements,//bool pMapPropertiesToAtomElements,
                    MapToNonAtomElements,//bool pMapPropertiesToNonAtomElements,
                    GenerateServerEPMMappings,//bool GenerateServerEPMMappings,
                    KeepSameNamespace,//bool KeepSameNamespace,
                    IncludeComplexTypes,//bool  IncludeComplexTypes
                    PreDefinedPaths  ,//string[] PreDefinedPaths
                    FilterResourcesLambda //Func<ResourceType, bool> pFilterResourcesLambda
                });
                    method.Invoke(testcase, null);


                    thisTestFailed = AstoriaTestLog.FailureFound;
                }
                catch (Microsoft.OData.Client.DataServiceClientException dsException)
                {
                    if (dsException.InnerException != null)
                        AstoriaTestLog.WriteLine(dsException.InnerException.Message);
                }
                catch (TestFailedException testException)
                {

                    AstoriaTestLog.WriteLine("Test failed  with :{0}", testException.Message);
                    AstoriaTestLog.WriteLine("Repro Details\r\nClient Code");
                }
                finally
                {
                    //Disabling this as OOM errors prevent file copying
                    thisTestFailed = false;
                    #region //Clean out all the facets after the test , so that the next test is clear
                    object workspacePointer = null;
                    PropertyInfo testWorkspacesProperty = testcase.Parent.GetType().GetProperty("Workspaces");
                    workspacePointer = testcase.Parent;
                    if (testWorkspacesProperty == null)
                    {
                        testWorkspacesProperty = testcase.GetType().GetProperty("Workspaces");
                        workspacePointer = testcase;
                    }
                    Workspaces testWorkspaces = (Workspaces)testWorkspacesProperty.GetValue(workspacePointer, null);
                    foreach (Workspace workspace in testWorkspaces)
                    {
                        if (thisTestFailed)
                        {
                            string testFailureReproPath = String.Format("FF_Failure_{0}", System.Guid.NewGuid().ToString());
                            testFailureReproPath = System.IO.Path.Combine(Environment.CurrentDirectory, testFailureReproPath);
                            IOUtil.CopyFolder(workspace.DataService.DestinationFolder, testFailureReproPath, true);
                            AstoriaTestLog.WriteLine("Test failed , Repro available at : {0} ", testFailureReproPath);
                        }
                 
                        if (!(workspace is EdmWorkspace))
                        {
                            workspace.GenerateClientTypes = true;
                            workspace.GenerateServerMappings = false;
                            workspace.ApplyFriendlyFeeds();
                        }
                    }
                    #endregion

                }
            };
            ffTestVariation = new TestVariation(testMethodAction);
            if (testVarAttrib != null)
            {
                ffTestVariation.Params = testVarAttrib.Params;
                ffTestVariation.Param = testVarAttrib.Param;
                ffTestVariation.Desc = String.Format(
                "{3} , {0},{1},{2},{4}{5}{6}{7}",
                GenerateClientTypes ? "Client Mapped" : "",
                GenerateServerEPMMappings ? "Server Mapped" : "",
                MapToAtomElements ? "Mapped to Atom" : "Mapped to Non-Atom Elements",
                testVarAttrib.Desc, InheritanceFilter.ToString(),
                KeepSameNamespace ? "Same Namespace" : "Different NameSpaces",
                PreDefinedPaths != null ? ",PredefinedPaths" : "", KeepInContent.ToString());
                if (AstoriaTestProperties.MaxPriority == 0)
                {
                    ffTestVariation.Id = 1;
                }
                else
                {
                    ffTestVariation.Id = idCounter++;
                }
                ffTestVariation.Priority = this.Priority;
            }
            return ffTestVariation;

        }
Ejemplo n.º 3
0
        public TestVariation GenerateVariation(TestCase testcase, MethodInfo method)
        {
            TestVariation rcTestVariation;
            TestFunc testMethodAction = delegate()
            {
                method.Invoke(testcase, null);
            };
            rcTestVariation = new TestVariation(testMethodAction);

            rcTestVariation.Params = this.Params;
            rcTestVariation.Param = this.Param;
            rcTestVariation.Desc = this.Desc;
            rcTestVariation.Id = this.Id;
            rcTestVariation.Priority = this.Priority;

            return rcTestVariation;
        }
 public ExplicitCastNullVariation(Type nodeType, Type retType, bool shouldThrow, TestCase tc, string desc)
 {
     this.Desc = desc;
     _nodeType = nodeType;
     _retType = retType;
     _shouldThrow = shouldThrow;
 }
 public ExplicitCastVariation(ExplicitCastTestType testType, NodeCreateType nodeCreateType, Type nodeType, object data, Type retType, TestCase testCase, string desc)
 {
     _desc = desc;
     _data = data;
     _nodeType = nodeType;
     _testType = testType;
     _retType = retType;
     _nodeCreateType = nodeCreateType;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 7
0
 private int VariationPriority(TestCase testCase, List<MatrixColumnAttribute> matrixColumns, List<MatrixPriorityFilterAttribute> priorityFilters, object[] matrixRow)
 {
     int maxPriority = this.Priority;
     foreach (MatrixPriorityFilterAttribute filter in priorityFilters)
     {
         if (IsMatchAcrossRow(testCase, matrixColumns, matrixRow, filter.FilterColumns, filter.FilterValues))
             maxPriority = Math.Max(maxPriority, filter.Priority);
     }
     return maxPriority;
 }
Ejemplo n.º 8
0
        private bool IsMatchAcrossRow(TestCase testCase, List<MatrixColumnAttribute> matrixColumns, object[] matrixRow, string[] filterNames, object[] filterValues)
        {
            bool allEqual = true;
            for (int i = 0; i < filterNames.Count(); i++)
            {
                string columnName = filterNames[i];
                object columnValue = filterValues[i];

                bool found = false;
                for (int j = 0; j < matrixColumns.Count; j++)
                {
                    if (matrixColumns[j].Name == columnName)
                    {
                        found = true;
                        if (!matrixRow[j].Equals(columnValue))
                            allEqual = false;
                        break;
                    }
                }
                if (!found)
                {
                    if (columnName.StartsWith("Parent.") && columnName.EndsWith(".Param"))
                    {
                        TestItem test = testCase;
                        string name = columnName;
                        while ((name = name.Remove(0, "Parent.".Length)).StartsWith("Parent."))
                            test = test.Parent;
                        if (name == "Param")
                        {
                            if (!test.Param.Equals(columnValue))
                                allEqual = false;
                        }
                        else
                        {
                            throw new TestFailedException("Could not parse inherited param name: " + columnName);
                        }
                    }
                    else
                    {
                        throw new TestFailedException("Could not find column: " + columnName);
                    }
                }
            }
            return allEqual;
        }
Ejemplo n.º 9
0
 private bool ShouldSkipVariation(TestCase testCase, List<MatrixColumnAttribute> matrixColumns, List<MatrixSkipConstraintAttribute> skipConstraints, object[] matrixRow)
 {
     foreach (MatrixSkipConstraintAttribute skipConstraint in skipConstraints)
     {
         if (IsMatchAcrossRow(testCase, matrixColumns, matrixRow, skipConstraint.SkipColumns, skipConstraint.SkipValues))
             return true;
     }
     return false;
 }