public async void BackupDeploymentDoesNotThrowOnFailure()
        {
            ISerde <DeploymentConfigInfo> serde = this.GetSerde();

            string expectedJson   = serde.Serialize(ValidConfigInfo1);
            var    readSecretData = new Dictionary <string, byte[]>
            {
                ["backup.json"] = System.Text.Encoding.UTF8.GetBytes(serde.Serialize(ValidConfigInfo2))
            };
            var readSecret        = new V1Secret(data: readSecretData);
            var replaceSecretData = new Dictionary <string, byte[]>
            {
                ["backup.json"] = System.Text.Encoding.UTF8.GetBytes(expectedJson)
            };
            var replaceSecret = new V1Secret(data: readSecretData);
            var readResponse  = new HttpOperationResponse <V1Secret>()
            {
                Body     = readSecret,
                Response = new HttpResponseMessage(HttpStatusCode.OK)
            };

            var client = new Mock <IKubernetes>(MockBehavior.Strict);

            client.Setup(c => c.ReadNamespacedSecretWithHttpMessagesAsync(DefaultSecretName, DefaultNamespace, It.IsAny <bool?>(), It.IsAny <bool?>(), null, null, It.IsAny <CancellationToken>()))
            .ReturnsAsync(readResponse);
            client.Setup(c => c.ReplaceNamespacedSecretWithHttpMessagesAsync(It.IsAny <V1Secret>(), DefaultSecretName, DefaultNamespace, null, null, null, null, It.IsAny <CancellationToken>()))
            .ThrowsAsync(new HttpOperationException("Not Permitted"));

            var backupSource = new DeploymentSecretBackup(DefaultSecretName, DefaultNamespace, DefaultOwner, serde, client.Object);
            await backupSource.BackupDeploymentConfigAsync(ValidConfigInfo1);

            client.VerifyAll();
        }
        public async void BackupDeploymentConfigReplacesSecret()
        {
            ISerde<DeploymentConfigInfo> serde = this.GetSerde();

            string expectedJson = serde.Serialize(ValidConfigInfo1);
            var readSecretData = new Dictionary<string, byte[]>
            {
                ["backup.json"] = System.Text.Encoding.UTF8.GetBytes(serde.Serialize(ValidConfigInfo2))
            };
            var readSecret = new V1Secret(data: readSecretData);
            var replaceSecretData = new Dictionary<string, byte[]>
            {
                ["backup.json"] = System.Text.Encoding.UTF8.GetBytes(expectedJson)
            };
            var replaceSecret = new V1Secret(data: readSecretData);
            var readResponse = new HttpOperationResponse<V1Secret>()
            {
                Body = readSecret,
                Response = new HttpResponseMessage(HttpStatusCode.OK)
            };
            var replaceResponse = new HttpOperationResponse<V1Secret>()
            {
                Body = replaceSecret,
                Response = new HttpResponseMessage(HttpStatusCode.OK)
            };

            byte[] receivedData = default(byte[]);
            var client = new Mock<IKubernetes>(MockBehavior.Strict);
            client.Setup(c => c.ReadNamespacedSecretWithHttpMessagesAsync(
                    DefaultSecretName,
                    DefaultNamespace,
                    It.IsAny<string>(), // pretty
                    null, // customHeaders
                    It.IsAny<CancellationToken>()))
                .ReturnsAsync(readResponse);
            client.Setup(c => c.ReplaceNamespacedSecretWithHttpMessagesAsync(
                    It.IsAny<V1Secret>(),
                    DefaultSecretName,
                    DefaultNamespace,
                    null, // dryRun
                    null, // fieldmanager
                    null, // pretty
                    null, // customHeaders
                    It.IsAny<CancellationToken>()))
                .Callback((V1Secret body, string name, string namespaceParameter, string dryRun, string fieldManager, string pretty, Dictionary<string, List<string>> customHeaders, CancellationToken cancellationToken) =>
                {
                    Assert.True(body.Data != null);
                    Assert.True(body.Data.TryGetValue("backup.json", out receivedData));
                })
                .ReturnsAsync(replaceResponse);

            var backupSource = new DeploymentSecretBackup(DefaultSecretName, DefaultNamespace, DefaultOwner, serde, client.Object);
            await backupSource.BackupDeploymentConfigAsync(ValidConfigInfo1);

            string backupJson = System.Text.Encoding.UTF8.GetString(receivedData);

            Assert.Equal(expectedJson, backupJson, ignoreCase: true);
            client.VerifyAll();
        }