public void Run_should_populate_StartTime_and_EndTime_and_TotalRunTime()
        {
            // Arrange
            var beforeStart = DateTime.UtcNow;
            var config = new Config();
            var testCaseReader = new TestCaseReaderMock();
            var stringReader = new StringReader("");

            var response = new HttpResponse();
            response.ResponseTime = TimeSpan.FromSeconds(5);

            HttpClientMock httpClient = new HttpClientMock(response);
            IResultWriter resultWriter = new ResultWriterStub();
            var runner = new TestSessionRunner(config, httpClient, resultWriter);

            var caseCollection = CreateCaseCollection(new[]
            {
                new Case() { Url = "foo1" },
            });

            // Act
            TestCaseSession session = runner.Run(caseCollection);

            // Assert
            Assert.That(session.StartTime, Is.GreaterThanOrEqualTo(beforeStart));
            Assert.That(session.EndTime, Is.GreaterThanOrEqualTo(session.StartTime));
            Assert.That(session.TotalRunTime, Is.EqualTo(session.EndTime - session.StartTime));
        }
Esempio n. 2
0
        public void should_parse_responses()
        {
            // Arrange
            var stringBuilder = new StringBuilder();
            var httpLogWriter = new HttpLogWriter(new StringWriter(stringBuilder));
            var httpClient = new HttpClient(httpLogWriter, new RestClient());

            var config = new Config();

            string xml = TestHelpers.ReadEmbeddedFile("parseresponses.xml", XmlExamplesFolder);
            var stringReader = new StringReader(xml);
            var reader = new TestCaseReader();
            var caseCollection = reader.Read(stringReader);
            var runner = new TestSessionRunner(config, httpClient, new ConsoleResultWriter());

            // Act
            TestCaseSession result = runner.Run(caseCollection);

            // Assert
            DumpAsYaml(result);
        }
Esempio n. 3
0
        public void should_do_something()
        {
            // Arrange
            var stringBuilder = new StringBuilder();
            var httpLogWriter = new HttpLogWriter(new StringWriter(stringBuilder));
            var httpClient = new HttpClient(httpLogWriter, new RestClient());

            var config = new Config();

            string xml = TestHelpers.ReadEmbeddedFile("wikipedia-simple.xml", XmlExamplesFolder);
            var stringReader = new StringReader(xml);
            var reader = new LegacyTestCaseReader();
            var caseCollection = reader.Read(stringReader);

            var runner = new TestSessionRunner(config, httpClient, new ConsoleResultWriter());

            // Act
            runner.Run(caseCollection);

            // Assert
            Console.WriteLine(stringBuilder);
        }
        public void Run_should_set_MinResponseTime_and_MaxResponseTime_from_http_response_times()
        {
            // Arrange
            var config = new Config();
            var stringReader = new StringReader("");
            var testCaseReader = new TestCaseReaderMock();

            var response = new HttpResponse();
            response.ResponseTime = TimeSpan.FromSeconds(5);

            HttpClientMock httpClient = new HttpClientMock(response);
            httpClient.ResponseTimes = new List<TimeSpan>()
            {
                // Deliberately mixed up order
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(88),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(10)
            };
            httpClient.Response = response;

            IResultWriter resultWriter = new ResultWriterStub();
            var runner = new TestSessionRunner(config, httpClient, resultWriter);

            var caseCollection = CreateCaseCollection(new[]
            {
                new Case() { Url = "foo1" },
                new Case() { Url = "foo2" },
                new Case() { Url = "foo3" },
                new Case() { Url = "foo4" },
            });

            // Act
            TestCaseSession session = runner.Run(caseCollection);

            // Assert
            Assert.That(session.MinResponseTime, Is.EqualTo(TimeSpan.FromSeconds(3)));
            Assert.That(session.MaxResponseTime, Is.EqualTo(TimeSpan.FromSeconds(88)));
        }
Esempio n. 5
0
        public void should_post()
        {
            // Arrange
            //_streamWriter = new StreamWriter(new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write));
            var stringBuilder = new StringBuilder();
            var stringWriter = new StringWriter(stringBuilder);

            var config = new Config();
            config.GlobalHttpLog = LogType.All;
            var httpClient = new HttpClient(new HttpLogWriter(stringWriter), new RestClient());

            var resultWriter = new TextResultWriter(stringWriter);

            string xml = TestHelpers.ReadEmbeddedFile("roadkill-login.xml", XmlExamplesFolder);
            var stringReader = new StringReader(xml);
            var reader = new TestCaseReader();

            var runner = new TestSessionRunner(config, httpClient, resultWriter);
            var caseCollection = reader.Read(stringReader);

            // Act
            TestCaseSession session = runner.Run(caseCollection);

            // Assert
            DumpAsXml(session);
            DumpAsYaml(session);

            Console.WriteLine(stringBuilder);
        }
        /// <summary>
        /// Starts the test case XML file run.
        /// </summary>
        internal void StartSession(SessionRunnerTaskInfo item)
        {
            try
            {
                // TODO: this run could be for a user run only, not the entire team (read the XML from their folder?)
                string username = item.Username;
                string teamName = item.TeamName;

                // Read in the XML file from the team folder, e.g. "c:\testcases\myteam\test1.xml"
                string fullPath = Path.Combine(_appConfig.TestCasesBaseDirectory, teamName, item.Request.Filename);
                string xml = File.ReadAllText(fullPath);

                using (var stringReader = new StringReader(xml))
                {
                    var testCaseReader = new TestCaseReader();
                    CaseCollection caseCollection = testCaseReader.Read(stringReader);
                    var config = new Config();
                    var logStringBuilder = new StringBuilder();
                    var httpLogWriter = new HttpLogWriter(new StringWriter(logStringBuilder));
                    var httpClient = new HttpClient(httpLogWriter, new RestClient());

                    var runner = new TestSessionRunner(config, httpClient, new TextFileResultWriter());
                    item.Runner = runner;
                    runner.Run(caseCollection);
                }
            }
            catch (Exception e)
            {
                item.Errors = e.ToString();
            }
        }