Example #1
0
        public bool ReadRecord(out DrawLineCommand record)
        {
            record = default;
            unsafe
            {
                fixed(byte *pByte = this.buffer)
                {
                    // This pointer points to the current read point in the
                    // instruction stream.
                    byte *pCur = pByte;

                    // This points to the first byte past the end of the
                    // instruction stream (i.e. when to stop)
                    byte *pEndOfInstructions = pByte + this.currentReadOffset;

                    if ((pCur >= pEndOfInstructions)) //reach end
                    {
                        return(false);
                    }

                    RecordHeader *pCurRecord = (RecordHeader *)pCur;

                    if (pCurRecord->Type != RecordType.DrawLine)
                    {
                        return(false);
                    }

                    DrawLineCommand *data = (DrawLineCommand *)(pCur + sizeof(RecordHeader));

                    record = *data;
                    this.currentReadOffset += pCurRecord->Size;
                    return(true);
                }
            }
        }
Example #2
0
        public void Throw_When_No_Canvas_Exist()
        {
            var command = new DrawLineCommand();

            command.Input = new string[] { "1", "1", "1", "5" };
            Action test = () => command.Execute(null);

            test.Should().Throw <ArgumentNullException>();
        }
Example #3
0
        public void Throw_When_An_Expected_Param_Is_Of_Invalid_Format(string arg1, string arg2, string arg3, string arg4)
        {
            var canvas = new Canvas(new CanvasDimentions {
                Width = 100, Height = 100
            });

            var command = new DrawLineCommand();

            command.Input = new string[] { arg1, arg2, arg3, arg4 };
            Action test = () => command.Execute(canvas);

            test.Should().Throw <ArgumentException>();
        }
Example #4
0
        public void Throw_When_Null_Argument()
        {
            var canvas = new Canvas(new CanvasDimentions {
                Width = 100, Height = 100
            });

            var command = new DrawLineCommand();

            command.Input = null;
            Action test = () => command.Execute(canvas);

            test.Should().Throw <ArgumentNullException>();
        }
Example #5
0
        public void Call_Canvas_DrawLine_When_Params_Are_Fine()
        {
            var args         = new string[] { "1", "1", "1", "20" };
            var expectedLine = new Line(new Point(1 - 1, 1 - 1), new Point(1 - 1, 20 - 1)); //adjust 1-based coordinates to 0-based

            var mockCanvas = new Mock <ICanvas>();

            var command = new DrawLineCommand();

            command.Input = args;
            command.Execute(mockCanvas.Object);

            mockCanvas.Verify(x => x.DrawLine(expectedLine), Times.Exactly(1), "DrawLineCommand doesn't call Canvas.DrawLine with correct args");
        }
Example #6
0
        public void Throw_When_Fewer_Params_Than_Expected_Are_Passed()
        {
            var canvas = new Canvas(new CanvasDimentions {
                Width = 100, Height = 100
            });

            var command = new DrawLineCommand();

            command.Input = new string[] { "1", "2", "3" };

            Action test = () => command.Execute(canvas);

            test.Should().Throw <ArgumentException>();
        }
Example #7
0
        public override void DrawLine(Pen pen, Point point0, Point point1)
        {
            if (pen == null)
            {
                throw new ArgumentNullException(nameof(pen));
            }

            unsafe
            {
                EnsureContent();

                var penIndex = content.AddDependentResource(pen);
                var record   = new DrawLineCommand(penIndex, point0, point1);

                content.WriteRecord(RecordType.DrawLine, (byte *)&record, sizeof(DrawLineCommand));
            }
        }