Ejemplo n.º 1
0
        public void RepromptsWhenResponseAboveMaxValue(string response, decimal maxValue)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (decimal result, string output) = TestFx.RepromptWithInvalidFirstDecimalResponse("", response,
                                                                                             $"{maxValue - 1}", null, maxValue);
            Assert.Equal(maxValue - 1, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 2
0
        [InlineData("-79228162514264337593543950336")] // One below decimal.MinValue
        public void RepromptsWhenResponseIsInvalid(string response)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (decimal result, string output) =
                TestFx.RepromptWithInvalidFirstDecimalResponse("", response, "15", int.MinValue);
            Assert.Equal(15, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 3
0
        public void RepromptsWhenResponseBelowMinValue(string response, decimal minValue)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (decimal result, string output) =
                TestFx.RepromptWithInvalidFirstDecimalResponse("", response, $"{minValue + 1}", minValue);
            Assert.Equal(minValue + 1, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 4
0
        public void ReturnsCorrectNumber(string prompt, string response, decimal expected)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            decimal result = TestFx.HandleValidDecimalResponse(prompt, response);

            Assert.Equal(expected, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 5
0
        public void AcceptsDecimalsInValidRange(string response, decimal min, decimal max, decimal expected)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            decimal result = TestFx.HandleValidDecimalResponse("", response, min, max);

            Assert.Equal(expected, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 6
0
        public void AcceptsIntegersInValidRange(string response, int min, int max, int expected)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            int result = TestFx.HandleValidIntegerResponse("", response, min, max);

            Assert.Equal(expected, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 7
0
        [InlineData("-79228162514264337593543950336")] // One below decimal.MinValue
        public void DoesNotOutputHelpMessageWithVerboseOff(string response)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (decimal result, string output) =
                TestFx.RepromptWithInvalidFirstDecimalResponse("", response, "15", verbose: false);

            Assert.DoesNotContain("decimal value", output);
            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 8
0
        public void ReturnsCorrectInteger(string prompt, string response, int expected)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            int result = TestFx.HandleValidIntegerResponse(prompt, response);

            Assert.Equal(expected, result);

            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 9
0
        [InlineData("-2147483649")] // One below int.MinValue
        public void DoesNotOutputHelpMessageWithVerboseOff(string response)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (int result, string output) =
                TestFx.RepromptWithInvalidFirstIntegerResponse("", response, "15", verbose: false);

            Assert.DoesNotContain("whole number", output);
            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 10
0
        [InlineData("-79228162514264337593543950336")] // One below decimal.MinValue
        public void OutputsHelpMessageWithInvalidResponse(string response)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (decimal result, string output) = TestFx.RepromptWithInvalidFirstDecimalResponse("", response, "15");

            string expected =
                $"Please supply a decimal value between {decimal.MinValue} and {decimal.MaxValue}.";

            Assert.Contains(expected, output);
            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 11
0
        [InlineData("-2147483649")] // One below int.MinValue
        public void OutputsHelpMessageWithInvalidResponse(string response)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            (int result, string output) = TestFx.RepromptWithInvalidFirstIntegerResponse("", response, "15");

            string expected =
                $"Please supply a whole number between {int.MinValue} and {int.MaxValue}.";

            Assert.Contains(expected, output);
            TestFx.ResetConsole(stdOut, stdIn);
        }
Ejemplo n.º 12
0
        public void IssuesCorrectPrompt(string prompt)
        {
            var(stdOut, stdIn) = TestFx.ConsoleDefaults();

            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                using (StringReader sr = new StringReader("15" + Environment.NewLine))
                {
                    Console.SetIn(sr);
                    ConsoleEx.PromptDecimal(prompt);
                    Assert.Equal(prompt + " ", sw.ToString());
                }
            }

            TestFx.ResetConsole(stdOut, stdIn);
        }