Skip to content

Commit 40b1eac

Browse files
committed
Added extension and improved tests
1 parent 7411a6c commit 40b1eac

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/AngleSharp.Io.Tests/Integration/DownloadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public async Task StandardDownloadBinary()
6767
var document = await context.OpenAsync(req => req.Content("<a href=\"http://example.com/setup.exe\">Download setup</a>"));
6868
var linkedDownload = await document.QuerySelector<IHtmlAnchorElement>("a").NavigateAsync();
6969

70-
Assert.AreEqual("setup.exe", downloadSeen);
7170
Assert.IsNull(linkedDownload);
7271
Assert.AreEqual(document, context.Active);
72+
Assert.AreEqual("setup.exe", downloadSeen);
7373
}
7474
}
7575
}

src/AngleSharp.Io.Tests/Network/FileRequesterTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public async Task FollowLinkToUseFileRequesterUsingStandardRequesters()
5555
var context = BrowsingContext.New(config);
5656
var document = await context.OpenAsync(res => res.Content("<a href='" + url + "'>Download</a>"));
5757
var result = await document.QuerySelector<IHtmlAnchorElement>("a").NavigateAsync();
58-
var content = result.Body.TextContent;
59-
Assert.AreEqual(0, content.Length);
58+
Assert.IsNull(result);
6059
}
6160
}
6261
}

src/AngleSharp.Io.Tests/Network/FtpRequesterTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Tests.Network
1+
namespace AngleSharp.Io.Tests.Network
22
{
33
using AngleSharp.Dom;
44
using AngleSharp.Html.Dom;
@@ -43,8 +43,7 @@ public async Task FollowLinkToUseFtpRequesterUsingStandardRequesters()
4343
var context = BrowsingContext.New(config);
4444
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>"));
4545
var result = await document.QuerySelector<IHtmlAnchorElement>("a").NavigateAsync();
46-
var content = result.Body.TextContent;
47-
Assert.AreEqual(0, content.Length);
46+
Assert.IsNull(result);
4847
}
4948
}
5049
}

src/AngleSharp.Io/IoConfigurationExtensions.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public static IConfiguration WithDownload(this IConfiguration configuration, Fun
3030
{
3131
var oldFactory = configuration.Services.OfType<IDocumentFactory>().FirstOrDefault();
3232
var newFactory = new DownloadFactory(oldFactory, download);
33-
return configuration.WithOnly<IDocumentFactory>(newFactory);
33+
return configuration.WithDefaultLoader(new LoaderOptions
34+
{
35+
Filter = req => false,
36+
}).WithOnly<IDocumentFactory>(newFactory);
3437
}
3538

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

139+
/// <summary>
140+
/// Registers a non-persistent advanced cookie container using the memory-only file
141+
/// handler.
142+
/// Alias for WithTemporaryCookies().
143+
/// </summary>
144+
/// <param name="configuration">The configuration to extend.</param>
145+
/// <returns>The new instance with the service.</returns>
146+
public static IConfiguration WithCookies(this IConfiguration configuration) =>
147+
configuration.WithTemporaryCookies();
148+
136149
/// <summary>
137150
/// Registers the advanced cookie service.
138151
/// </summary>
@@ -149,7 +162,7 @@ public static IConfiguration WithCookies(this IConfiguration configuration, ICoo
149162
/// <param name="provider">The provider for cookie interactions.</param>
150163
/// <returns>The new instance with the service.</returns>
151164
public static IConfiguration WithCookies(this IConfiguration configuration, ICookieProvider provider) =>
152-
configuration.WithOnly<ICookieProvider>(provider);
165+
configuration.WithOnly(provider);
153166

154167
#endregion
155168
}

0 commit comments

Comments
 (0)