public async void FileBackupReadFromBackupCallsEncryptDecrypt() { if (File.Exists(this.tempFileName)) { File.Delete(this.tempFileName); } ISerde <DeploymentConfigInfo> serde = this.GetSerde(); var encryptionProvider = new Mock <IEncryptionProvider>(); encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>())) .ReturnsAsync(serde.Serialize(ValidConfigInfo1)); encryptionProvider.Setup(ep => ep.DecryptAsync(It.IsAny <string>())) .ReturnsAsync(serde.Serialize(ValidConfigInfo1)); IDeploymentBackupSource fileBackup = new DeploymentFileBackup(this.tempFileName, serde, encryptionProvider.Object); await fileBackup.BackupDeploymentConfigAsync(ValidConfigInfo1); DeploymentConfigInfo config1 = await fileBackup.ReadFromBackupAsync(); Assert.NotNull(config1); Assert.True(File.Exists(this.tempFileName)); string backupJson = await DiskFile.ReadAllAsync(this.tempFileName); string returnedJson = serde.Serialize(config1); string expectedJson = serde.Serialize(ValidConfigInfo1); Assert.Equal(expectedJson, backupJson, ignoreCase: true); Assert.Equal(expectedJson, returnedJson, ignoreCase: true); encryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>())); encryptionProvider.Verify(ep => ep.DecryptAsync(It.IsAny <string>())); }
public async void FileBackupDoesNotHappenIfConfigSourceReportsException() { if (File.Exists(this.tempFileName)) { File.Delete(this.tempFileName); } // Arrange var exceptionDeployment = new DeploymentConfigInfo(10, new InvalidOperationException()); ISerde <DeploymentConfigInfo> serde = this.GetSerde(); // Act IDeploymentBackupSource fileBackup = new DeploymentFileBackup(this.tempFileName, serde, NullEncryptionProvider.Instance); await fileBackup.BackupDeploymentConfigAsync(exceptionDeployment); // Assert Assert.False(File.Exists(this.tempFileName)); }
public async void FileBackupSuccessWhenFileNotExists() { if (File.Exists(this.tempFileName)) { File.Delete(this.tempFileName); } ISerde <DeploymentConfigInfo> serde = this.GetSerde(); IDeploymentBackupSource fileBackup = new DeploymentFileBackup(this.tempFileName, serde, NullEncryptionProvider.Instance); await fileBackup.BackupDeploymentConfigAsync(ValidConfigInfo1); Assert.True(File.Exists(this.tempFileName)); string backupJson = await DiskFile.ReadAllAsync(this.tempFileName); string expectedJson = serde.Serialize(ValidConfigInfo1); Assert.Equal(expectedJson, backupJson, ignoreCase: true); }
public async void FileBackupDoesnotThrowWhenEncryptFails() { if (File.Exists(this.tempFileName)) { File.Delete(this.tempFileName); } ISerde <DeploymentConfigInfo> serde = this.GetSerde(); var encryptionProvider = new Mock <IEncryptionProvider>(); encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>())) .ThrowsAsync(new WorkloadCommunicationException("failed", 404)); IDeploymentBackupSource fileBackup = new DeploymentFileBackup(this.tempFileName, serde, encryptionProvider.Object); await fileBackup.BackupDeploymentConfigAsync(ValidConfigInfo1); Assert.False(File.Exists(this.tempFileName)); encryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>())); }
public async void FileBackupReadThrowsWhenDecryptFails() { if (File.Exists(this.tempFileName)) { File.Delete(this.tempFileName); } ISerde <DeploymentConfigInfo> serde = this.GetSerde(); var encryptionProvider = new Mock <IEncryptionProvider>(); encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>())) .ReturnsAsync(serde.Serialize(ValidConfigInfo1)); encryptionProvider.Setup(ep => ep.DecryptAsync(It.IsAny <string>())) .ThrowsAsync(new WorkloadCommunicationException("failed", 404)); IDeploymentBackupSource fileBackup = new DeploymentFileBackup(this.tempFileName, serde, encryptionProvider.Object); await fileBackup.BackupDeploymentConfigAsync(ValidConfigInfo1); await Assert.ThrowsAsync <WorkloadCommunicationException>(async() => await fileBackup.ReadFromBackupAsync()); }