예제 #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 void ShouldChangeActiveColorForCurrentTool(string newColorInHex)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();

            //When
            paint.ChangeActiveColor(newColorInHex);

            //Then
            PaintingColor newColor = PaintingColor.CreateFromHex(newColorInHex);
            Assert.AreEqual(newColor, paint.GetActiveColor());
        }
예제 #3
0
        public void ShouldChangeCurrentTool(eTool toolType)
        {
            //Given
            PaintingMediator paint = new PaintingMediator();

            //When
            paint.ChangeToolTo(toolType);

            //Then
            Tool expectedTool = new Tool(toolType);
            Assert.AreEqual(expectedTool, paint.GetCurrentTool());
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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());
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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());
        }
예제 #11
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());
        }