Ejemplo n.º 1
0
        public ICanvas Execute(ICanvas canvas)
        {
            var width  = this.End.X - this.Start.X;
            var height = this.End.Y - this.Start.Y;


            var line1 = new LineCommand(
                this.Start,
                new System.Drawing.Point(this.Start.X + width, this.Start.Y));

            canvas = line1.Execute(canvas);

            var line2 = new LineCommand(
                this.Start,
                new System.Drawing.Point(this.Start.X, this.Start.Y + height));

            canvas = line2.Execute(canvas);

            var line3 = new LineCommand(
                new System.Drawing.Point(this.Start.X, this.Start.Y + height),
                this.End);

            canvas = line3.Execute(canvas);


            var line4 = new LineCommand(
                new System.Drawing.Point(this.Start.X + width, this.Start.Y),
                this.End);

            canvas = line4.Execute(canvas);

            return(canvas);
        }
Ejemplo n.º 2
0
            public void ShouldDrawVerticalLineRightToLeft()
            {
                var start = new System.Drawing.Point(6, 2);
                var end   = new System.Drawing.Point(6, 0);
                var cmd   = new LineCommand(start, end);

                var canvas = new Canvas(20, 5);

                var result = cmd.Execute(canvas);

                var expected = new char[20, 5];

                expected[6, 0] = 'x';
                expected[6, 1] = 'x';
                expected[6, 2] = 'x';

                Assert.Equal(expected, result.Data);
            }
Ejemplo n.º 3
0
            public void ShouldDrawHorizontalLineLeftToRight()
            {
                var start = new System.Drawing.Point(0, 2);
                var end   = new System.Drawing.Point(6, 2);
                var cmd   = new LineCommand(start, end);

                var canvas = new Canvas(20, 5);

                var result = cmd.Execute(canvas);

                var expected = new char[20, 5];

                expected[0, 2] = 'x';
                expected[1, 2] = 'x';
                expected[2, 2] = 'x';
                expected[3, 2] = 'x';
                expected[4, 2] = 'x';
                expected[5, 2] = 'x';
                expected[6, 2] = 'x';

                Assert.Equal(expected, result.Data);
            }