public async Task ExecutionTest() { var userInput = Enumerable.Range(0, 10) .SelectMany(x => new[] { x.ToString(CultureInfo.InvariantCulture), " " }) .Take(19) .Append("0") .Append(" ") .Append("1") .ToArray(); var console = new ConsoleSimulator(userInput); var menuTarget = new TestMenuTargetWithStaticMethods(); var instance = new TestMenuTargetWithCtorParameter("fail"); await new[] { MenuItem.Print(() => this.LocalVoidMethodWithParameter(string.Empty)), MenuItem.Print(() => this.LocalStringMethodWithParameter(string.Empty)), MenuItem.Print(() => this.LocalAsyncVoidMethodWithParameter(string.Empty)), MenuItem.Print(() => this.LocalAsyncStringMethodWithParameter(string.Empty)), MenuItem.For <TestMenuTarget>(x => x.ThisIsAVoidMethod(), "hello", menuTarget), MenuItem.For <TestMenuTargetWithCtorParameter>(x => x.DoIt(instance), "hello", menuTarget, instance), MenuItem.For <TestMenuTargetWithCtorParameter>(x => x.DoIt(), "hello", menuTarget), MenuItem.For <TestMenuTargetWithCtorParameter>(() => instance.DoIt(), "hello", menuTarget), MenuItem.For <TestMenuTargetWithCtorParameter>(() => instance.VoidDoIt(), "hello", menuTarget), MenuItem.For <TestMenuTargetWithStaticMethods>("hello", menuTarget, console), }.Show(console); var result = console.Output.Aggregate((x, s) => x + "\n" + s); const string expected = "{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #0 Local Void Method With Parameter\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #1 Local String Method With Parameter\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #2 Local Async Void Method With Parameter\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #3 Local Async String Method With Parameter\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #4 This is a good documented void method.\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #5 Do It\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #6 Do It\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #7 Do It\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #8 Void Do It\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?\nexecuting menu item #9 A class containing method to create a menu from.\n{clear}\n0) This is a method returning a string async.\n1) This is a good documented void method.\nwhat should be executed?\nexecuting menu item #0 This is a method returning a string async.\nreturn value\ndone\npress any key to continue\n{clear}\n0) This is a method returning a string async.\n1) This is a good documented void method.\nwhat should be executed?\nexecuting menu item #1 This is a good documented void method.\ndone\npress any key to continue\n{clear}\n0) This is a method returning a string async.\n1) This is a good documented void method.\nwhat should be executed?\ndone\npress any key to continue\n{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) This is a good documented void method.\n5) Do It\n6) Do It\n7) Do It\n8) Void Do It\n9) A class containing method to create a menu from.\nwhat should be executed?"; Assert.AreEqual(expected, result); }
public void GivenLinesToReadWhenReadLineThenLinesAreReadInTheCorrectOrder() { var simulator = new ConsoleSimulator("123", "456"); Check.That(simulator.ReadLine()).IsEqualTo("123"); Check.That(simulator.ReadLine()).IsEqualTo("456"); }
public async Task SampleMenuCreationWithShowParameters() { var console = new ConsoleSimulator(" ", " "); var menuTarget = new TestMenuTargetWithStaticMethods(); var instance = new TestMenuTargetWithCtorParameter("fail"); await new[] { MenuItem.Print <string>(this.LocalVoidMethodWithParameter), MenuItem.Print <string>(this.LocalStringMethodWithParameter), MenuItem.Print <string>(this.LocalAsyncVoidMethodWithParameter), MenuItem.Print <string>(this.LocalAsyncStringMethodWithParameter), MenuItem.For <TestMenuTargetWithStaticMethods>(), MenuItem.For <TestMenuTarget>(x => x.ThisIsAVoidMethod()), MenuItem.For <TestMenuTargetWithCtorParameter>(x => x.DoIt(instance)), MenuItem.For <TestMenuTargetWithCtorParameter>(x => x.DoIt()), MenuItem.For <TestMenuTargetWithCtorParameter>(() => instance.DoIt()), MenuItem.For <TestMenuTargetWithCtorParameter>(() => instance.VoidDoIt()), }.Show(console, new { value = string.Empty }, menuTarget); var result = console.Output.Aggregate((x, s) => x + "\n" + s); const string expected = "{clear}\n0) Local Void Method With Parameter\n1) Local String Method With Parameter\n2) Local Async Void Method With Parameter\n3) Local Async String Method With Parameter\n4) A class containing method to create a menu from.\n5) This is a good documented void method.\n6) Do It\n7) Do It\n8) Do It\n9) Void Do It\nwhat should be executed?"; Assert.AreEqual(expected, result); }
public void GivenWrittenLinesWhenGetWrittenLinesThenWrittenLinesAreInTheCorrectOrder() { var simulator = new ConsoleSimulator(); simulator.WriteLine("123"); simulator.WriteLine("456"); Check.That(simulator.WrittenLines).ContainsExactly("123", "456"); }
public async Task OutputsTheResultOfTheMethod() { var console = new ConsoleSimulator("0", "0", " ", " "); var parameters = new { client = new TestMenuTarget(), sampleCrmId = Guid.Empty }; await new[] { MenuItem.For <TestMenuTargetForOutput>() }.Show(console, parameters); var result = console.Output.Aggregate((x, s) => x + "\n" + s); Assert.AreEqual("{clear}\n0) A class containing a method to create a menu from.\nwhat should be executed?\nexecuting menu item #0 A class containing a method to create a menu from.\n{clear}\n0) Read Single Contact\nwhat should be executed?\nexecuting menu item #0 Read Single Contact\nok\ndone\npress any key to continue\n{clear}\n0) Read Single Contact\nwhat should be executed?\ndone\npress any key to continue\n{clear}\n0) A class containing a method to create a menu from.\nwhat should be executed?", result); }
public async Task ShowsExceptionInOutput() { var simulator = new ConsoleSimulator("0", " ", " "); MenuItem.Console = simulator; var target = new[] { MenuItem.For <TestMenuTargetForException>(x => x.ThrowException()) }; await target.Show(simulator); Assert.IsTrue(simulator.Output[4].Contains("System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.\r\n ---> System.NotImplementedException: The method or operation is not implemented", StringComparison.OrdinalIgnoreCase)); }
public async Task CallingWithShowParameters() { var userInput = new[] { "0", " ", " ", " ", }; var console = new ConsoleSimulator(userInput); var instance = new TestMenuTargetWithCtorParameter("fail"); var target = MenuItem.For <TestMenuTargetWithCtorParameter>(x => x.DoIt(instance)); await new[] { target }.Show(console, new { text = "hello", container = instance }); Assert.AreEqual("hello", instance.Text); }
public async Task ParametersAreForwardedToMethods() { var simulator = new ConsoleSimulator("0", " ", " "); MenuItem.Console = simulator; var target = new[] { MenuItem.Print <TestMenuTargetWithStaticMethods>(TestMenuTargetWithStaticMethods.ThisIsAVoidMethod) }; var parameter = new TestMenuTargetWithStaticMethods(); await target.Show(simulator, parameter); Assert.AreEqual("ok", parameter.Result); }
public async Task InvokesAction2() { var menuTarget = new TestMenuTarget(); var target = new[] { MenuItem.Print(() => menuTarget.DoItTheRightWay()) }; var simulator = new ConsoleSimulator("0", " ", " "); MenuItem.Console = simulator; await target.Show(simulator); Assert.AreEqual("{clear}", simulator.Output[0]); Assert.AreEqual("0) Do It The Right Way", simulator.Output[1]); }
public async Task InvokesAction() { var value = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); var menuTarget = new TestMenuTarget(); var simulator = new ConsoleSimulator("0", " ", " "); MenuItem.Console = simulator; var target = MenuItem.MenuItemsFor <TestMenuTarget>(new { myParameterWrong = value, target = menuTarget }); await target.Show(simulator); Assert.AreEqual("{clear}", simulator.Output[0]); Assert.AreEqual("0) Do It The Right Way", simulator.Output[1]); Assert.AreEqual("1) This is a good documented method.", simulator.Output[2]); Assert.AreEqual("2) This is a good documented void method with parameter.", simulator.Output[3]); Assert.AreEqual("3) This is a good documented void method.", simulator.Output[4]); Assert.AreEqual("what should be executed?", simulator.Output[5]); Assert.AreEqual("executing menu item #0 Do It The Right Way", simulator.Output[6]); Assert.AreEqual("ok", simulator.Output[7]); Assert.AreEqual("done", simulator.Output[8]); Assert.AreEqual("press any key to continue", simulator.Output[9]); }
private static void Main(string[] args) { ConsoleSimulator simulator = new ConsoleSimulator(); simulator.Run(); }
public void GivenExcessReadLineWhenReadLineThenThrowArgumentException() { var simulator = new ConsoleSimulator(); Check.ThatCode(() => simulator.ReadLine()).Throws <NoMoreLinesToReadException>(); }
protected override void ResetState() { computer = null; }
protected override void LoadState() { computer = new(FileLines, true); }