public IActionResult Index(ReadFileModel model) { try { var encryption = new ReverseEncryption(); var security = new SecurityService(); File file; switch (model.FileType) { case FileType.FlatFile: file = new FlatFile(encryption, security); break; case FileType.XmlFile: file = new XmlFile(encryption, security); break; case FileType.Json: file = new Json(encryption, security); break; default: throw new Exception("error on filetype"); } return(Content(file.ReadFile(model.File, model.UseEncryption, model.UseSecurity, model.UserRole))); } catch { return(RedirectToAction("Index")); } }
static string ReadFile(FileTypes fileType, string path, bool isEncrypted, bool useRoles, string role) { IEncryptionProvider encryptionProvider = null; IRoleProvider roleProvider = null; if (isEncrypted) { encryptionProvider = new ReverseEncryption(); } if (useRoles) { roleProvider = new SimpleRoleProvider(); } Reader reader = new Reader(encryptionProvider, roleProvider); try { return(reader.ReadFile(fileType, path, isEncrypted: isEncrypted, role: role)); } catch (UnauthorizedAccessException) { return($"ERROR: Role \"{role}\" is not authorized to access this file"); } }
private static void Main(string[] args) { var math = Wiskunde.Wiskunde.GetInstance(); float x = 5; float y = 7; float result = math.Divide(x, y); Console.WriteLine(result); result = math.Multiply(result, 2); Console.WriteLine(result); result = math.Subtract(result, 4); Console.WriteLine(result); result = math.Sum(result, x); var noEncryption = new NoEncryption(); var reverseEncryption = new ReverseEncryption(); var shiftEncryption = new ShiftEncryption(); string test = "Time flies like an arrow, fruit flies like a banana."; Console.WriteLine(noEncryption.PreformEncryption(test)); Console.WriteLine(reverseEncryption.PreformEncryption(test)); Console.WriteLine(shiftEncryption.PreformEncryption(test)); }
public void ReadEncodedTest() { ReverseEncryption encryptionStrategy = new ReverseEncryption(); TextFileReader reader = new TextFileReader("encryptedText.txt", encryptionStrategy); string decodedText = reader.ReadEncoded(); Assert.AreEqual(decodedText, "hello"); }
static void Main(string[] args) { Console.WriteLine("Give the file to read"); var fileName = Console.ReadLine(); var encryption = new ReverseEncryption(); var security = new SecurityService(); var file = new Json(encryption, security); Console.Write(file.ReadSecure(fileName, UserRole.Admin)); }
public void DecryptString() { ReverseEncryption provider = new ReverseEncryption(); string input = "Test"; string expected = "tseT"; string actual = provider.Decrypt(input); Assert.Equal(expected, actual); }
public void EncryptReturnsCorrectResult( string input) { // Fixture setup var sut = new ReverseEncryption(); // Exercise system string actual = sut.Encrypt(input); // Verify outcome var expected = new string(input.Reverse().ToArray()); Assert.Equal(expected, actual); // Teardown }
private void button1_Click(object sender, EventArgs e) { IEncryption encryption = null; ISecurityRole securityRole = null; AbstractReader reader = null; if (checkBox1.Checked) { encryption = new ReverseEncryption(); } if (checkBox2.Checked) { securityRole = new ClassicSecurityRole(); } reader = GetReaderByIndex(comboBox1.SelectedIndex, encryption, securityRole, textBox3.Text, textBox4.Text); textBox2.Text = reader.Read(textBox1.Text); }
public void SutIsEncryption() { var sut = new ReverseEncryption(); Assert.IsAssignableFrom <IEncryption>(sut); }