コード例 #1
0
            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);
            }
コード例 #2
0
            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);
            }
コード例 #3
0
            public async Task AcceptsAsyncMethodsReturningIEnumerableString()
            {
                var menuTarget = new TestMenuTargetWithStaticMethods();
                var target     = MenuItem.Print(() => TestMenuTargetWithStaticMethods.WithAsyncIEnumerableStringResult(menuTarget));
                await target.ActionWithParameters(Array.Empty <object>()).ConfigureAwait(false);

                Assert.AreEqual("ok", menuTarget.Result);
            }
コード例 #4
0
            public async Task AcceptsStaticMethods()
            {
                var   menuTarget = new TestMenuTargetWithStaticMethods();
                var   target     = MenuItem.MenuItemsFor <TestMenuTargetWithStaticMethods>(menuTarget);
                await target[0].ActionWithParameters(Array.Empty <object>()).ConfigureAwait(false);

                Assert.AreEqual("ok", menuTarget.Result);
            }
コード例 #5
0
            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);
            }
コード例 #6
0
 public static Task <IEnumerable <string> > WithAsyncIEnumerableStringResult(TestMenuTargetWithStaticMethods menuTarget)
 {
     menuTarget.MustNotBeNull(nameof(menuTarget)).Result = "ok";
     return(Task.FromResult((IEnumerable <string>) new[] { "return value" }));
 }
コード例 #7
0
 public static Task <string> WithAsyncStringResult(TestMenuTargetWithStaticMethods menuTarget)
 {
     menuTarget.MustNotBeNull(nameof(menuTarget)).Result = "ok";
     return(Task.FromResult("return value"));
 }
コード例 #8
0
 public static void ThisIsAVoidMethod(TestMenuTargetWithStaticMethods menuTarget) => menuTarget.MustNotBeNull(nameof(menuTarget)).Result = "ok";