public async Task ImportPageWithIndirectCycle() { var content = "<!doctype html><link rel=import href=http://example.com/test.html>"; var nested = new Queue <String>(new [] { "<!doctype html><link rel=import href=http://example.com/foo.html>", "<!doctype html><link rel=import href=http://example.com/bar.html>", "<!doctype html><link rel=import href=http://example.com/test.html>", "<!doctype html><link rel=import href=http://example.com/foo.html>" }); var requester = new MockRequester(); var requestCount = 0; requester.OnRequest = request => requestCount++; requester.BuildResponse(request => nested.Dequeue()); var config = Configuration.Default.WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true, new[] { requester }); var document = await BrowsingContext.New(config).OpenAsync(m => m.Content(content)); var link = document.QuerySelector <IHtmlLinkElement>("link"); Assert.AreEqual("import", link.Relation); Assert.IsNotNull(link.Import); Assert.AreEqual(3, requestCount); }
public static IConfiguration WithMockRequester(this IConfiguration config, MockRequester mockRequester) { return(config.WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true, new[] { mockRequester })); }
private static Task<IDocument> LoadDocumentWithFakeRequesterAndCookie(IResponse initialResponse, Func<IRequest, IResponse> onRequest) { var requester = new MockRequester(); requester.BuildResponse(onRequest); var config = Configuration.Default.WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true, new[] { requester }).WithCookies(); return BrowsingContext.New(config).OpenAsync(initialResponse, System.Threading.CancellationToken.None); }