public void Check_CallsMissingPage_Returns404StatusCode() { var check = new Check { Url = "http://httpstat.us/404" }; _requester.Check(check); Assert.That(check.Status, Is.EqualTo(404)); }
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)); }
public void Check_CallsExistingPage_ReturnsCorrectContent() { var check = new Check { Url = "http://httpstat.us/200" }; _requester.Check(check); AssertContainsString("200 OK", check.Source); }
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; } }
public void Log(Check check) { var passed = (check.Passed()) ? "Passed" : "Failed"; if (check.Passed()) { WritePass(check, passed); } else { WriteFail(check, passed); } }
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(); } }
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); }
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); }
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()); }
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; }
private static void WritePass(Check check, string passed) { WriteToConsoleInColour(check, passed, SuccessTextColour); }
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()); }
public void Check(Check check) { RunCheck(check); }
public void Passed_WhenStatusCodeIsNot200_ThenReturnFalse() { var check = new Check { Status = 500 }; Assert.That(check.Passed(), Is.False); }
public void Passed_WhenStatusCodeIs200AndThereAreNoContentChecks_ThenReturnTrue() { var check = new Check { Status = Check.Ok }; Assert.That(check.Passed(), Is.True); }
private static void WriteFail(Check check, string passed) { WriteToConsoleInColour(check, passed, ErrorTextColour); }
private static void WriteContentFail(Check check, string passed) { WriteToConsoleInColour(check, passed, ContentFailTextColour); }
private void AddCheck(string line) { var check = new Check {Url = line.Trim()}; _checks.Add(check); }
private static void WriteToConsole(Check check, string passed) { Console.WriteLine("{0}: {1} - {2}", check.Status, check.Url, passed); }