Beispiel #1
0
        /// <summary>
        /// Applies bugs property on TestAttribute to TestInfo.
        /// </summary>
        /// <param name="testAttribute">Attribute specifying test case metadata.</param>
        /// <param name="testInfo">TestInfo to modify.</param>
        private static void ApplyBugs(TestAttribute testAttribute, TestInfo testInfo)
        {
            if (testAttribute.DevDivBugs != null)
            {
                // We want to override the default bugs. Either create new
                // empty collection is prototype TestInfo's bugs collection
                // was null, or clear it.
                if (testInfo.Bugs == null)
                {
                    testInfo.Bugs = new Collection <Bug>();
                }
                else
                {
                    testInfo.Bugs.Clear();
                }

                foreach (string bugId in testAttribute.DevDivBugs.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    Bug bug = new Bug();
                    bug.Id     = int.Parse(bugId.Trim(), CultureInfo.InvariantCulture);
                    bug.Source = "DevDiv";
                    testInfo.Bugs.Add(bug);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Applies driver related settings to the TestInfo.
        /// </summary>
        /// <param name="testAttribute">Attribute specifying test case metadata.</param>
        /// <param name="ownerType">Type that attribute is specified on.</param>
        /// <param name="testInfo">TestInfo to modify.</param>
        /// <returns>Application success.</returns>
        private static bool ApplyDriverSettings(TestAttribute testAttribute, Type ownerType, TestInfo testInfo)
        {
            testInfo.DriverParameters["Assembly"] = ownerType.Assembly.FullName;
            testInfo.DriverParameters["Class"]    = ownerType.FullName;

            if (testAttribute.MethodName != null)
            {
                testInfo.DriverParameters["Method"] = testAttribute.MethodName;
            }
            if (testAttribute.MethodParameters != null)
            {
                testInfo.DriverParameters["MethodParams"] += testAttribute.MethodParameters;
            }
            if (testAttribute.SecurityLevel != TestCaseSecurityLevel.Unset)
            {
                testInfo.DriverParameters["SecurityLevel"] = testAttribute.SecurityLevel.ToString();
            }
            if (testAttribute.MtaThread)
            {
                testInfo.DriverParameters["MtaThread"] = String.Empty;
            }
            if (testAttribute.TestParameters != null)
            {
                if (!ParseKeyValues(testAttribute.TestParameters, testInfo.DriverParameters))
                {
                    // Failure parsing key values, return an empty list.
                    Trace.TraceWarning("Test on class " + ownerType.FullName + " will not be discovered.");
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
 /// <summary>
 /// Applies support files property on TestAttribute to TestInfo.
 /// </summary>
 /// <param name="testAttribute">Attribute specifying test case metadata.</param>
 /// <param name="testInfo">TestInfo to modify.</param>
 private static void ApplySupportFiles(TestAttribute testAttribute, TestInfo testInfo)
 {
     if (testAttribute.SupportFiles != null)
     {
         foreach (string supportFile in testAttribute.SupportFiles.Split(','))
         {
             TestSupportFile testSupportFile = new TestSupportFile();
             testSupportFile.Source = supportFile.Trim();
             testInfo.SupportFiles.Add(testSupportFile);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Applies versions property on TestAttribute to TestInfo.
        /// </summary>
        /// <param name="testAttribute">Attribute specifying test case metadata.</param>
        /// <param name="testInfo">TestInfo to modify.</param>
        private static void ApplyVersions(TestAttribute testAttribute, TestInfo testInfo)
        {
            if (testAttribute.Versions != null)
            {
                // We want to override the default versions.
                testInfo.Versions.Clear();

                foreach (string versionString in testAttribute.Versions.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    testInfo.Versions.Add(versionString.Trim());
                }
            }
        }
Beispiel #5
0
        private void ApplyDeployments(TestAttribute testAttribute, TestInfo testInfo)
        {
            if (testAttribute.Deployments != null)
            {
                if (testInfo.Deployments == null)
                {
                    testInfo.Deployments = new Collection <String>();
                }

                foreach (string deploymentString in testAttribute.Deployments.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    testInfo.Deployments.Add(deploymentString.Trim());
                }
            }
        }
Beispiel #6
0
        private void ApplyConfigurations(TestAttribute testAttribute, TestInfo testInfo)
        {
            if (testAttribute.Configurations != null)
            {
                if (testInfo.Configurations == null)
                {
                    testInfo.Configurations = new Collection <String>();
                }

                foreach (string configurationString in testAttribute.Configurations.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    testInfo.Configurations.Add(configurationString.Trim());
                }
            }
        }
Beispiel #7
0
        //



        //        if (!ParseKeyValues(testAttribute.Variables, testInfo.Variables))
        //        {
        //            // Failure parsing key values, return an empty list.
        //            Trace.TraceWarning("Test on class " + ownerType.FullName + " will not be discovered.");
        //            return false;
        //        }
        //    }

        //    return true;
        //}

        /// <summary>
        /// Applies keywords property on TestAttribute to TestInfo.
        /// </summary>
        /// <param name="testAttribute">Attribute specifying test case metadata.</param>
        /// <param name="testInfo">TestInfo to modify.</param>
        private static void ApplyKeywords(TestAttribute testAttribute, TestInfo testInfo)
        {
            if (testAttribute.Keywords != null)
            {
                if (testInfo.Keywords == null)
                {
                    testInfo.Keywords = new Collection <string>();
                }

                foreach (string keywordString in testAttribute.Keywords.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    testInfo.Keywords.Add(keywordString.Trim());
                }
            }
        }
        /// <summary>
        /// Multiply TestInfo by VariationAttributes found on type's constructors.
        /// Create TestInfo from a TestAttribute, Type and default TestInfo.
        /// New test info will be added to tests List.
        /// </summary>
        protected override ICollection <TestInfo> BuildTestInfo(TestAttribute testAttribute, Type ownerType, TestInfo defaultTestInfo)
        {
            List <TestInfo> tests        = new List <TestInfo>();
            TestInfo        baseTestInfo = base.BuildTestInfo(testAttribute, ownerType, defaultTestInfo).First();

            // Search each constructor for variationAttributes
            foreach (ConstructorInfo constructorInfo in ownerType.GetConstructors())
            {
                IEnumerable <VariationAttribute> variationAttributes = constructorInfo.GetCustomAttributes(typeof(VariationAttribute), false).Cast <VariationAttribute>();
                tests.AddRange(Multiply(baseTestInfo, variationAttributes, ownerType));
            }

            // No variationAttributes found for the base test. Add it without variation information.
            if (tests.Count == 0)
            {
                tests.Add(baseTestInfo);
            }

            return(tests);
        }
Beispiel #9
0
 /// <summary>
 /// Applies general metadata properties to TestInfo.
 /// </summary>
 /// <param name="testAttribute">Attribute specifying test case metadata.</param>
 /// <param name="ownerType">Type that attribute is specified on.</param>
 /// <param name="testInfo">TestInfo to modify.</param>
 private static void ApplyGeneralMetadata(TestAttribute testAttribute, Type ownerType, TestInfo testInfo)
 {
     if (testAttribute.Name != null)
     {
         // If the TestAttribute Name property is String.Empty, it means
         // to use the name of the class as the test name. (See remark
         // in TestAttribute ctor that doesn't take a name)
         if (testAttribute.Name == String.Empty)
         {
             testInfo.Name = ownerType.FullName;
         }
         else
         {
             testInfo.Name = testAttribute.Name;
         }
     }
     if (testAttribute.Priority != TestAttribute.UnsetInt)
     {
         testInfo.Priority = testAttribute.Priority;
     }
     if (testAttribute.Area != null)
     {
         testInfo.Area = testAttribute.Area;
     }
     if (testAttribute.SubArea != null)
     {
         testInfo.SubArea = testAttribute.SubArea;
     }
     if (testAttribute.Disabled)
     {
         testInfo.Disabled = testAttribute.Disabled;
     }
     if (testAttribute.Timeout != TestAttribute.UnsetInt)
     {
         testInfo.Timeout = TimeSpan.FromSeconds(testAttribute.Timeout);
     }
     if (testAttribute.ExecutionGroupingLevel != ExecutionGroupingLevel.InternalDefault_DontUseThisLevel)
     {
         testInfo.ExecutionGroupingLevel = testAttribute.ExecutionGroupingLevel;
     }
 }
Beispiel #10
0
        /// <summary>
        /// Create TestInfo from a TestAttribute, Type and default TestInfo.
        /// New test info will be added to tests List.
        /// </summary>
        protected virtual ICollection <TestInfo> BuildTestInfo(TestAttribute testAttribute, Type ownerType, TestInfo defaultTestInfo)
        {
            // NOTE:
            // The old implementation restricted this method to only building a
            // TestInfo from the exact AttributeType, not any class inheriting
            // from TestAttribute. This logic was already being enforced by
            // SearchClass/SearchMethods, so this restriction here has been
            // lifted. It allows subclasses to delegate population of inherited
            // properties to the base class and focus on just new properties.

            List <TestInfo> newTests = new List <TestInfo>();

            TestInfo testInfo = defaultTestInfo.Clone();

            // General Test metadata
            ApplyGeneralMetadata(testAttribute, ownerType, testInfo);

            ApplyVersions(testAttribute, testInfo);

            ApplyBugs(testAttribute, testInfo);

            ApplyKeywords(testAttribute, testInfo);

            ApplyConfigurations(testAttribute, testInfo);

            ApplyDeployments(testAttribute, testInfo);

            ApplySupportFiles(testAttribute, testInfo);

            // Driver data. This is part of an implicit contract with sti.exe.
            if (!ApplyDriverSettings(testAttribute, ownerType, testInfo))
            {
                return(newTests);
            }

            newTests.Add(testInfo);

            return(newTests);
        }
Beispiel #11
0
        /// <summary>
        /// Create TestInfo from a TestAttribute, Type, default TestInfo, and XTC file.
        /// </summary>
        protected override ICollection <TestInfo> BuildTestInfo(TestAttribute testAttribute, Type ownerType, TestInfo defaultTestInfo)
        {
            ModelAttribute modelAttribute = (ModelAttribute)testAttribute;

            List <TestInfo> newTests = new List <TestInfo>();

            if (String.IsNullOrEmpty(modelAttribute.XtcFileName))
            {
                // No xtc file name, return empty list.
                Trace.TraceWarning("Xtc file name is null or empty. Aborting discovery on class " + ownerType.FullName + ".");
                return(newTests);
            }

            if (modelAttribute.ModelStart > modelAttribute.ModelEnd)
            {
                // Invalid end index, return empty list.
                Trace.TraceWarning("The model end index cannot be greater than the start index. Aborting discovery on class " + ownerType.FullName + ".");
                return(newTests);
            }

            // Build test info as we would for normal test attribute.
            // This should only return one test case.
            IEnumerable <TestInfo> baseTests = base.BuildTestInfo(modelAttribute, ownerType, defaultTestInfo);

            if (baseTests.Count() > 1)
            {
                // Too many tests, return empty list.
                Trace.TraceWarning("Parsing single ModelAttribute produced multiple test infos before reading XTC, aborting discovery on class " + ownerType.FullName + ".");
                return(newTests);
            }

            if (baseTests.Count() == 0)
            {
                // Too few tests, return empty list.
                Trace.TraceWarning("Failure parsing ModelAttribute on class " + ownerType.FullName + " before reading XTC. Aborting discovery.");
                return(newTests);
            }

            TestInfo baseTest = base.BuildTestInfo(modelAttribute, ownerType, defaultTestInfo).First();

            baseTest.DriverParameters["ModelClass"]    = baseTest.DriverParameters["Class"];
            baseTest.DriverParameters["ModelAssembly"] = baseTest.DriverParameters["Assembly"];
            baseTest.DriverParameters["XtcFileName"]   = modelAttribute.XtcFileName;
            TestSupportFile tsf = new TestSupportFile();

            tsf.Source = modelAttribute.XtcFileName;
            baseTest.SupportFiles.Add(tsf);

            int modelStart, modelEnd;

            try
            {
                GetStartEndTestCaseFromXtc(modelAttribute.XtcFileName, out modelStart, out modelEnd);
            }
            catch (ArgumentException e)
            {
                // Xtc file does not exist, return empty list.
                Trace.TraceWarning(e.Message + " Discovery aborted on class " + ownerType.FullName + ".");
                return(newTests);
            }

            // Attribute range overrides that found in the xtc file.
            if (modelAttribute.ModelStart >= 0)
            {
                modelStart = modelAttribute.ModelStart;
            }
            if (modelAttribute.ModelEnd >= 0)
            {
                modelEnd = modelAttribute.ModelEnd;
            }

            if (modelAttribute.ExpandModelCases)
            {
                // Create new test info for each test in the xtc and pass TIndex to driver.
                for (int testIndex = modelStart; testIndex <= modelEnd; testIndex++)
                {
                    baseTest.DriverParameters["TIndex"] = testIndex.ToString(CultureInfo.InvariantCulture);
                    newTests.Add(baseTest.Clone());
                }
            }
            else
            {
                // Create a single test info for all the tests in the xtc and pass range to driver.
                baseTest.DriverParameters["ModelStart"] = modelStart.ToString(CultureInfo.InvariantCulture);
                baseTest.DriverParameters["ModelEnd"]   = modelEnd.ToString(CultureInfo.InvariantCulture);
                newTests.Add(baseTest);
            }

            return(newTests);
        }