Esempio n. 1
0
        public void Check_CallsMissingPage_Returns404StatusCode()
        {
            var check = new Check { Url = "http://httpstat.us/404" };

            _requester.Check(check);

            Assert.That(check.Status, Is.EqualTo(404));
        }
Esempio n. 2
0
        public void Check_CallsExistingPage_Returns200StatusCode()
        {
            var check = new Check { Url = "http://httpstat.us/200" };

            _requester.Check(check);

            Assert.That(check.Status, Is.EqualTo(Check.Ok));
        }
Esempio n. 3
0
        public void Check_CallsExistingPage_ReturnsCorrectContent()
        {
            var check = new Check { Url = "http://httpstat.us/200" };

            _requester.Check(check);

            AssertContainsString("200 OK", check.Source);
        }
Esempio n. 4
0
 private static void WriteToConsoleInColour(Check check, string passed, ConsoleColor textColour)
 {
     // this is necessary as this can get called by multiple threads and it can cause the colours to get output incorrectly
     lock (LockObject)
     {
         Console.ForegroundColor = textColour;
         WriteToConsole(check, passed);
         Console.ForegroundColor = _originalTextColour;
     }
 }
Esempio n. 5
0
        public void Log(Check check)
        {
            var passed = (check.Passed()) ? "Passed" : "Failed";

            if (check.Passed())
            {
                WritePass(check, passed);
            }
            else
            {
                WriteFail(check, passed);
            }
        }
Esempio n. 6
0
 private static void RunCheck(Check check)
 {
     var request = (HttpWebRequest) WebRequest.Create(check.Url);
     request.Timeout = 10000;
     HttpWebResponse response = null;
     try
     {
         response = ParseRequest(request, check);
     }
     finally
     {
         if (response != null) response.Close();
     }
 }
Esempio n. 7
0
        public void Passed_WhenStatusCodeIs200AndAContentMatchPasses_ThenReturnTrue()
        {
            var check = new Check
            {
                Status = Check.Ok,
                Source = "This is the test source containing a match.",
                ContentMatches = new List<ContentMatch>
                        {
                            new ContentMatch
                                {
                                    Match = "match",
                                    Required = true
                                }
                        }
            };

            Assert.That(check.Passed(), Is.True);
        }
Esempio n. 8
0
        public void Passed_WhenStatusCodeIs200AndANegativeContentMatchFails_ThenReturnTrue()
        {
            var check = new Check
            {
                Status = Check.Ok,
                Source = "This is the test source.",
                ContentMatches = new List<ContentMatch>
                        {
                            new ContentMatch
                                {
                                    Match = "match",
                                    Required = false
                                }
                        }
            };

            Assert.That(check.Passed(), Is.True);
        }
Esempio n. 9
0
        public void Close_WhenACheckFailsButEventuallyPasses_ThenItShouldNotGetLogged()
        {
            const string passingUrl = "http://www.google.com/";
            const string failingUrl = "http://www.yahoo.com/";

            var helper = new Mock<IFileHelper>();
            helper.Setup(m => m.CreateFile(It.IsAny<string>()));
            helper.Setup(m => m.FileExists(It.IsAny<string>())).Returns(false);
            helper.Setup(m => m.WriteLine(It.IsAny<string>(), It.IsAny<string>()));

            var logger = new FileLogger(helper.Object);

            var check = new Check
            {
                Url = passingUrl,
                Status = 500
            };

            logger.Log(check);

            check.Status = Check.Ok;

            logger.Log(check);

            var failedCheck = new Check
                {
                    Url = failingUrl,
                    Status = 500
                };

            logger.Log(failedCheck);

            logger.Close();

            helper.Verify(f => f.FileExists(It.IsAny<string>()), Times.Once());
            helper.Verify(f => f.CreateFile(It.IsAny<string>()), Times.Once());
            helper.Verify(f => f.WriteLine(It.IsAny<string>(), failingUrl), Times.Once());
            helper.Verify(f => f.WriteLine(It.IsAny<string>(), passingUrl), Times.Never());
        }
Esempio n. 10
0
        private static HttpWebResponse ParseRequest(WebRequest request, Check check)
        {
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException e)
            {
                response = ((HttpWebResponse)e.Response);
            }

            if (response == null)
            {
                check.Status = 500;
            }
            else
            {
                check.Status = (int)response.StatusCode;
                check.Source = GetSource(response);
            }

            return response;
        }
Esempio n. 11
0
 private static void WritePass(Check check, string passed)
 {
     WriteToConsoleInColour(check, passed, SuccessTextColour);
 }
Esempio n. 12
0
        public void Close_WhenThereIsOneCheckWhichFailedButEventuallyPassed_ThenItShouldNotCreateTheFile()
        {
            var helper = new Mock<IFileHelper>();
            helper.Setup(m => m.CreateFile(It.IsAny<string>()));
            helper.Setup(m => m.FileExists(It.IsAny<string>())).Returns(false);
            helper.Setup(m => m.WriteLine(It.IsAny<string>(), It.IsAny<string>()));

            var logger = new FileLogger(helper.Object);

            var check = new Check
                {
                    Url = "http://www.google.com/",
                    Status = 500
                };

            logger.Log(check);

            check.Status = Check.Ok;

            logger.Log(check);

            logger.Close();

            helper.Verify(f => f.FileExists(It.IsAny<string>()), Times.Never());
            helper.Verify(f => f.CreateFile(It.IsAny<string>()), Times.Never());
            helper.Verify(f => f.WriteLine(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }
Esempio n. 13
0
 public void Check(Check check)
 {
     RunCheck(check);
 }
Esempio n. 14
0
        public void Passed_WhenStatusCodeIsNot200_ThenReturnFalse()
        {
            var check = new Check
            {
                Status = 500
            };

            Assert.That(check.Passed(), Is.False);
        }
Esempio n. 15
0
        public void Passed_WhenStatusCodeIs200AndThereAreNoContentChecks_ThenReturnTrue()
        {
            var check = new Check
                {
                    Status = Check.Ok
                };

            Assert.That(check.Passed(), Is.True);
        }
Esempio n. 16
0
 private static void WriteFail(Check check, string passed)
 {
     WriteToConsoleInColour(check, passed, ErrorTextColour);
 }
Esempio n. 17
0
 private static void WriteContentFail(Check check, string passed)
 {
     WriteToConsoleInColour(check, passed, ContentFailTextColour);
 }
Esempio n. 18
0
 private void AddCheck(string line)
 {
     var check = new Check {Url = line.Trim()};
     _checks.Add(check);
 }
Esempio n. 19
0
 private static void WriteToConsole(Check check, string passed)
 {
     Console.WriteLine("{0}: {1} - {2}", check.Status, check.Url, passed);
 }