wabbajack/Wabbajack.Server.Test/ModFileTests.cs

63 lines
1.9 KiB
C#
Raw Normal View History

2020-06-21 22:03:54 +00:00
using System;
using System.Linq;
2020-06-21 22:03:54 +00:00
using System.Threading.Tasks;
using Wabbajack.BuildServer.Test;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Server.DataLayer;
using Wabbajack.Server.DTOs;
2020-06-21 22:03:54 +00:00
using Xunit;
using Xunit.Abstractions;
namespace Wabbajack.Server.Test
{
public class ModFileTests : ABuildServerSystemTest
{
public ModFileTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
{
}
[Fact]
public async Task CanGetDownloadStates()
{
var sql = Fixture.GetService<SqlService>();
var hash = Hash.FromBase64("eSIyd+KOG3s=");
2020-06-21 22:03:54 +00:00
var archive =
2021-02-06 18:53:59 +00:00
new Archive(new HTTPDownloader.State(
"https://build.wabbajack.org/WABBAJACK_TEST_FILE.txt"))
2020-06-21 22:03:54 +00:00
{
Size = 20, Hash = hash
2020-06-21 22:03:54 +00:00
};
await sql.EnqueueDownload(archive);
await sql.UpsertMirroredFile(new MirroredFile()
{
Created = DateTime.UtcNow,
Uploaded = DateTime.UtcNow,
Hash = hash,
Rationale = "Test File"
});
2020-06-21 22:03:54 +00:00
var dld = await sql.GetNextPendingDownload();
await dld.Finish(sql);
var state = await ClientAPI.InferDownloadState(archive.Hash);
2021-02-06 18:53:59 +00:00
Assert.NotNull(state);
2020-06-21 22:03:54 +00:00
Assert.Equal(archive.State.GetMetaIniString(), state!.GetMetaIniString());
var archives = await (await ClientAPI.GetClient()).GetJsonAsync<Archive[]>(
$"{Consts.WabbajackBuildServerUri}mod_files/by_hash/{hash.ToHex()}");
Assert.True(archives.Length >= 2);
Assert.NotNull(archives.FirstOrDefault(a => a.State is WabbajackCDNDownloader.State));
await sql.DeleteMirroredFile(hash);
2020-06-21 22:03:54 +00:00
}
}
}