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 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 async Task AcceptsExpressionToSingleAsyncMethod() { var container = new TestMenuTargetWithCtorParameter("false"); var target = MenuItem.For <TestMenuTargetWithCtorParameter>(x => x.DoIt(container), "some text", container); Assert.AreEqual("Do It", target.DisplayString); await target.ActionWithParameters(Array.Empty <object>()); Assert.AreEqual("some text", container.Text); }
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); }