2020-05-09 22:16:16 +00:00
|
|
|
|
using System;
|
2020-05-10 01:35:42 +00:00
|
|
|
|
using System.Linq;
|
2020-05-09 22:16:16 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.AuthorApi;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2020-05-10 01:35:42 +00:00
|
|
|
|
using Wabbajack.Server.DataLayer;
|
2020-05-09 22:16:16 +00:00
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Test
|
|
|
|
|
{
|
|
|
|
|
public class AuthoredFilesTests : ABuildServerSystemTest
|
|
|
|
|
{
|
|
|
|
|
public AuthoredFilesTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanUploadDownloadAndDeleteAuthoredFiles()
|
|
|
|
|
{
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using var file = new TempFile();
|
2020-05-09 22:16:16 +00:00
|
|
|
|
await file.Path.WriteAllBytesAsync(RandomData(Consts.UPLOADED_FILE_BLOCK_SIZE * 4 + Consts.UPLOADED_FILE_BLOCK_SIZE / 3));
|
|
|
|
|
var originalHash = await file.Path.FileHashAsync();
|
|
|
|
|
|
|
|
|
|
var client = await Client.Create(Fixture.APIKey);
|
|
|
|
|
using var queue = new WorkQueue(2);
|
|
|
|
|
var uri = await client.UploadFile(queue, file.Path, (s, percent) => Utils.Log($"({percent}) {s}"));
|
|
|
|
|
|
2020-05-10 01:35:42 +00:00
|
|
|
|
var data = await Fixture.GetService<SqlService>().AllAuthoredFiles();
|
|
|
|
|
Assert.Contains((string)file.Path.FileName, data.Select(f => f.OriginalFileName));
|
|
|
|
|
|
2020-05-10 01:58:01 +00:00
|
|
|
|
var result = await _client.GetStringAsync(MakeURL("authored_files"));
|
|
|
|
|
Assert.Contains((string)file.Path.FileName, result);
|
|
|
|
|
|
2020-05-09 22:16:16 +00:00
|
|
|
|
var state = await DownloadDispatcher.Infer(uri);
|
|
|
|
|
Assert.IsType<WabbajackCDNDownloader.State>(state);
|
|
|
|
|
|
|
|
|
|
await state.Download(new Archive(state) {Name = (string)file.Path.FileName}, file.Path);
|
|
|
|
|
Assert.Equal(originalHash, await file.Path.FileHashAsync());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|