Represents a test case.
Inheritance: INotifyPropertyChanged
        public void ChangeStatus(string testCaseName, TestCaseStatus status)
        {
            TestCaseGroup from = testcasemap[testCaseName];
            TestCaseGroup to = OtherTestCases;
            if (from == null) return;
            TestCase testcase = from.TestCaseList.FirstOrDefault(c => c.Name == testCaseName);
            if (status == TestCaseStatus.Running) RunningTestCase = testcase;
            switch (status)
            {
                case TestCaseStatus.Running:
                    to = InProgressTestCases;
                    break;
                case TestCaseStatus.Passed:
                    testcase.IsChecked = false;
                    to = PassedTestCases;
                    break;
                case TestCaseStatus.Failed:
                    testcase.IsChecked = true;
                    to = FailedTestCases;
                    break;
                case TestCaseStatus.Other:
                    to = OtherTestCases;
                    break;
                case TestCaseStatus.NotRun:
                    to = NotRunTestCases;
                    break;
            }

            testcase.Status = status;
            if (UpdateTestCaseStatus != null)
            {
                UpdateTestCaseStatus(from, to, testcase);
            }
            else
            {

                from.RemoveTestCase(testcase);
                to.AddTestCase(testcase);
            }
            testcasemap[testCaseName] = to;
        }
 /// <summary>
 /// Update running case to be the first case in a group.
 /// </summary>
 /// <param name="runningTestCase"></param>
 private void ChangeRunningCaseToTop(TestCase runningTestCase)
 {
     if (TestCaseList.Contains(runningTestCase))
     {
         OnPropertyChanged("Status");
     }
 }
 /// <summary>
 /// Remove the test case from the group.
 /// </summary>
 /// <param name="testcase">The test case.</param>
 public void RemoveTestCase(TestCase testcase)
 {
     testcase.PropertyChanged -= TestcasePropertyChanged;
     if (testcase.IsChecked) checkedNumber--;
     TestCaseList.Remove(testcase);
     OnPropertyChanged("Visibility");
     OnPropertyChanged("HeaderText");
     OnPropertyChanged("IsChecked");
 }
 /// <summary>
 /// Add a test case to the group.
 /// </summary>
 /// <param name="testcase">The test case.</param>
 public void AddTestCase(TestCase testcase)
 {
     testcase.PropertyChanged += TestcasePropertyChanged;
     if (testcase.IsChecked) checkedNumber++;
     int insertIndex = 0;
     if (TestCaseList.Count > 0 && (TestCaseList.First<TestCase>().Status == TestCaseStatus.Running))
     {
         insertIndex = 1;
     }
     TestCaseList.Insert(insertIndex, testcase);
     OnPropertyChanged("Visibility");
     OnPropertyChanged("HeaderText");
     OnPropertyChanged("IsChecked");
 }
 /// <summary>
 /// Update the case status and case log
 /// Find the related case name, change its status and show log to user
 /// </summary>
 public void UpdateCaseFromHtmlLog(TestCaseStatus status, string testCaseName, string testCaseLogPath)
 {
     RunningTestCase = AllTestCases.FirstOrDefault(c => c.Name == testCaseName);
     if (RunningTestCase == null) return;
     GroupByOutcome.ChangeStatus(testCaseName, status);
     RunningTestCase.LogUri = new Uri(testCaseLogPath);
     RunningTestCase = null;
 }
 /// <summary>
 /// If existing running test cases, change the status to Other.
 /// </summary>
 public void FinishTest()
 {
     // Clear RunningTestCase
     if (RunningTestCase != null)
     {
         if(RunningTestCase.Status == TestCaseStatus.Running)
         {
             GroupByOutcome.ChangeStatus(RunningTestCase.Name, TestCaseStatus.NotRun);
         }
         RunningTestCase = null;
     }
     foreach (var testcase in AllTestCases)
     {
         // Clear Waiting cases.
         if (testcase.Status == TestCaseStatus.Waiting && CurrentPageCaseList.Contains(testcase.Name))
         {
             TestCaseStatus status = TestCaseStatus.NotRun;
             if(testcase.LogUri != null && System.IO.File.Exists(testcase.LogUri.AbsolutePath))
             {
                 Utility.ParseFileGetStatus(testcase.LogUri.AbsolutePath, out status);
             }
             testcase.Status = status;
         }
         // Clear Running cases. Should not be here
         if(testcase.Status == TestCaseStatus.Running && CurrentPageCaseList.Contains(testcase.Name))
         {
             testcase.Status = TestCaseStatus.NotRun;
             RunningTestCase = null;
         }
     }
 }
        public void LoadFrom(List<string> dllPath)
        {
            _testCaseList = new List<TestCase>();
            foreach (string DllFileName in dllPath)
            {
                Assembly assembly = Assembly.LoadFrom(DllFileName);
                Type[] types = assembly.GetTypes();

                foreach (Type type in types)
                {
                    //search for class, ont interfaces and other type
                    if (type.IsClass)
                    {
                        MethodInfo[] methods = type.GetMethods();
                        foreach (MethodInfo method in methods)
                        {
                            //methods loop, serch for methods with TestMethodAttribute
                            object[] objs = method.GetCustomAttributes(false);
                            bool isTestMethod = false;
                            bool isIgnored = false;
                            foreach (object attribute in method.GetCustomAttributes(false))
                            {
                                if (attribute.GetType().Name == "TestMethodAttribute") isTestMethod = true;
                                if (attribute.GetType().Name == "IgnoreAttribute") isIgnored = true;
                            }
                            if (isTestMethod && !isIgnored)
                            {
                                //GetCategory
                                List<string> categories = new List<string>();
                                string caseFullName = method.DeclaringType.FullName + "." + method.Name;
                                foreach (object attribute in objs)
                                {
                                    //record TestCategories
                                    if (attribute.GetType().Name == "TestCategoryAttribute")
                                    {
                                        PropertyInfo property = attribute.GetType().GetProperty("TestCategories");
                                        object category = property.GetValue(attribute, null);
                                        foreach (string str in (System.Collections.ObjectModel.ReadOnlyCollection<string>)category)
                                        {
                                            categories.Add(str);
                                        }
                                    }
                                }
                                TestCase testcase = new TestCase()
                                {
                                    FullName = caseFullName,
                                    Category = categories,
                                    Name = method.Name
                                };
                                testcase.ToolTipOnUI = testcase.Name + Environment.NewLine + "Category:";
                                foreach (string category in testcase.Category)
                                {
                                    testcase.ToolTipOnUI += Environment.NewLine + category;
                                }
                                _testCaseList.Add(testcase);
                            }
                        }
                    }
                }

            }
        }
 void logger_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "RunningTestCase" && IsCurrent)
     {
         testcase = logger.RunningTestCase;
         SelectedCaseChanged();
     }
 }
 public void SelectTestCase(TestCase testcase)
 {
     IsCurrent = false;
     this.testcase = testcase;
     SelectedCaseChanged();
 }
 private void TreeViewItem_GotFocus(object sender, RoutedEventArgs e)
 {
     var myListBoxItem = sender as TreeViewItem;
     if (myListBoxItem == null) return;
     BindingExpression binding = myListBoxItem.GetBindingExpression(TreeViewItem.TagProperty);
     selectedTestCase = binding.DataItem as TestCase;
     if (selectedTestCase != null)
         logview.SelectTestCase(selectedTestCase);
     else
         logview.IsCurrent = true;
 }
        public void ChangeStatus(string testCaseName, TestCaseStatus status)
        {
            lock (locker)
            {
                TestCaseGroup from = testcasemap[testCaseName];
                TestCaseGroup to   = OtherTestCases;
                if (from == null)
                {
                    return;
                }
                TestCase testcase = from.TestCaseList.FirstOrDefault(c => c.Name == testCaseName);
                // If changed to Running/Waiting status, no need to change group.

                if (status == TestCaseStatus.Running)
                {
                    if (RunningTestCase != null)
                    {
                        if (RunningTestCase.Status == TestCaseStatus.Running)
                        {
                            RunningTestCase.Status = TestCaseStatus.Waiting;
                        }
                    }
                    RunningTestCase        = testcase;
                    RunningTestCase.Status = status;
                    if (UpdateTestCaseList != null)
                    {
                        UpdateTestCaseList(from, RunningTestCase);
                    }
                    return;
                }
                if (status == TestCaseStatus.Waiting)
                {
                    if (testcase.Status == TestCaseStatus.Running)
                    {
                        testcase.Status = status;
                        return;
                    }
                }

                switch (status)
                {
                case TestCaseStatus.Passed:
                    testcase.IsChecked = false;
                    to = PassedTestCases;
                    break;

                case TestCaseStatus.Failed:
                    testcase.IsChecked = true;
                    to = FailedTestCases;
                    break;

                case TestCaseStatus.Other:
                    to = OtherTestCases;
                    break;

                case TestCaseStatus.NotRun:
                    to = NotRunTestCases;
                    break;
                }
                testcase.Status = status;
                if (UpdateTestCaseStatus != null)
                {
                    UpdateTestCaseStatus(from, to, testcase);
                }
                else
                {
                    from.RemoveTestCase(testcase);
                    to.AddTestCase(testcase);
                }
                testcasemap[testCaseName] = to;
            }
        }
        public void LoadFrom(List <string> dllPath)
        {
            _testCaseList = new List <TestCase>();
            foreach (string DllFileName in dllPath)
            {
                Assembly assembly = Assembly.LoadFrom(DllFileName);
                Type[]   types    = assembly.GetTypes();

                foreach (Type type in types)
                {
                    //search for class, ont interfaces and other type
                    if (type.IsClass)
                    {
                        MethodInfo[] methods = type.GetMethods();
                        foreach (MethodInfo method in methods)
                        {
                            //methods loop, serch for methods with TestMethodAttribute
                            object[] objs         = method.GetCustomAttributes(false);
                            bool     isTestMethod = false;
                            bool     isIgnored    = false;
                            foreach (object attribute in method.GetCustomAttributes(false))
                            {
                                if (attribute.GetType().Name == "TestMethodAttribute")
                                {
                                    isTestMethod = true;
                                }
                                if (attribute.GetType().Name == "IgnoreAttribute")
                                {
                                    isIgnored = true;
                                }
                            }
                            if (isTestMethod && !isIgnored)
                            {
                                //GetCategory
                                List <string> categories   = new List <string>();
                                string        caseFullName = method.DeclaringType.FullName + "." + method.Name;
                                foreach (object attribute in objs)
                                {
                                    //record TestCategories
                                    if (attribute.GetType().Name == "TestCategoryAttribute")
                                    {
                                        PropertyInfo property = attribute.GetType().GetProperty("TestCategories");
                                        object       category = property.GetValue(attribute, null);
                                        foreach (string str in (System.Collections.ObjectModel.ReadOnlyCollection <string>)category)
                                        {
                                            categories.Add(str);
                                        }
                                    }
                                }
                                TestCase testcase = new TestCase()
                                {
                                    FullName = caseFullName,
                                    Category = categories,
                                    Name     = method.Name
                                };
                                testcase.ToolTipOnUI = testcase.Name + Environment.NewLine + "Category:";
                                foreach (string category in testcase.Category)
                                {
                                    testcase.ToolTipOnUI += Environment.NewLine + category;
                                }
                                _testCaseList.Add(testcase);
                            }
                        }
                    }
                }
            }
        }