Пример #1
0
        public bool ReadRecord(out DrawRectangleCommand 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.DrawRectangle)
                    {
                        return(false);
                    }

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

                    record = *data;
                    this.currentReadOffset += pCurRecord->Size;
                    return(true);
                }
            }
        }
Пример #2
0
        public void Throw_When_No_Canvas_Exist()
        {
            var command = new DrawRectangleCommand();

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

            test.Should().Throw <ArgumentException>();
        }
Пример #3
0
        public void Throw_When_Null_Argument()
        {
            var canvas = new Canvas(new CanvasDimentions {
                Width = 100, Height = 100
            });

            var command = new DrawRectangleCommand();

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

            test.Should().Throw <ArgumentNullException>();
        }
Пример #4
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 DrawRectangleCommand();

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

            test.Should().Throw <ArgumentException>();
        }
Пример #5
0
        public void Throw_When_Fewer_Params_Than_Expected_Are_Passed()
        {
            var canvas = new Canvas(new CanvasDimentions {
                Width = 100, Height = 100
            });

            var command = new DrawRectangleCommand();

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

            test.Should().Throw <ArgumentException>();
        }
Пример #6
0
        public void Call_Canvas_DrawRectangle_When_Params_Are_Fine()
        {
            var args = new string[] { "1", "1", "5", "20" };
            var expectedRectangle = new Rectangle(new Point(1 - 1, 1 - 1), new Point(5 - 1, 20 - 1));  //adjust 1-based coordinates to 0-based

            var mockCanvas = new Mock <ICanvas>();

            var command = new DrawRectangleCommand();

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

            mockCanvas.Verify(x => x.DrawRectangle(expectedRectangle), Times.Exactly(1), "DrawRectangleCommand doesn't call Canvas.DrawRectangle with correct args");
        }
Пример #7
0
        public override void DrawRectangle(Brush brush, Pen pen, Rect rectangle)
        {
            if (brush == null && pen == null)
            {
                return;
            }

            unsafe
            {
                EnsureContent();

                var record = new DrawRectangleCommand(
                    content.AddDependentResource(brush),
                    content.AddDependentResource(pen),
                    rectangle);

                content.WriteRecord(RecordType.DrawRectangle, (byte *)&record, sizeof(DrawRectangleCommand));
            }
        }