Skip to content

Commit

Permalink
Added extension and improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Sep 7, 2019
1 parent 7411a6c commit 40b1eac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/AngleSharp.Io.Tests/Integration/DownloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public async Task StandardDownloadBinary()
var document = await context.OpenAsync(req => req.Content("<a href=\"http://example.com/setup.exe\">Download setup</a>"));
var linkedDownload = await document.QuerySelector<IHtmlAnchorElement>("a").NavigateAsync();

Assert.AreEqual("setup.exe", downloadSeen);
Assert.IsNull(linkedDownload);
Assert.AreEqual(document, context.Active);
Assert.AreEqual("setup.exe", downloadSeen);
}
}
}
3 changes: 1 addition & 2 deletions src/AngleSharp.Io.Tests/Network/FileRequesterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public async Task FollowLinkToUseFileRequesterUsingStandardRequesters()
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(res => res.Content("<a href='" + url + "'>Download</a>"));
var result = await document.QuerySelector<IHtmlAnchorElement>("a").NavigateAsync();
var content = result.Body.TextContent;
Assert.AreEqual(0, content.Length);
Assert.IsNull(result);
}
}
}
5 changes: 2 additions & 3 deletions src/AngleSharp.Io.Tests/Network/FtpRequesterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AngleSharp.Io.Tests.Network
namespace AngleSharp.Io.Tests.Network
{
using AngleSharp.Dom;
using AngleSharp.Html.Dom;
Expand Down Expand Up @@ -43,8 +43,7 @@ public async Task FollowLinkToUseFtpRequesterUsingStandardRequesters()
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(res => res.Content("<a href='ftp://ftp.funet.fi/pub/standards/w3/TR/2003/xhtml2-20030506/attributes.html'>Download</a>"));
var result = await document.QuerySelector<IHtmlAnchorElement>("a").NavigateAsync();
var content = result.Body.TextContent;
Assert.AreEqual(0, content.Length);
Assert.IsNull(result);
}
}
}
17 changes: 15 additions & 2 deletions src/AngleSharp.Io/IoConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public static IConfiguration WithDownload(this IConfiguration configuration, Fun
{
var oldFactory = configuration.Services.OfType<IDocumentFactory>().FirstOrDefault();
var newFactory = new DownloadFactory(oldFactory, download);
return configuration.WithOnly<IDocumentFactory>(newFactory);
return configuration.WithDefaultLoader(new LoaderOptions
{
Filter = req => false,
}).WithOnly<IDocumentFactory>(newFactory);
}

/// <summary>
Expand Down Expand Up @@ -133,6 +136,16 @@ public static IConfiguration WithPersistentCookies(this IConfiguration configura
public static IConfiguration WithTemporaryCookies(this IConfiguration configuration) =>
configuration.WithCookies(new MemoryFileHandler());

/// <summary>
/// Registers a non-persistent advanced cookie container using the memory-only file
/// handler.
/// Alias for WithTemporaryCookies().
/// </summary>
/// <param name="configuration">The configuration to extend.</param>
/// <returns>The new instance with the service.</returns>
public static IConfiguration WithCookies(this IConfiguration configuration) =>
configuration.WithTemporaryCookies();

/// <summary>
/// Registers the advanced cookie service.
/// </summary>
Expand All @@ -149,7 +162,7 @@ public static IConfiguration WithCookies(this IConfiguration configuration, ICoo
/// <param name="provider">The provider for cookie interactions.</param>
/// <returns>The new instance with the service.</returns>
public static IConfiguration WithCookies(this IConfiguration configuration, ICookieProvider provider) =>
configuration.WithOnly<ICookieProvider>(provider);
configuration.WithOnly(provider);

#endregion
}
Expand Down

0 comments on commit 40b1eac

Please sign in to comment.