public TestVerdict ScratchMethod()
        {
            try
            {
                //using (var testMetric = new TestMetric("9999", "Test metric description"))
                //{
                //    testMetric.Start();
                //    Thread.Sleep(5000);
                //    testMetric.Stop();
                //};

                var testCheck = TestCheck.IsTrue("This is the first a sample test check", false, "I expected this to fail");
                testCheck = TestCheck.IsTrue("This is the second a sample test check", true, "I expected this to pass.");
                testCheck = TestCheck.IsTrue("This is the third a sample test check", false, $"Expected:  Pass, Actual:  Fail.");

                TestWarning.IsTrue(false, "This is a sample test warning.");

                TestTrace.Trace("This is a sample trace message");

                Thread.Sleep(5000);

                TestMessage += "Completed!";
                TestVerdict  = TestVerdict.Pass;
            }
            catch (Exception e)
            {
                TestMessage += e.ToString();
                TestVerdict  = TestVerdict.Error;
            }
            finally
            {
            }

            return(TestVerdict);
        }
        public TestVerdict Dictionary()
        {
            try
            {
                var parameters = new Dictionary <string, string>();
                parameters.Add("Param1", "Value1");
                parameters.Add("Param2", "Value2");

                foreach (var item in parameters)
                {
                    TestTrace.Trace($"Key:  {item.Key}, Value:  {item.Value}");
                }

                TestMessage += "Success";
                TestVerdict  = TestVerdict.Pass;
            }
            catch (Exception e)
            {
                TestMessage += e.ToString();
                TestVerdict  = TestVerdict.Error;
            }
            finally
            {
            }

            return(TestVerdict);
        }
Ejemplo n.º 3
0
        public override void OnTestMetric(string virtualUser, TestMetricEventArgs args)
        {
            try
            {
                if (!args.ElapsedTime.Equals(TimeSpan.Zero))
                {
                    var flattenedArgs = args.FlattenStateArgs();

                    var metric = string.Format(testMetricInsert,
                                               testRunId,
                                               args.VirtualUser,
                                               args.PerfID,
                                               args.Description,
                                               args.StartTime,
                                               args.StopTime,
                                               args.ElapsedTime.TotalSeconds,
                                               flattenedArgs);
#if VERBOSE
                    TestTrace.Trace(metric);
#endif

                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.CommandText = metric;
                        sqlCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                TestTrace.Trace(e.ToString());
            }
        }
        public TestVerdict RandomTimeout(
            int minTime,
            int maxTime)
        {
            try
            {
                Random rnd = new Random();

                var millisecs = rnd.Next(minTime, maxTime);

                var testMessage = $"Virtual user:  {GetCurrentUser()} random timeout:  {millisecs} millseconds.";
                TestTrace.Trace(testMessage);

                Thread.Sleep(millisecs);

                TestMessage += $"{GetCurrentUser()}:  Success!";
                TestVerdict  = TestVerdict.Pass;
            }
            catch (Exception e)
            {
                TestMessage += e.ToString();
                TestVerdict  = TestVerdict.Error;
            }
            finally
            {
            }

            return(TestVerdict);
        }
Ejemplo n.º 5
0
        public override void OnTestExecutionBegin(TestExecutor testExecutor, TestExecutionBeginArgs args)
        {
            try
            {
                if (sqlConnection == null)
                {
                    sqlConnection = new SqlConnection(sqlConnectionString);

                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        if (sqlConnection.State != System.Data.ConnectionState.Open)
                        {
                            sqlConnection.Open();
                        }

                        sqlCommand.CommandText = string.Format(testRunInsert, DateTime.Now);
                        testRunId = Convert.ToInt32(sqlCommand.ExecuteScalar());
                    }
                }
            }
            catch (Exception e)
            {
                TestTrace.Trace(e.ToString());
            }
        }
Ejemplo n.º 6
0
        public override void OnTestSuiteExecutionComplete(TestSuite testSuite, TestSuiteResult testSuiteResult)
        {
            try
            {
                var metric = string.Format(testResultInsert,
                                           testRunId,
                                           testSuiteResult.VirtualUser,
                                           testSuiteResult.StartTime,
                                           testSuiteResult.EndTime,
                                           testSuiteResult.ElapsedTime,
                                           testSuiteResult.TestVerdict);

                Debug.WriteLine(metric);

                using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                {
                    sqlCommand.CommandText = metric;
                    sqlCommand.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                TestTrace.Trace(e.ToString());
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Setup generic environment for unit testing with XFS code.
 /// </summary>
 public static void SetupUnitTests()
 {
     ErrorHandling.ErrorHandler = (message) =>
     {
         TestTrace.Trace("Testing", "Error", message);
         if (System.Diagnostics.Debugger.IsAttached)
         {
             System.Diagnostics.Debugger.Break();
         }
         throw new TestFatalErrorException(message);
     };
 }
Ejemplo n.º 8
0
        public TestVerdict GetProjects(
            [TestParameter("TestRail Url", "Enter the TestRail Url", "[TestRailUrl]")]
            string url,
            [TestParameter("User name", "Enter the TestRail user name.", "[TestRailUser]")]
            string userName,
            [TestParameter("User password", "Enter the TestRail user password.", "[TestRailPassword]")]
            string password)
        {
            try
            {
                var client = new TestRail.TestRailClient(url, userName, password);

                var projects = client.GetProjects();

                var project = projects.Find(x => x.Name.Equals("TestProject"));

                //client.GetProject()

                var runs = client.GetRuns(project.ID);

                var bob = client.GetResults(136);

                var results = client.GetResultsForCase(59, 136);

                var suites = client.GetSuites(project.ID);
                var suite  = suites.Find(x => x.Name.Equals("Master test suite"));


                var testRun = client.AddRun(project.ID, (ulong)suite.ID, $"Very important test run:  {DateTime.Now}", "Blah, blah, blah", 1);
                var dorks   = client.GetResultsForRun(60);

                var tests = client.GetTests(60);
                var cases = client.GetCases(project.ID, (ulong)suite.ID);

                var comment = File.ReadAllText(@"C:\DevProjects\Quintity\Repos\Quintity.TestFramework.TestListeners\Quintity.TestFramework.TestListeners.Test\TestProperties\TestProperties.props");

                foreach (var @case in cases)
                {
                    var spud = client.AddResultForCase(testRun.Value, (ulong)@case.ID, TestRail.Types.ResultStatus.Passed, comment, "version 1.0", new TimeSpan(0, 0, 30));
                    TestTrace.Trace($"Added result:  {spud.Value}");
                }

                TestMessage += "Success";
                TestVerdict  = TestVerdict.Pass;
            }
            catch (Exception e)
            {
                TestMessage += e.ToString();
                TestVerdict  = TestVerdict.Error;
            }

            return(TestVerdict.Pass);
        }
Ejemplo n.º 9
0
        public TestVerdict MyTestMethod(
            [TestParameter("String parameter", "Enter string parameter", "Default value")]
            string param1,
            [TestParameter("Int parameter", "Enter integer parameter", 0)]
            int param2,
            [TestParameter("Boolean parameter", "Enter boolean parameter", true)]
            bool param3)
        {
            try
            {
                Setup();

                TestTrace.Trace("This is a sample TestTrace message.");

                TestAssert.IsTrue(param3, "This is a sample assertion.");

                TestCheck.IsTrue("Test of param3", param3, "This is a sample TestCheck.");

                TestMessage += "This is the returned test message.";
                TestVerdict  = TestVerdict.Pass;
            }
            catch (TestAssertFailedException e)
            {
                TestMessage += e.ToString();
                TestVerdict  = TestVerdict.Fail;
            }
            catch (Exception e)
            {
                TestMessage += e.ToString();
                TestVerdict  = TestVerdict.Error;
            }
            finally
            {
                Teardown();
            }

            return(TestVerdict);
        }