Tmx.TestData.AddTestSuite C# (CSharp) Method

AddTestSuite() static private method

static private AddTestSuite ( string testSuiteName, string testSuiteId, System.Guid testPlatformId, string testSuiteDesctiption, ICodeBlock testSuiteBeforeScenario, ICodeBlock testSuiteAfterScenario ) : bool
testSuiteName string
testSuiteId string
testPlatformId System.Guid
testSuiteDesctiption string
testSuiteBeforeScenario ICodeBlock
testSuiteAfterScenario ICodeBlock
return bool
        internal static bool AddTestSuite(string testSuiteName, 
                                          string testSuiteId,
                                          Guid testPlatformId,
                                          string testSuiteDesctiption,
                                          ICodeBlock[] testSuiteBeforeScenario,
                                          ICodeBlock[] testSuiteAfterScenario)
        {
            bool result = false;
            
            if (string.IsNullOrEmpty(testSuiteId))
                testSuiteId = GetTestSuiteId();
            
            if (null != GetTestSuite(testSuiteName, testSuiteId, testPlatformId))
                // the suite requested won't be duplicated, exit
                return false;
            
            // removing the first (autogenerated) suite
            try {
                if (null == TestSuites)
                    TestSuites = new List<ITestSuite>();
                // 20141117
                // probably useful
//                if (1 == TestData.TestSuites.Count && TestData.Autogenerated == TestData.TestSuites[0].Name &&
//                                1 == TestData.TestSuites[0].TestScenarios.Count && TestData.Autogenerated == TestData.TestSuites[0].TestScenarios[0].Name &&
//                                1 == TestData.TestSuites[0].TestScenarios[0].TestResults.Count && TestResultOrigins.Automatic == TestData.TestSuites[0].TestScenarios[0].TestResults[0].Origin) {
                if (1 == TestSuites.Count && TestSuites.All(ts => ts.Name == Autogenerated))
                    TestSuites.RemoveAt(0);
            } catch (Exception ee) {
                Console.WriteLine(ee.Message);
            }
            
            // set time spent on the previous suite
            if (null != CurrentTestSuite) {
                
                if (DateTime.MinValue != CurrentTestSuite.Timestamp) {
                    
                    CurrentTestSuite.SetTimeSpent(
                        CurrentTestSuite.TimeSpent +=
                        (DateTime.Now - CurrentTestSuite.Timestamp).TotalSeconds);
                    
                    CurrentTestSuite.Timestamp = DateTime.MinValue;
                }
            }
            
            TestSuites.Add(new TestSuite(testSuiteName, testSuiteId));
            if (!string.IsNullOrEmpty(testSuiteDesctiption))
                TestSuites[TestSuites.Count - 1].Description = testSuiteDesctiption;
            
            CurrentTestSuite = TestSuites[TestSuites.Count - 1];
            
            if (CurrentTestSuite != null) {
                
                CurrentTestSuite.PlatformUniqueId = testPlatformId != Guid.Empty ? testPlatformId : CurrentTestPlatform.UniqueId;
                CurrentTestSuite.PlatformId = TestPlatforms.First(tp => tp.UniqueId == CurrentTestSuite.PlatformUniqueId).Id;
                CurrentTestSuite.BeforeScenario = testSuiteBeforeScenario;
                CurrentTestSuite.AfterScenario = testSuiteAfterScenario;
                
                // set the initial time for this suite's session
                CurrentTestSuite.SetNow();
                
                OnTmxNewTestSuiteCreated(CurrentTestSuite, new EventArgs()); //null);
            }
            
            if (Preferences.Storage) {
                using (var session = StorageHelper.SessionFactory.OpenSession()) {
                    session.Save(CurrentTestSuite);
                }
            }
            
            if (0 == CurrentTestSuite.TestScenarios.Count)
                CreateAutogeneratedTestScenario();
            
            result = true;
            return result;
        }