This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
forked from Squirrel/Squirrel.Windows
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in SimpleWebSource and add tests
- Loading branch information
Showing
6 changed files
with
81 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Squirrel.Tests | ||
{ | ||
public class FakeDownloader : Sources.IFileDownloader | ||
{ | ||
public string LastUrl { get; private set; } | ||
public string LastLocalFile { get; private set; } | ||
public string LastAuthHeader { get; private set; } | ||
public string LastAcceptHeader { get; private set; } | ||
public byte[] MockedResponseBytes { get; set; } = new byte[0]; | ||
public bool WriteMockLocalFile { get; set; } = false; | ||
|
||
public Task<byte[]> DownloadBytes(string url, string auth, string acc) | ||
{ | ||
LastUrl = url; | ||
LastAuthHeader = auth; | ||
LastAcceptHeader = acc; | ||
return Task.FromResult(MockedResponseBytes); | ||
} | ||
|
||
public async Task DownloadFile(string url, string targetFile, Action<int> progress, string auth, string acc) | ||
{ | ||
LastLocalFile = targetFile; | ||
var resp = await DownloadBytes(url, auth, acc); | ||
progress?.Invoke(25); | ||
progress?.Invoke(50); | ||
progress?.Invoke(75); | ||
progress?.Invoke(100); | ||
if (WriteMockLocalFile) | ||
File.WriteAllBytes(targetFile, resp); | ||
} | ||
|
||
public async Task<string> DownloadString(string url, string auth, string acc) | ||
{ | ||
return Encoding.UTF8.GetString(await DownloadBytes(url, auth, acc)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters