Files
velopack/test/Velopack.Tests/TestHelpers/FakeDownloader.cs
Kevin Bost e51a3505b6 Implementing Flow tiered rollout in C#
This add support for setting the tiered rollout percentage in vpk
2025-03-03 08:15:37 +00:00

40 lines
1.3 KiB
C#

using System.Text;
using Velopack.Sources;
namespace Velopack.Tests;
public class FakeDownloader : 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; } = [];
public bool WriteMockLocalFile { get; set; } = false;
public Task<byte[]> DownloadBytes(string url, string auth, string acc, double timeout = 30)
{
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, double timeout, CancellationToken token)
{
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, double timeout = 30)
{
return Encoding.UTF8.GetString(await DownloadBytes(url, auth, acc));
}
}