コード例 #1
0
        public void ShouldFloodFillConsistentColorSpace()
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);
            canvasNode.MouseDown += paint.OnCanvasMouseDown;

            paint.ChangeToolTo(eTool.Line);
            paint.ChangeActiveColor("#ffffff");
            ImitateMouseDownOn(canvasNode);
            paint.ChangeToolTo(eTool.Fill);
            paint.ChangeActiveColor("#000000");
            Line drawedLine = canvasNode.Children[0] as Line;
            drawedLine.MouseDown += paint.OnCanvasChildClick;

            //When
            ImitateMouseDownOn(drawedLine);

            //Then
            Assert.AreEqual(paint.GetActiveColor().ToString(),drawedLine.Stroke.ToString());
        }
コード例 #2
0
        public MainWindow()
        {
            InitializeComponent();
            _paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = this.canvasNode;

            canvasNode.MouseDown += _paint.OnCanvasMouseDown;
            canvasNode.MouseMove += _paint.OnCanvasMouseMove;
            canvasNode.MouseUp += _paint.OnCanvasMouseUp;

            canvasService.SetCanvas(canvasNode);
            _paint.SetCanvasService(canvasService);
            _paint.ChangeToolTo(eTool.Pencil);
            _paint.ChangeActiveColor("#000000");
            SetButtonAsActive(pencil);
        }
コード例 #3
0
        public void ShouldDrawWithCurrentToolOnCanvas(eTool currentTool)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasNode.MouseDown += paint.OnCanvasMouseDown;
            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);
            paint.ChangeToolTo(currentTool);
            int numberOfElementsOnCanvas = canvasNode.Children.Count;

            //When
            ImitateMouseDownOn(canvasNode);

            //Then
            Assert.AreNotEqual(numberOfElementsOnCanvas, canvasNode.Children.Count);
        }
コード例 #4
0
        public void ShouldUndoChanges(int numberOfChangesToUndo)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);

            for (int i = 0; i < numberOfChangesToUndo; i++)
            {
                paint.Rotate(90);
            }

            //When
            for (int i = 0; i < numberOfChangesToUndo; i++)
            {
                paint.Undo();
            }

            //Then
            int expectedNumberOfChangesOnStack = 0;
            Assert.AreEqual(expectedNumberOfChangesOnStack, paint.GetNumberOfDoneChanges());
        }
コード例 #5
0
        public void ShouldSaveImageToBmp(string expectedSaveLocationString)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);
            paint.LoadImage("g:\\test.bmp");

            //When
            paint.Save(expectedSaveLocationString);

            //Then
            Uri saveLocation = new Uri(expectedSaveLocationString);
            BitmapImage expectedImage = new BitmapImage(saveLocation);
            Assert.IsNotNull(expectedImage);
        }
コード例 #6
0
        public void ShouldRotateCanvas(int degrees)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);

            //When
            paint.Rotate(degrees);

            //Then

            Assert.AreEqual(canvasNode.Height, canvasNode.Width);
            Assert.AreEqual(canvasNode.Width, canvasNode.Height);
        }
コード例 #7
0
        public void ShouldReverseCanvas(eDirection direction)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);

            //When
            paint.Reverse(direction);

            //Then
            ScaleTransform expectedTransform = new ScaleTransform();
            if (direction.Equals(eDirection.Horizontal))
                expectedTransform.ScaleY = -1;
            else if (direction.Equals(eDirection.Vertical))
                expectedTransform.ScaleX = -1;

            Assert.AreEqual(expectedTransform.Value, canvasNode.RenderTransform.Value);
        }
コード例 #8
0
        public void ShouldResizeCanvas(int newWidth, int newHeight)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);

            //When
            paint.ChangeCanvasSize(newWidth, newHeight);

            //Then
            Size expectedSize = new Size(newWidth, newHeight);
            Assert.AreEqual(expectedSize, canvasService.GetSize());
        }
コード例 #9
0
        public void ShouldLoadBmpImage(string path)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();
            CanvasBackService canvasService = new CanvasBackService();
            Canvas canvasNode = new Canvas();

            canvasService.SetCanvas(canvasNode);
            paint.SetCanvasService(canvasService);

            //When
            paint.LoadImage(path);

            //Then
            //Loaded image should be in the background of canvas
            Uri pathUri = new Uri(path);
            BitmapImage expectedImage = new BitmapImage(pathUri);
            ImageBrush expectedBrush = new ImageBrush(expectedImage);

            ImageBrush actualBrush = canvasNode.Background as ImageBrush;
            Assert.AreEqual(expectedBrush.ImageSource.ToString(), actualBrush.ImageSource.ToString());
        }
コード例 #10
0
 public void SetCanvasService(CanvasBackService canvasService)
 {
     _canvasService = canvasService;
 }