public void EmptyDict_ShouldReturnDefaultSubstitutions() { var file = File.Create("testDict1.txt"); file.Close(); var args = new[] { "subs", "C", "-d", "testDict1.txt" }; var subsOptions = ParseSubOptions(args); var expected = "C\r\n" + "[\r\n" + "{\r\n" + "(\r\n" + "<\r\n"; var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); File.Delete("testDict1.txt"); Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True); } }
public void VerboseDictWithGoodLeetOnly_ShouldPrintVerbose() { var content = "{\r\n\t\"GLeet\": {\r\n\t\t\"C\": [\r\n\t\t\t\"[\",\r\n\t\t\t\"(\"\r\n\t\t]\r\n\t}\r\n}"; File.WriteAllText("testDict1.txt", content, Encoding.UTF8); var args = new[] { "subs", "C", "-d", "testDict1.txt", "-v" }; var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); File.Delete("testDict1.txt"); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains($"[DICTIONARY]: testDict1.txt{Environment.NewLine}")); Assert.That(consoleText.Contains($"[METHOD]: GLeet{Environment.NewLine}")); } }
public void SourceWord_ShouldReturnSubstitutions(string[] args, string expected) { var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True); } }
public string Methods_ShouldReturnSubstitutions(string[] args) { var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); return(consoleOutput.GetOuput()); } }
public void StdInputOneWrongSymbolInput_ShouldPrintErrorAndContinueWork() { var args = new[] { "subs", "-i" }; var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleInput = new ConsoleInput("q\r\n")) { using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains("[ERROR]")); consoleInput.SetInput("B\r\n"); subsInstance.Process(); consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains("B\r\n|3\r\n8\r\n")); } } }
public void SourceWordThreeLetterLowercase_ShouldReturnErrorAndHelp() { var args = new[] { "subs", "bzs" }; var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains("[ERROR]: "), Is.True); } }
public void OutputFileNotSpecified_ShouldPrintInConsole() { var args = new[] { "subs", "B" }; var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains("B\r\n|3\r\n8\r\n"), Is.True); } }
public void StdInputWithSourceWord_ShouldIgnoreSourceWord() { var args = new[] { "subs", "B", "-i" }; var subsOptions = ParseSubOptions(args); using (var consoleOutput = new ConsoleOutput()) { var subsInstance = new Substitution(subsOptions); subsInstance.Process(); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Equals(""), Is.True); } }
public void OutputFileSpecified_ShouldPrintInFile() { var args = new[] { "subs", "B", "-o", "outputTest.txt" }; var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); subsInstance.Process(); var text = File.ReadAllText("outputTest.txt"); File.Delete("outputTest.txt"); Assert.That(text.Contains("B\r\n|3\r\n8\r\n"), Is.True); }
public void MadLeetThreeSymbols_ShouldReturnSubstitutions() { var args = new[] { "subs", "BZS", "-m", "MadLeet" }; var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); Assert.AreEqual(1041, consoleOutput.GetOuput().Split('\n').Length); } }
public void SourceWordThreeLetterIgnoreCase_ShouldReturnSubstitutions() { var args = new[] { "subs", "bzs", "--ignore-case" }; var subsOptions = ParseSubOptions(args); var expected = "bzs\r\n" + "|3zs\r\n" + "8zs\r\n" + "b2s\r\n" + "b7_s\r\n" + "|32s\r\n" + "|37_s\r\n" + "82s\r\n" + "87_s\r\n" + "bz5\r\n" + "bz$\r\n" + "|3z5\r\n" + "|3z$\r\n" + "8z5\r\n" + "8z$\r\n" + "b25\r\n" + "b2$\r\n" + "b7_5\r\n" + "b7_$\r\n" + "|325\r\n" + "|32$\r\n" + "|37_5\r\n" + "|37_$\r\n" + "825\r\n" + "82$\r\n" + "87_5\r\n" + "87_$\r\n"; var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True); } }
public void StdInputThreeSymbolsInput_ShouldPrintSubstitution() { var args = new[] { "subs", "-i" }; var subsOptions = ParseSubOptions(args); using (new ConsoleInput("B\r\nC\r\n")) { using (var consoleOutput = new ConsoleOutput()) { var subsInstance = new Substitution(subsOptions); subsInstance.Process(); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Equals("B\r\n|3\r\n8\r\nC\r\n[\r\n{\r\n(\r\n<\r\n")); } } }
public void SourceWord_ShouldReturnErrorAndHelp(string[] args) { var subsOptions = ParseSubOptions(args); var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { try { subsInstance.Process(); } catch (VerbOptionException e) { Logger.ErrorAndPrint(e.Message); } var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains("[ERROR]: "), Is.True); } }
public void StdDictMethodAndEncoding_ShouldPrintVerbose() { var args = new[] { "subs", "QW", "-v" }; var subsOptions = ParseSubOptions(args); using (new ConsoleInput("B\r\nC\r\n")) { using (var consoleOutput = new ConsoleOutput()) { var subsInstance = new Substitution(subsOptions); subsInstance.Process(); var consoleText = consoleOutput.GetOuput(); Assert.That(consoleText.Contains($"[METHOD]: GoodLeet{Environment.NewLine}")); Assert.That(consoleText.Contains($"[DICTIONARY]: default{Environment.NewLine}")); } } }
public void DictWithGoodLeetOnlySymbols_ShouldReturnSubstitutions() { var content = "{\r\n\t\"GoodLeet\": {\r\n\t\t\"{\": [\r\n\t\t\t\"[\",\r\n\t\t\t\"(\"\r\n\t\t]\r\n\t}\r\n}"; File.WriteAllText("testDict1.txt", content, Encoding.UTF8); var args = new[] { "subs", "{", "-d", "testDict1.txt" }; var subsOptions = ParseSubOptions(args); var expected = "{\r\n[\r\n(\r\n"; var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); File.Delete("testDict1.txt"); Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True); } }
public void WrongMethod_ShouldReturnSubstitutionsFromFirstAvailableMethod() { var args = new[] { "subs", "C", "-m", "balabala" }; var subsOptions = ParseSubOptions(args); var expected = "C\r\n" + "[\r\n" + "{\r\n" + "(\r\n" + "<\r\n"; var subsInstance = new Substitution(subsOptions); using (var consoleOutput = new ConsoleOutput()) { subsInstance.Process(); Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True); } }
private void SubstitutionButton_OnClick(object sender, RoutedEventArgs e) => SafeAction(() => { var substitution = new Substitution(SubstitutionKeyTextBox.Text); SubstitutionOutputTextBlock.Text = substitution.Process(SubstitutionInputTextBox.Text); });
private static void BaseTest(string text, string expected, string key) { var substitution = new Substitution(key); Assert.AreEqual(expected, substitution.Process(text)); }