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.
- Loading branch information
Showing
6 changed files
with
250 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Squirrel.Tests.TestHelpers | ||
{ | ||
internal class FakeFixtureRepository : Sources.IFileDownloader | ||
{ | ||
private readonly string _pkgId; | ||
private readonly IEnumerable<ReleaseEntry> _releases; | ||
|
||
public FakeFixtureRepository(string pkgId, bool mockLatestFullVer) | ||
{ | ||
_pkgId = pkgId; | ||
var releases = ReleaseEntry.BuildReleasesFile(IntegrationTestHelper.GetFixturesPath(), false) | ||
.Where(r => r.OriginalFilename.StartsWith(_pkgId)) | ||
.ToList(); | ||
|
||
if (mockLatestFullVer) { | ||
var minFullVer = releases.Where(r => !r.IsDelta).MinBy(r => r.Version); | ||
var maxfullVer = releases.Where(r => !r.IsDelta).MaxBy(r => r.Version).Single(); | ||
var maxDeltaVer = releases.Where(r => r.IsDelta).MaxBy(r => r.Version).Single(); | ||
|
||
// our fixtures don't have a full package for the latest version, we expect the tests to generate this file | ||
if (maxfullVer.Version < maxDeltaVer.Version) { | ||
var name = new ReleaseEntryName(maxfullVer.PackageId, maxDeltaVer.Version, false, maxfullVer.Rid); | ||
releases.Add(new ReleaseEntry("0000000000000000000000000000000000000000", name.ToFileName(), maxfullVer.Filesize)); | ||
} | ||
} | ||
|
||
_releases = releases; | ||
} | ||
|
||
public Task<byte[]> DownloadBytes(string url, string authorization = null, string accept = null) | ||
{ | ||
if (url.Contains("/RELEASES?")) { | ||
MemoryStream ms = new MemoryStream(); | ||
ReleaseEntry.WriteReleaseFile(_releases, ms); | ||
return Task.FromResult(ms.ToArray()); | ||
} | ||
|
||
var rel = _releases.FirstOrDefault(r => url.EndsWith(r.OriginalFilename)); | ||
var filePath = IntegrationTestHelper.GetPath("fixtures", rel.OriginalFilename); | ||
if (!File.Exists(filePath)) { | ||
throw new NotSupportedException("FakeFixtureRepository doesn't have: " + rel.OriginalFilename); | ||
} | ||
|
||
return Task.FromResult(File.ReadAllBytes(filePath)); | ||
} | ||
|
||
public Task DownloadFile(string url, string targetFile, Action<int> progress, string authorization = null, string accept = null) | ||
{ | ||
var rel = _releases.FirstOrDefault(r => url.EndsWith(r.OriginalFilename)); | ||
var filePath = IntegrationTestHelper.GetPath("fixtures", rel.OriginalFilename); | ||
if (!File.Exists(filePath)) { | ||
throw new NotSupportedException("FakeFixtureRepository doesn't have: " + rel.OriginalFilename); | ||
} | ||
|
||
File.Copy(filePath, targetFile); | ||
progress(25); | ||
progress(50); | ||
progress(75); | ||
progress(100); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<string> DownloadString(string url, string authorization = null, string accept = null) | ||
{ | ||
if (!url.Contains("/RELEASES?")) { | ||
throw new NotImplementedException(); | ||
} | ||
MemoryStream ms = new MemoryStream(); | ||
ReleaseEntry.WriteReleaseFile(_releases, ms); | ||
return Task.FromResult(Encoding.UTF8.GetString(ms.ToArray())); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.