Ejemplo n.º 1
0
        private void Test(string expectedResult, object[] items, bool resetCursor = true, string prompt = null, bool mustDing = false)
        {
            if (resetCursor)
            {
                _console.CursorLeft = 0;
                _console.CursorTop  = 0;
            }
            SetPrompt(prompt);

            _console.Init(items);
            var mockedMethods = new MockedMethods();
            var instance      = (PSConsoleReadLine)typeof(PSConsoleReadLine)
                                .GetField("_singleton", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            typeof(PSConsoleReadLine)
            .GetField("_mockableMethods", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, mockedMethods);
            typeof(PSConsoleReadLine)
            .GetField("_console", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, _console);

            var result = PSConsoleReadLine.ReadLine(null, null);

            if (_console.validationFailure != null)
            {
                throw new Exception("", _console.validationFailure);
            }

            while (_console.index < _console.inputOrValidateItems.Length)
            {
                var item = _console.inputOrValidateItems[_console.index++];
                ((Action)item)();
            }

            Assert.AreEqual(expectedResult, result);

            if (mustDing)
            {
                Assert.IsTrue(mockedMethods.didDing);
            }
        }
Ejemplo n.º 2
0
        private static void Test(string expectedResult, object[] items, bool resetCursor = true, string prompt = null, bool mustDing = false)
        {
            if (resetCursor)
            {
                Console.CursorLeft = 0;
                Console.CursorTop = 0;
                Console.BufferWidth = Console.WindowWidth = 60;
                Console.BufferHeight = Console.WindowHeight = 40;
            }
            SetPrompt(prompt);

            var mockedMethods = new MockedMethods(items);
            var instance = (PSConsoleReadLine)typeof(PSConsoleReadLine)
                .GetField("_singleton", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
            typeof(PSConsoleReadLine)
                .GetField("_mockableMethods", BindingFlags.Instance | BindingFlags.NonPublic)
                .SetValue(instance, mockedMethods);

            var result = PSConsoleReadLine.ReadLine();

            if (mockedMethods.validationFailure != null)
            {
                throw new Exception("", mockedMethods.validationFailure);
            }

            while (mockedMethods.index < mockedMethods.items.Length)
            {
                var item = mockedMethods.items[mockedMethods.index++];
                ((Action)item)();
            }

            Assert.AreEqual(expectedResult, result);

            if (mustDing)
            {
                Assert.IsTrue(mockedMethods.didDing);
            }
        }