Exemple #1
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);
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// Assign TestDefaults attribute values to unset values in of TestInfo.
 /// Used on assembly and class TestDefaults attributes.
 /// </summary>
 private static void ApplyTestDefaultsAttribute(ref TestInfo testInfo, TestDefaultsAttribute defaultsAttribute)
 {
     if (testInfo == null)
     {
         throw new ArgumentNullException("testInfo");
     }
     if (defaultsAttribute == null)
     {
         throw new ArgumentNullException("defaultsAttribute");
     }
     if (defaultsAttribute.DefaultSubArea != null)
     {
         testInfo.SubArea = defaultsAttribute.DefaultSubArea;
     }
     if (defaultsAttribute.DefaultPriority != -1)
     {
         testInfo.Priority = defaultsAttribute.DefaultPriority;
     }
     if (defaultsAttribute.DefaultName != null)
     {
         testInfo.Name = defaultsAttribute.DefaultName;
     }
     if (defaultsAttribute.DefaultTimeout != -1)
     {
         testInfo.Timeout = TimeSpan.FromSeconds(defaultsAttribute.DefaultTimeout);
     }
     if (defaultsAttribute.SupportFiles != null)
     {
         foreach (string supportFileName in defaultsAttribute.SupportFiles.Split(','))
         {
             TestSupportFile testSupportFile = new TestSupportFile();
             testSupportFile.Source = supportFileName;
             testInfo.SupportFiles.Add(testSupportFile);
         }
     }
     if (defaultsAttribute.DefaultMethodName != null)
     {
         testInfo.DriverParameters["Method"] = defaultsAttribute.DefaultMethodName;
     }
 }
Exemple #3
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);
        }
Exemple #4
0
        /// <summary>
        /// Discover DRTs from drt manifest.
        /// </summary>
        /// <param name="testManifestPath">Should be path to rundrtlist.txt</param>
        /// <param name="defaultTestInfo"></param>
        /// <returns>TestInfos for drts.</returns>
        //List<TestInfo> Discover(string testBinRootPath, string targetFilename, TestInfo defaultTestInfo)
        public override IEnumerable <TestInfo> Discover(FileInfo testManifestPath, TestInfo defaultTestInfo)
        {
            string targetFilename = testManifestPath.FullName;

            if (!File.Exists(targetFilename))
            {
                throw new FileNotFoundException(Path.GetFullPath(targetFilename));
            }

            // Deserialize Drt manifest file into a list of Drt objects.
            XmlTextReader reader         = new XmlTextReader(targetFilename);
            List <Drt>    drtDefinitions = (List <Drt>)ObjectSerializer.Deserialize(reader, typeof(List <Drt>), null);

            // Convert each Drt object into a TestInfo.
            List <TestInfo> drts = new List <TestInfo>();

            foreach (Drt drtDef in drtDefinitions)
            {
                // Initialize TestInfo.
                TestInfo drtTestInfo = defaultTestInfo.Clone();

                ContentPropertyBag driverArgs = drtTestInfo.DriverParameters;
                // Store Executable, Owner, and Args in the property bag for DrtDriver to consume.
                driverArgs["exe"] = drtDef.Executable;
                if (!String.IsNullOrEmpty(drtDef.Args))
                {
                    driverArgs["args"] = drtDef.Args;
                }
                driverArgs["owner"] = drtDef.Owner;

                string exeFileNameWithoutExtension = Path.GetFileNameWithoutExtension(driverArgs["exe"]);

                drtTestInfo.Name             = exeFileNameWithoutExtension + "(" + drtDef.Args + ")";
                drtTestInfo.DriverParameters = driverArgs;
                drtTestInfo.Area             = drtDef.Team;

                if (drtDef.Timeout > 0)
                {
                    drtTestInfo.Timeout = TimeSpan.FromSeconds(drtDef.Timeout);
                }

                SelectConfiguration(drtTestInfo, drtDef);

                // Convert drt support files to a source/destination pair for TestInfo.
                foreach (string file in drtDef.SupportFiles)
                {
                    //The path may be to a directory or a file.  If we think the path is to a directory
                    //then the destination and the source are the same
                    //otherwise the destination is the containing directory of the source file
                    //We assume people are not specifying files that have no extention
                    //and that * is used only in filenames
                    TestSupportFile supportFile = new TestSupportFile();
                    supportFile.Source      = Path.Combine("DRT", file);
                    supportFile.Destination = string.IsNullOrEmpty(Path.GetExtension(supportFile.Source)) && !supportFile.Source.Contains("*") ? file : Path.GetDirectoryName(file);
                    drtTestInfo.SupportFiles.Add(supportFile);
                }

                // Add all needed build output files
                List <string> buildOutputFilePaths =
                    new List <string>()
                {
                    Path.Combine("DRT", driverArgs["exe"]),
                };

                // In .NET Core we need to add all outputs that are prefixed with the exe name
                buildOutputFilePaths.AddRange(Directory.GetFiles("DRT", exeFileNameWithoutExtension + ".*"));

                foreach (var path in buildOutputFilePaths)
                {
                    if (!drtTestInfo.SupportFiles.Select(s => s.Source).Contains(path))
                    {
                        drtTestInfo.SupportFiles.Add(new TestSupportFile()
                        {
                            Source = path
                        });
                    }
                }

                // Append relative path to all deployments.
                foreach (string deployment in drtDef.Deployments)
                {
                    drtTestInfo.Deployments.Add(Path.Combine("DRT", deployment));
                }

                drts.Add(drtTestInfo);
            }
            return(drts);
        }