From 40b1eac2a4b81accbf43f759c2cae81d5587f6c5 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sat, 7 Sep 2019 02:05:40 +0200 Subject: [PATCH] Added extension and improved tests --- .../Integration/DownloadTests.cs | 2 +- .../Network/FileRequesterTests.cs | 3 +-- .../Network/FtpRequesterTests.cs | 5 ++--- src/AngleSharp.Io/IoConfigurationExtensions.cs | 17 +++++++++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/AngleSharp.Io.Tests/Integration/DownloadTests.cs b/src/AngleSharp.Io.Tests/Integration/DownloadTests.cs index 7ca906a..5540f5a 100644 --- a/src/AngleSharp.Io.Tests/Integration/DownloadTests.cs +++ b/src/AngleSharp.Io.Tests/Integration/DownloadTests.cs @@ -67,9 +67,9 @@ public async Task StandardDownloadBinary() var document = await context.OpenAsync(req => req.Content("Download setup")); var linkedDownload = await document.QuerySelector("a").NavigateAsync(); - Assert.AreEqual("setup.exe", downloadSeen); Assert.IsNull(linkedDownload); Assert.AreEqual(document, context.Active); + Assert.AreEqual("setup.exe", downloadSeen); } } } diff --git a/src/AngleSharp.Io.Tests/Network/FileRequesterTests.cs b/src/AngleSharp.Io.Tests/Network/FileRequesterTests.cs index 22a81f4..edfbcef 100644 --- a/src/AngleSharp.Io.Tests/Network/FileRequesterTests.cs +++ b/src/AngleSharp.Io.Tests/Network/FileRequesterTests.cs @@ -55,8 +55,7 @@ public async Task FollowLinkToUseFileRequesterUsingStandardRequesters() var context = BrowsingContext.New(config); var document = await context.OpenAsync(res => res.Content("Download")); var result = await document.QuerySelector("a").NavigateAsync(); - var content = result.Body.TextContent; - Assert.AreEqual(0, content.Length); + Assert.IsNull(result); } } } diff --git a/src/AngleSharp.Io.Tests/Network/FtpRequesterTests.cs b/src/AngleSharp.Io.Tests/Network/FtpRequesterTests.cs index 33f0079..351da6d 100644 --- a/src/AngleSharp.Io.Tests/Network/FtpRequesterTests.cs +++ b/src/AngleSharp.Io.Tests/Network/FtpRequesterTests.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Io.Tests.Network +namespace AngleSharp.Io.Tests.Network { using AngleSharp.Dom; using AngleSharp.Html.Dom; @@ -43,8 +43,7 @@ public async Task FollowLinkToUseFtpRequesterUsingStandardRequesters() var context = BrowsingContext.New(config); var document = await context.OpenAsync(res => res.Content("Download")); var result = await document.QuerySelector("a").NavigateAsync(); - var content = result.Body.TextContent; - Assert.AreEqual(0, content.Length); + Assert.IsNull(result); } } } diff --git a/src/AngleSharp.Io/IoConfigurationExtensions.cs b/src/AngleSharp.Io/IoConfigurationExtensions.cs index 48c0ed6..1aa36f3 100644 --- a/src/AngleSharp.Io/IoConfigurationExtensions.cs +++ b/src/AngleSharp.Io/IoConfigurationExtensions.cs @@ -30,7 +30,10 @@ public static IConfiguration WithDownload(this IConfiguration configuration, Fun { var oldFactory = configuration.Services.OfType().FirstOrDefault(); var newFactory = new DownloadFactory(oldFactory, download); - return configuration.WithOnly(newFactory); + return configuration.WithDefaultLoader(new LoaderOptions + { + Filter = req => false, + }).WithOnly(newFactory); } /// @@ -133,6 +136,16 @@ public static IConfiguration WithPersistentCookies(this IConfiguration configura public static IConfiguration WithTemporaryCookies(this IConfiguration configuration) => configuration.WithCookies(new MemoryFileHandler()); + /// + /// Registers a non-persistent advanced cookie container using the memory-only file + /// handler. + /// Alias for WithTemporaryCookies(). + /// + /// The configuration to extend. + /// The new instance with the service. + public static IConfiguration WithCookies(this IConfiguration configuration) => + configuration.WithTemporaryCookies(); + /// /// Registers the advanced cookie service. /// @@ -149,7 +162,7 @@ public static IConfiguration WithCookies(this IConfiguration configuration, ICoo /// The provider for cookie interactions. /// The new instance with the service. public static IConfiguration WithCookies(this IConfiguration configuration, ICookieProvider provider) => - configuration.WithOnly(provider); + configuration.WithOnly(provider); #endregion }