예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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());
            }
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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());
            }
        }