public void FileBuilder_NoAdditionalParameters_Success() { // Assert var fileType = _fixture.Create <FileTypes>(); // Act var file = FileBuilder .Create(fileType) .Build(); // Assert file.FileType.Should().Be(fileType); file.IsProtected.Should().BeFalse(); file.IsEncrypted.Should().BeFalse(); }
public void FileBuilder_WithAuthorization_Success() { // Assert var fileType = _fixture.Create <FileTypes>(); // Act var file = FileBuilder .Create(fileType) .WithAuthorization() .Build(); // Assert file.FileType.Should().Be(fileType); file.IsProtected.Should().BeTrue(); file.IsEncrypted.Should().BeFalse(); }
public string ReadFile() { var jsonFile = FileBuilder .Create(FileTypes.Json) .Build(); if (jsonFile == null) { throw new FileNotFoundException(); } using (var file = File.OpenText(jsonFile.FilePath)) { return(file.ReadToEnd()); } }
public string ReadEncryptedFile() { var jsonFile = FileBuilder .Create(FileTypes.Json) .WithEncryption() .Build(); if (jsonFile == null) { throw new FileNotFoundException(); } using (var file = File.OpenText(jsonFile.FilePath)) { var encryptedContents = file.ReadToEnd(); return(_fileEncryption.DecryptFileContents(encryptedContents)); } }
public string ReadProtectedFile(string role) { var jsonFile = FileBuilder .Create(FileTypes.Json) .WithAuthorization() .Build(); if (jsonFile == null) { throw new FileNotFoundException(); } if (!_fileSecurity.CanAccessFile(role)) { return($"ACCESS DENIED: The role \"{role}\" is not authorized to access this file."); } using (var file = File.OpenText(jsonFile.FilePath)) { return(file.ReadToEnd()); } }