예제 #1
0
        public void AddGlobalVariables_should_add_baseurl_as_variable()
        {
            // Arrange
            var config = new Config();
            config.BaseUrl = "mybaseurl";
            var sessionVariables = new SessionVariables();

            // Act
            sessionVariables.AddGlobalVariables(config);

            // Assert
            Assert.That(sessionVariables.GetVariableValue("baseurl"), Is.EqualTo("mybaseurl"));
        }
예제 #2
0
        public void AddGlobalVariables_should_add_variables_from_config()
        {
            // Arrange
            var config = new Config();
            config.Variables.Add(new Variable("eggs", "ham"));
            var sessionVariables = new SessionVariables();

            // Act
            sessionVariables.AddGlobalVariables(config);

            // Assert
            Assert.That(sessionVariables.GetVariableValue("eggs"), Is.EqualTo("ham"));
        }
예제 #3
0
        public TestCaseSession Run(CaseCollection testCollection)
        {
            _isStopPending = false;
            _currentResults = new List<TestCaseResult>();

            var session = new TestCaseSession();
            session.StartTime = DateTime.UtcNow;

            // Add all config variables and ones in this <testcase>
            var variables = new SessionVariables();
            variables.AddGlobalVariables(_config);
            variables.AddOrUpdateVariables(testCollection.Variables);

            var verificationsMatcher = new VerificationsMatcher(variables);

            // Ensure we loop atleast once:
            int repeatTotal = (testCollection.Repeat > 0) ? testCollection.Repeat : 1;
            List<Case> testCases = testCollection.TestCases.ToList();

            TimeSpan minResponseTime = TimeSpan.MaxValue;
            TimeSpan maxResponseTime = TimeSpan.MinValue;
            int totalCasesRun = 0;

            CasesRun = 0;
            TotalCases = testCases.Count;
            RepeatCount = 0;

            for (int i = 0; i < repeatTotal; i++)
            {
                foreach (Case testCase in testCases)
                {
                    if (_isStopPending)
                        break;

                    try
                    {
                        TestCaseResult result = RunCase(testCase, variables, verificationsMatcher);
                        session.TestCaseResults.Add(result);
                        _currentResults.Add(result);

                        if (result.ResponseTime < minResponseTime)
                            minResponseTime = result.ResponseTime;

                        if (result.ResponseTime > maxResponseTime)
                            maxResponseTime = result.ResponseTime;
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "An exception occurred running case {0}", testCase.Id);
                    }
                    finally
                    {
                        totalCasesRun++;

                        CasesRun++;
                        RepeatCount = i;
                    }
                }

                if (_isStopPending)
                    break;
            }

            session.EndTime = DateTime.UtcNow;
            session.TotalRunTime = session.EndTime - session.StartTime;
            session.TotalCasesRun = totalCasesRun;
            session.MinResponseTime = minResponseTime;
            session.MaxResponseTime = maxResponseTime;

            return session;
        }