コード例 #1
0
        public void TestXmlStringWriter()
        {
            var memoryStream = new MemoryStream();


            var writer = new WebTestXmlWriter();

            writer.Write(memoryStream, _testRun);

            var actual = Encoding.UTF8.GetString(memoryStream.ToArray());

            Assert.AreEqual(ResultsXml, actual, true);
        }
コード例 #2
0
        public void GenerateTests()
        {
            var creationTimestamp = DateTime.Now;
            // Sets up crawlers.
            List <Crawler> crawlers = new List <Crawler>();

            foreach (BrowserConfigElement browserConfig in Config.Browsers)
            {
                Browser browser = new Browser(browserConfig, Config.NetworkCredentials);

                Crawler crawler = new Crawler(Config.Seeds, browser, Config.RecursionLimit);
                crawlers.Add(crawler);
            }

            // Start crawling.
            var results = new List <HttpRequestResult>();

            foreach (var crawler in crawlers)
            {
                crawler.Crawl();
                results.AddRange(crawler.HttpRequestResults);
            }

            var startTime = DateTime.Now;

            // Creates the test results and writes them to a file.
            var file = new FileInfo(Config.TestResultsFile);

            if (file.Exists)
            {
                file.Delete();
            }
            var writer = new WebTestXmlWriter();

            var finishTimestamp = DateTime.Now;

            var testRun = (new TestResultsFactory()).GenerateTestRun(Config.Name,
                                                                     Config.Description,
                                                                     startTime,
                                                                     finishTimestamp,
                                                                     creationTimestamp,
                                                                     startTime,
                                                                     results);

            var streamWriter = file.CreateText();

            writer.Write(streamWriter, testRun);
            streamWriter.Flush();
            streamWriter.Close();
        }
コード例 #3
0
        public void TestResultsFactory()
        {
            var file = new FileInfo("factory-results-file.xml");

            if (file.Exists)
            {
                file.Delete();
            }

            var writer = new WebTestXmlWriter();

            var testRun = (new TestResultsFactory()).GenerateTestRun("Test Unit .com", "Unit testing", DateTime.Now,
                                                                     DateTime.Now.Add(new TimeSpan(0, 0, 23)),
                                                                     DateTime.Now, DateTime.Now,
                                                                     new List <HttpRequestResult>()
            {
                new HttpRequestResult()
                {
                    RequestUrl  = new Uri("http://allegra.co"),
                    ResultUrl   = new Uri("http://allegra.com"),
                    Start       = DateTime.Now,
                    End         = DateTime.Now,
                    Error       = null,
                    BrowserUsed = new Browser()
                },
                new HttpRequestResult()
                {
                    RequestUrl = new Uri("http://allegra.co"),
                    ResultUrl  = new Uri("http://allegra.com"),
                    Start      = DateTime.Now,
                    End        = DateTime.Now,
                    Error      = new HttpValidationError()
                    {
                        AbsoluteUri = new Uri("http://allegra.co"),
                        HttpCode    = 404,
                        Message     = "File not found!"
                    },
                    BrowserUsed = new Browser()
                }
            });

            writer.Write(file.CreateText(), testRun);
        }
コード例 #4
0
        public void TestFileWrite()
        {
            var file = new FileInfo("results-file.xml");

            if (file.Exists)
            {
                file.Delete();
            }

            var writer = new WebTestXmlWriter();



            writer.Write(file.CreateText(), _testRun);

            file = new FileInfo("results-file.xml");
            Assert.IsTrue(file.Exists, "File was not created");
            Assert.IsTrue(file.Length > 0, "File is empty");
        }