Example #1
0
        public void ProgressBar_PercentageGreaterThanOne_ArgumentOutOfRangeException()
        {
            var window = new StubbedWindow();
            var sut    = new ConControls.Controls.ProgressBar(window);

            sut.Invoking(s => s.Percentage = 1.000000001).Should().Throw <ArgumentOutOfRangeException>();
        }
Example #2
0
        public void ProgressBar_PercentageChanged_EventRaisedIfChangedAndDrawnIfRectChanged()
        {
            var window = new StubbedWindow();
            int drawn  = 0;

            window.Graphics.FillAreaConsoleColorConsoleColorCharRectangle = (color, consoleColor, character, rect) =>
            {
                if (character == ConControls.Controls.ProgressBar.DefaultProgressChar)
                {
                    drawn += 1;
                }
            };

            var sut = new ConControls.Controls.ProgressBar(window)
            {
                Orientation = ConControls.Controls.ProgressBar.ProgressOrientation.LeftToRight,
                Size        = new Size(10, 3),
                Parent      = window
            };
            int raised = 0;

            sut.PercentageChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                raised += 1;
            };

            drawn = 0;

            sut.Percentage.Should().Be(0);
            sut.Percentage = 0.01;
            sut.Percentage.Should().Be(0.01);
            raised.Should().Be(1);
            drawn.Should().Be(1, "previous rectangles have not been stored, so this change leads to drawing.");

            sut.Percentage = 0.01;
            sut.Percentage.Should().Be(0.01);
            raised.Should().Be(1);
            drawn.Should().Be(1);

            sut.Percentage = 0.011;
            sut.Percentage.Should().Be(0.011);
            raised.Should().Be(2);
            drawn.Should().Be(1);

            sut.Percentage = 0.5;
            sut.Percentage.Should().Be(0.5);
            raised.Should().Be(3);
            drawn.Should().Be(2);

            sut.Percentage = 0.5;
            sut.Percentage.Should().Be(0.5);
            raised.Should().Be(3);
            drawn.Should().Be(2);
        }
Example #3
0
        public void ProgressBar_OrientationChanged_EventRaisedOnceAndDrawn()
        {
            var window = new StubbedWindow();
            int drawn  = 0;

            window.Graphics.FillAreaConsoleColorConsoleColorCharRectangle = (color, consoleColor, character, rect) =>
            {
                if (character == ConControls.Controls.ProgressBar.DefaultProgressChar)
                {
                    drawn += 1;
                }
            };

            var sut = new ConControls.Controls.ProgressBar(window)
            {
                Parent = window, Size = new Size(10, 10)
            };
            int raised = 0;

            sut.OrientationChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                raised += 1;
            };

            drawn = 0;

            sut.Orientation.Should().Be(ConControls.Controls.ProgressBar.ProgressOrientation.LeftToRight);

            sut.Orientation = ConControls.Controls.ProgressBar.ProgressOrientation.TopToBottom;
            raised.Should().Be(1);
            drawn.Should().Be(1);
            sut.Orientation.Should().Be(ConControls.Controls.ProgressBar.ProgressOrientation.TopToBottom);

            sut.Orientation = ConControls.Controls.ProgressBar.ProgressOrientation.TopToBottom;
            raised.Should().Be(1);
            drawn.Should().Be(1);
            sut.Orientation.Should().Be(ConControls.Controls.ProgressBar.ProgressOrientation.TopToBottom);
        }
Example #4
0
        public void ProgressBar_ProgressCharChanged_EventRaisedOnceAndDrawn()
        {
            const char testChar = 'x';

            var window = new StubbedWindow();
            int drawn  = 0;

            window.Graphics.FillAreaConsoleColorConsoleColorCharRectangle = (color, consoleColor, character, rect) =>
            {
                if (character == testChar)
                {
                    drawn += 1;
                }
            };

            var sut = new ConControls.Controls.ProgressBar(window)
            {
                Size   = new Size(10, 3), Orientation = ConControls.Controls.ProgressBar.ProgressOrientation.LeftToRight,
                Parent = window
            };
            int raised = 0;

            sut.ProgressCharChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                raised += 1;
            };

            sut.ProgressChar.Should().Be(ConControls.Controls.ProgressBar.DefaultProgressChar);

            sut.ProgressChar = testChar;
            raised.Should().Be(1);
            drawn.Should().Be(1);
            sut.ProgressChar.Should().Be(testChar);
            sut.ProgressChar = testChar;
            raised.Should().Be(1);
            drawn.Should().Be(1);
            sut.ProgressChar.Should().Be(testChar);
        }