示例#1
0
        internal List <DataRowAttribute> GetRows(MethodInfo methodInfo, out DataDrivenTypeEnum dataDrivenType)
        {
            List <DataRowAttribute> rows = null;

            Attribute[] dataRowAttribute;

            dataDrivenType = DataDrivenTypeEnum.None;

            dataRowAttribute = methodInfo.GetCustomAttributes <DataRowAttribute>(false).ToArray() ?? null;
            if ((dataRowAttribute != null) && (dataRowAttribute.Length > 0))
            {
                dataDrivenType = DataDrivenTypeEnum.DataRow;
                rows           = new List <DataRowAttribute>();

                foreach (Attribute attrib in dataRowAttribute)
                {
                    rows.Add((DataRowAttribute)attrib);
                }
            }

            dataRowAttribute = methodInfo.GetCustomAttributes <DynamicDatasourceAttribute>(false).ToArray() ?? null;
            if ((dataRowAttribute != null) && (dataRowAttribute.Length > 0))
            {
                dataDrivenType = DataDrivenTypeEnum.DynamicDataSource;
                rows           = new List <DataRowAttribute>();

                foreach (object[] row in ((DynamicDatasourceAttribute)dataRowAttribute[0]).GetData(methodInfo))
                {
                    DataRowAttribute attrib = new DataRowAttribute(row);
                    attrib.DisplayName = ((DynamicDatasourceAttribute)dataRowAttribute[0]).GetDisplayName(methodInfo, row);
                    rows.Add(attrib);
                }
            }

            dataRowAttribute = methodInfo.GetCustomAttributes <DynamicDataAttribute>(false).ToArray() ?? null;
            if ((dataRowAttribute != null) && (dataRowAttribute.Length > 0))
            {
                dataDrivenType = DataDrivenTypeEnum.DynamicData;
                rows           = new List <DataRowAttribute>();

                foreach (object[] row in ((DynamicDataAttribute)dataRowAttribute[0]).GetData(methodInfo))
                {
                    DataRowAttribute attrib = new DataRowAttribute(row);
                    attrib.DisplayName = ((DynamicDataAttribute)dataRowAttribute[0]).GetDisplayName(methodInfo, row);
                    rows.Add(attrib);
                }
                ((DynamicDataAttribute)dataRowAttribute[0]).DynamicDataDisplayNameDeclaringType.GetMethod($"BuildDatasource").Invoke(null, new object[] { $"{methodInfo.DeclaringType.FullName}.{methodInfo.Name}" });
            }

            return(rows);
        }
        private List <DataRowAttribute> GetRows(MethodInfo methodInfo, out DataDrivenTypeEnum dataDrivenType)
        {
            List <DataRowAttribute> rows = null;

            Attribute[] dataRowAttribute;

            dataDrivenType = DataDrivenTypeEnum.None;

            dataRowAttribute = methodInfo.GetCustomAttributes <DataRowAttribute>(false).ToArray() ?? null;
            if ((dataRowAttribute != null) && (dataRowAttribute.Length > 0))
            {
                dataDrivenType = DataDrivenTypeEnum.DataRow;
                rows           = new List <DataRowAttribute>();

                foreach (Attribute attrib in dataRowAttribute)
                {
                    rows.Add((DataRowAttribute)attrib);
                }
            }

            dataRowAttribute = methodInfo.GetCustomAttributes <DynamicDatasourceAttribute>(false).ToArray() ?? null;
            if ((dataRowAttribute != null) && (dataRowAttribute.Length > 0))
            {
                dataDrivenType = DataDrivenTypeEnum.DynamicDataSource;
                rows           = new List <DataRowAttribute>();

                foreach (object[] row in ((DynamicDatasourceAttribute)dataRowAttribute[0]).GetData(methodInfo))
                {
                    DataRowAttribute attrib = new DataRowAttribute(row);
                    attrib.DisplayName = ((DynamicDatasourceAttribute)dataRowAttribute[0]).GetDisplayName(methodInfo, row);
                    rows.Add(attrib);
                }
            }

            dataRowAttribute = methodInfo.GetCustomAttributes <DynamicDataAttribute>(false).ToArray() ?? null;
            if ((dataRowAttribute != null) && (dataRowAttribute.Length > 0))
            {
                dataDrivenType = DataDrivenTypeEnum.DynamicData;
                rows           = new List <DataRowAttribute>();

                foreach (object[] row in ((DynamicDataAttribute)dataRowAttribute[0]).GetData(methodInfo))
                {
                    DataRowAttribute attrib = new DataRowAttribute(row);
                    attrib.DisplayName = ((DynamicDataAttribute)dataRowAttribute[0]).GetDisplayName(methodInfo, row);
                    rows.Add(attrib);
                }
            }

            return(rows);
        }
示例#3
0
        public override TestResult[] Execute(ITestMethod testMethod)
        {
            TestResult[]       iterationResults = null;
            DataDrivenTypeEnum dataDrivenType   = DataDrivenTypeEnum.None;

            _testInfo = new TestInfo()
            {
                // testMethod.MethodInfo.DeclaringType.FullName
                Class = new ClassObject()
                {
                    FullName = testMethod.TestClassName, Assembly = testMethod.MethodInfo.Module.Name, Description = _classDisplayName
                },
                Test = new TestObject()
                {
                    FullName = $"{testMethod.TestClassName}.{testMethod.TestMethodName}", Description = GetTestDescription(testMethod.MethodInfo), Categories = GetTestCategories(testMethod.MethodInfo)
                },
                Iteration = 0,
                IsChild   = false,
            };

            if (_rowIndex == 0)
            {
                _testInfo = ReporterManager.Get().AddTest(_testInfo);
                _rowIndex = 0;
                _rows     = GetRows(testMethod.MethodInfo, out dataDrivenType);
            }

            TestInfo childTest = (TestInfo)_testInfo.DeepCopy();

            childTest.Iteration        = ++_rowIndex;
            childTest.IsChild          = true;
            childTest.Test.Description = String.Copy(((DataRowAttribute)_rows[_rowIndex - 1]).DisplayName ?? $"{_testInfo.Test.Description} (Row #{_rowIndex})");

            childTest = ReporterManager.Get().AddTestNode(childTest);

            iterationResults = base.Execute(testMethod);
            results.AddRange(iterationResults);

            _testInfo = ReporterManager.Get().TestEnd(childTest);

            if (_rows.Count == _rowIndex)
            {
                ReporterManager.Get().TestEnd(_testInfo);
            }

            return(iterationResults);
        }