private async Task UpdateAborted() { var(_, storageMod, eventBus) = CreateStorageMod(); var repo = CreateRepoMod(); eventBus.Work(100, () => storageMod.GetState() != StorageModStateEnum.Loading); var targetMatchHash = await MatchHash.CreateAsync(repo, CancellationToken.None); var targetVersionHash = await VersionHash.CreateAsync(repo, CancellationToken.None); var cts = new CancellationTokenSource(); var update = storageMod.Update(repo, targetMatchHash, targetVersionHash, null, cts.Token); cts.Cancel(); await update; eventBus.Work(100, () => storageMod.GetState() == StorageModStateEnum.CreatedWithUpdateTarget); Assert.Equal(StorageModStateEnum.CreatedWithUpdateTarget, storageMod.GetState()); Assert.True(targetMatchHash.IsMatch(storageMod.GetMatchHash())); Assert.True(targetVersionHash.IsMatch(storageMod.GetVersionHash())); }
private static async Task <MatchHash> CreateStorageMod(string[] names, string?name) { var storageMod = new MockStorageMod(Task.CompletedTask); AddFiles(storageMod, names, name); return(await MatchHash.CreateAsync(storageMod, CancellationToken.None)); }
private static async Task <MatchHash> CreateRepoMod(string[] names, string?name) { var repoMod = new MockRepositoryMod(); AddFiles(repoMod, names, name); return(await MatchHash.CreateAsync(repoMod, CancellationToken.None)); }
internal static async Task <MatchHash> GetMatchHash(int match) { var mockRepo = new MockRepositoryMod(); for (int i = 0; i < 3; i++) { mockRepo.SetFile($"/addons/{match}_{i}.pbo", i.ToString()); } return(await MatchHash.CreateAsync(mockRepo, CancellationToken.None)); }
private void UpdateWithTarget() { var target = new UpdateTarget("1234"); var(_, storageMod, eventBus) = CreateStorageMod(target); eventBus.Work(100, () => storageMod.GetState() == StorageModStateEnum.CreatedWithUpdateTarget); var repo = CreateRepoMod(); storageMod.Update(repo, MatchHash.CreateEmpty(), VersionHash.CreateEmpty(), null, CancellationToken.None); Assert.Equal(StorageModStateEnum.Updating, storageMod.GetState()); Assert.True((storageMod.GetMatchHash()).IsMatch(MatchHash.CreateEmpty())); Assert.True((storageMod.GetVersionHash()).IsMatch(VersionHash.CreateEmpty())); }
private async Task Updated() { var(_, storageMod, eventBus) = CreateStorageMod(); var repo = CreateRepoMod(); eventBus.Work(100, () => storageMod.GetState() != StorageModStateEnum.Loading); var targetMatchHash = await MatchHash.CreateAsync(repo, CancellationToken.None); var targetVersionHash = await VersionHash.CreateAsync(repo, CancellationToken.None); var update = storageMod.Update(repo, targetMatchHash, targetVersionHash, null, CancellationToken.None); await update; eventBus.Work(100, () => storageMod.GetState() == StorageModStateEnum.Created); Assert.Equal(StorageModStateEnum.Created, storageMod.GetState()); Assert.True(storageMod.GetMatchHash().IsMatch(await MatchHash.CreateAsync(repo, CancellationToken.None))); Assert.True(storageMod.GetVersionHash().IsMatch(await VersionHash.CreateAsync(repo, CancellationToken.None))); }
private async Task ErrorUpdate() { var(implementation, storageMod, eventBus) = CreateStorageMod(); var repo = CreateRepoMod(); eventBus.Work(200, () => storageMod.GetState() != StorageModStateEnum.Loading); var targetMatchHash = await MatchHash.CreateAsync(repo, CancellationToken.None); var targetVersionHash = await VersionHash.CreateAsync(repo, CancellationToken.None); var update = storageMod.Update(repo, targetMatchHash, targetVersionHash, null, CancellationToken.None); implementation.ThrowErrorOpen = true; eventBus.Work(100); var result = await update; eventBus.Work(100, () => storageMod.GetState() == StorageModStateEnum.CreatedWithUpdateTarget); Assert.Equal(UpdateResult.Failed, result); Assert.True(targetMatchHash.IsMatch(storageMod.GetMatchHash())); Assert.True(targetVersionHash.IsMatch(storageMod.GetVersionHash())); }
public Task <UpdateResult> Update(IRepositoryMod repositoryMod, MatchHash targetMatch, VersionHash targetVersion, IProgress <FileSyncStats>?progress, CancellationToken cancellationToken) { throw new NotImplementedException(); }