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 FileBackupReadDoesNotThrowWhenBackupFileDoesNotExist() { if (File.Exists(this.tempFileName)) { File.Delete(this.tempFileName); } // Arrange ISerde <DeploymentConfigInfo> serde = this.GetSerde(); IDeploymentBackupSource fileBackup = new DeploymentFileBackup(this.tempFileName, serde, NullEncryptionProvider.Instance); // Act var config = await fileBackup.ReadFromBackupAsync(); // Assert Assert.NotNull(config); Assert.Equal(DeploymentConfigInfo.Empty, config); }
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()); }