예제 #1
0
        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()));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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()));
        }
예제 #6
0
        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)));
        }
예제 #7
0
        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()));
        }
예제 #8
0
 public Task <UpdateResult> Update(IRepositoryMod repositoryMod, MatchHash targetMatch, VersionHash targetVersion, IProgress <FileSyncStats>?progress,
                                   CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }