public async Task HandlesBadCalls() { var restClientMock = Substitute.For <IRestClient>(); restClientMock.GetAsync(callUri).Throws(new RestRequestFailedException()); var sut = new WebPageParser(restClientMock); var result = await sut.ParsePage(callUri.OriginalString); Assert.That(result, Is.TypeOf(typeof(WebPage))); Assert.That(result.PageUrl.OriginalString, Is.EqualTo(absoluteUri)); Assert.That(result.Links.Count, Is.EqualTo(0)); Assert.That(result.WasCrawled, Is.True); Assert.That(result.DeadLink, Is.True); await restClientMock.Received(1).GetAsync(Arg.Any <Uri>()); }
public async Task CorrectlyParsesAPageWithNoLink() { var restClientMock = Substitute.For <IRestClient>(); restClientMock.GetAsync(callUri).Returns(@"<html><body><h1>No Links!!</h1></body></html>"); var sut = new WebPageParser(restClientMock); var result = await sut.ParsePage(callUri.OriginalString); Assert.That(result, Is.TypeOf(typeof(WebPage))); Assert.That(result.PageUrl.OriginalString, Is.EqualTo(absoluteUri)); Assert.That(result.Links.Count, Is.EqualTo(0)); Assert.That(result.WasCrawled, Is.True); Assert.That(result.DeadLink, Is.False); await restClientMock.Received(1).GetAsync(Arg.Any <Uri>()); }
public async Task CorrectlyParsesAPageWithLinksToElements() { var restClientMock = Substitute.For <IRestClient>(); restClientMock.GetAsync(callUri).Returns(@"<a href=""testsite.com/path"">stuff</a><a href=""testsite.com/path#1"">stuff</a><a href=""#element"">stuff</a>"); var sut = new WebPageParser(restClientMock); var result = await sut.ParsePage(callUri.OriginalString); Assert.That(result, Is.TypeOf(typeof(WebPage))); Assert.That(result.PageUrl.OriginalString, Is.EqualTo(absoluteUri)); Assert.That(result.Links.Count, Is.EqualTo(2)); Assert.That(result.WasCrawled, Is.True); Assert.That(result.DeadLink, Is.False); await restClientMock.Received(1).GetAsync(Arg.Any <Uri>()); }