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);
        }
        [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);
        }
        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);
        }
        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);
        }
        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);
        }
Example #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);
        }
        [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);
        }
Example #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);
        }
Example #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);
        }
        [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);
        }
Example #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);
        }
        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);
        }