/// <summary> /// The add test case element. /// </summary> /// <param name="assemblyObjectList"> /// The assembly object list. /// </param> /// <param name="methodInfo"> /// The method info. /// </param> /// <param name="methodDocumentation"> /// The method documentation. /// </param> private void AddTestCaseElement(TestObjectCollection assemblyObjectList, EhMethodInfo methodInfo, MethodTags methodDocumentation) { Log.Enter(this, string.Format("AddTestCaseElement: {0}", methodInfo.MethodName)); var parent = assemblyObjectList.FirstOrDefault(n => n.Name == methodInfo.MethodName); if (parent == null) { var testCase = new TestCase(); testCase.Name = methodInfo.MethodDisplayName; var lastNamespaceSegment = GetLastNamespaceSegment(methodInfo.Namespace); testCase.DisplayName = string.Format("{0}.{1}.{2}", lastNamespaceSegment, methodInfo.ClassName, methodInfo.MethodName); testCase.Description = methodDocumentation.GetDocumentationText(); testCase.AssemblyMethodRefId = methodInfo.CustomAttributGuid; testCase.AssemblyName = Path.GetFileName(methodInfo.AssemblyFullPath); testCase.Parameters = this.GetTestParameterCollection(methodDocumentation); assemblyObjectList.Add(testCase); } }
/// <summary> /// Merges the test suite collection. /// </summary> /// <param name="tree"> /// The tree. /// </param> /// <param name="assemblyObject"> /// The assembly object. /// </param> private static void MergeTestSuiteCollection(TestObjectCollection tree, TestSuite assemblyObject) { var vorhanden = false; foreach (var name in tree) { if (name.Name == assemblyObject.Name) { foreach (var ob in assemblyObject.TestObjects) { if (name is TestCollection) { MergeTestObjectCollection((name as TestCollection).TestObjects, ob); } } vorhanden = true; } } if (!vorhanden) { tree.Add(assemblyObject); } }
public TestObject() { //generate the unique id this.ID = Guid.NewGuid(); this.TestObjects = new TestObjectCollection(); //add this testobject to the List of test objects. _collections.Add(this.ID, this); }
/// <summary> /// Merges the test object collection. /// </summary> /// <param name="tree"> /// The tree. /// </param> /// <param name="assemblyObject"> /// The assembly object. /// </param> private static void MergeTestObjectCollection(TestObjectCollection tree, TestObject assemblyObject) { if (assemblyObject is TestFolder) { MergeTestFolderCollection(tree, assemblyObject as TestFolder); } if (assemblyObject is TestSuite) { MergeTestSuiteCollection(tree, assemblyObject as TestSuite); } if (assemblyObject is TestCase) { MergeTestCaseCollection(tree, assemblyObject as TestCase); } }
/// <summary> /// The add folder element. /// </summary> /// <param name="testObjectCollection"> /// The assembly object list. /// </param> /// <param name="name"> /// The name. /// </param> /// <returns> /// The <see cref="TestFolder"/>. /// </returns> private TestFolder AddFolderElement(TestObjectCollection testObjectCollection, string name) { Log.Enter(this, string.Format("AddFolderElement: {0}", name)); var parent = testObjectCollection.FirstOrDefault(n => n.Name == name); if (parent == null) { var testFolder = new TestFolder { Name = name }; testObjectCollection.Add(testFolder); return(testFolder); } return(parent as TestFolder); }
/// <summary> /// Merges the test case collection. /// </summary> /// <param name="tree"> /// The tree. /// </param> /// <param name="assemblyObject"> /// The assembly object. /// </param> private static void MergeTestCaseCollection(TestObjectCollection tree, TestCase assemblyObject) { var vorhanden = false; foreach (var name in tree) { if (name.Name == assemblyObject.Name) { vorhanden = true; break; } } if (!vorhanden) { tree.Add(assemblyObject); } }
public static void Main() { // your code goes here TestObject test1 = new TestObject(); TestObject test2 = new TestObject(); var collection = new TestObjectCollection(); collection.Add(test2); test1.testObjects = collection; if (test2.parentCollection.parent == test1) { Console.WriteLine("Done"); } else { Console.WriteLine("Fail"); } }
/// <summary> /// The get test object collection. /// </summary> /// <param name="subNamespace"> /// The root folder. /// </param> /// <param name="testObjects"> /// The test objects. /// </param> /// <returns> /// The <see cref="TestObjectCollection"/>. /// </returns> private IEnumerable <TestObject> AddNamespaceToTestObjectCollection(string subNamespace, IEnumerable <TestObject> testObjects) { Log.Enter(this, "GetTestObjectCollection"); var ns = new TestObjectCollection(); var rootFolder = subNamespace.Split('.'); foreach (var testObject in testObjects) { var tempFolder = this.AddFolderElement(ns, testObject.TestDefinition.ToString()); for (var i = 0; i < rootFolder.Count(); i++) { tempFolder = this.AddFolderElement(tempFolder.TestObjects, rootFolder[i]); } testObject.Parent = tempFolder; tempFolder.TestObjects.Add(testObject); } return(ns); }
/// <summary> /// The get test object collection. /// </summary> /// <param name="methodsInfo"> /// The methods info. /// </param> /// <param name="xmlDocument"> /// The xml document. /// </param> /// <returns> /// The <see cref="TestObject"/>. /// </returns> private IEnumerable <TestObject> GetTestObjectCollection(IEnumerable <EhMethodInfo> methodsInfo, XmlDocument xmlDocument) { Log.Enter(this, "GetTestObjectCollection"); var ns = new TestObjectCollection(); foreach (EhMethodInfo methodInfo in methodsInfo) { if (methodInfo != null) { var methodNamespace = methodInfo.Namespace; if (methodNamespace == null) { continue; } var rootElement = this.AddFolderElement(ns, methodInfo.CustomAttributTestDefinition).TestObjects; var spaces = methodNamespace.Split('.'); var parent = rootElement; for (var i = 0; i < spaces.Count(); i++) { // Folder hinzufügen var folderName = spaces[i]; parent = this.AddFolderElement(parent, folderName).TestObjects; } // Folder hinzufügen parent = this.AddFolderElement(parent, methodInfo.ClassName).TestObjects; // TestCase hinzufügen var methodDocumentation = this.GetMethodTags(methodInfo, xmlDocument); this.AddTestCaseElement(parent, methodInfo, methodDocumentation); } } return(ns); }
/// <summary> /// The execute new. /// </summary> /// <param name="executionObject"> /// The execution object. /// </param> /// <returns> /// The <see cref="ExecutionObject"/>. /// </returns> public ExecutionObject Execute(ExecutionObject executionObject) { Log.Enter(this, MethodBase.GetCurrentMethod().Name); if (executionObject != null) { // Create a copy from origin var currentExecutionObject = new ExecutionObject(executionObject); // Get all available testobjects from testconfiguration (= control document) TestObjectCollection testObjectCollection = currentExecutionObject.TestConfiguration.AvailableTestObjects; // More than one testObjectCollection is possible. In fact there´s only one. It´s the top layer in control document. foreach (var testObject in testObjectCollection) { if (testObject is TestCollection) { // Add new TestReportInfos without related TestSuites var testReportInfo = new TestReportInfo(string.Empty); currentExecutionObject.TestReportInfos.Add(testReportInfo); currentExecutionObject.CurrentTestReportInfo = testReportInfo; // Recursvive call currentExecutionObject.CurrentTestObject = testObject; currentExecutionObject.ExecutionData.TestMethods = ((TestCollection)testObject).TestObjects; currentExecutionObject = this.ReadByObject(currentExecutionObject); } } return(currentExecutionObject); } Log.Error(this, "ExecutionObject is Null before execution"); PCPS.TestAutomation.Common.Tools.Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "ExecutionObject is Null before execution"); Console.WriteLine("ExecutionObject is Null before execution"); return(null); }
/// <summary> /// The filder test config. /// </summary> /// <param name="deviceFunctions"> /// The device functions. /// </param> /// <param name="availableTestObjects"> /// The available test objects. /// </param> /// <returns> /// The <see cref="TestObjectCollection"/>. /// </returns> private static TestObjectCollection FilderTestConfig(List <DeviceFunction> deviceFunctions, TestObjectCollection availableTestObjects) { for (var i = 0; i < availableTestObjects.Count; i++) { var testObject = availableTestObjects[i]; if (testObject is TestSuite) { var testSuite = testObject as TestSuite; if (!IsDeviceFunctionActive(deviceFunctions, testSuite)) { availableTestObjects.Remove(testSuite); i--; } else { testSuite.TestObjects = FilderTestConfig(deviceFunctions, testSuite.TestObjects); } } else if (testObject is TestFolder) { var testFolder = testObject as TestFolder; testFolder.TestObjects = FilderTestConfig(deviceFunctions, testFolder.TestObjects); if (testFolder.TestObjects.Count == 0) { availableTestObjects.Remove(testFolder); i--; } } } return(availableTestObjects); }