Example #1
0
        async Task TestCustomInstalls(CancellationToken cancellationToken)
        {
            var byondInstaller = new PlatformIdentifier().IsWindows
                                ? (IByondInstaller) new WindowsByondInstaller(
                Mock.Of <IProcessExecutor>(),
                new DefaultIOManager(),
                Mock.Of <ILogger <WindowsByondInstaller> >())
                                : new PosixByondInstaller(
                Mock.Of <IPostWriteHandler>(),
                new DefaultIOManager(),
                Mock.Of <ILogger <PosixByondInstaller> >());

            // get the bytes for stable
            using var stableBytesMs = new MemoryStream(
                      await byondInstaller.DownloadVersion(TestVersion, cancellationToken));

            var test = await byondClient.SetActiveVersion(
                new ByondVersionRequest
            {
                Version         = TestVersion,
                UploadCustomZip = true
            },
                stableBytesMs,
                cancellationToken)
                       .ConfigureAwait(false);

            Assert.IsNotNull(test.InstallJob);
            await WaitForJob(test.InstallJob, 60, false, null, cancellationToken).ConfigureAwait(false);

            var newSettings = await byondClient.ActiveVersion(cancellationToken);

            Assert.AreEqual(new Version(TestVersion.Major, TestVersion.Minor, 1), newSettings.Version);

            // test a few switches
            var installResponse = await byondClient.SetActiveVersion(new ByondVersionRequest
            {
                Version = TestVersion
            }, null, cancellationToken);

            Assert.IsNull(installResponse.InstallJob);
            await ApiAssert.ThrowsException <ApiConflictException>(() => byondClient.SetActiveVersion(new ByondVersionRequest
            {
                Version = new Version(TestVersion.Major, TestVersion.Minor, 2)
            }, null, cancellationToken), ErrorCode.ByondNonExistentCustomVersion);

            installResponse = await byondClient.SetActiveVersion(new ByondVersionRequest
            {
                Version = new Version(TestVersion.Major, TestVersion.Minor, 1)
            }, null, cancellationToken);

            Assert.IsNull(installResponse.InstallJob);
        }