This repository has been archived by the owner on Jan 18, 2020. It is now read-only.
/
PathExtentionTests.cs
110 lines (80 loc) · 3.13 KB
/
PathExtentionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using Moq;
using Xunit;
using SixLabors.Primitives;
namespace SixLabors.Shapes.Tests
{
public class PathExtentionTests
{
private RectangleF bounds;
private readonly Mock<IPath> mockPath;
public PathExtentionTests()
{
this.bounds = new RectangleF(10, 10, 20, 20);
this.mockPath = new Mock<IPath>();
this.mockPath.Setup(x => x.Bounds).Returns(() => this.bounds);
}
[Fact]
public void RotateInRadians()
{
float angle = (float)Math.PI;
this.mockPath.Setup(x => x.Transform(It.IsAny<Matrix3x2>()))
.Callback<Matrix3x2>(m =>
{
//validate matrix in here
Matrix3x2 targetMatrix = Matrix3x2.CreateRotation(angle, RectangleF.Center(this.bounds));
Assert.Equal(targetMatrix, m);
}).Returns(this.mockPath.Object);
this.mockPath.Object.Rotate(angle);
this.mockPath.Verify(x => x.Transform(It.IsAny<Matrix3x2>()), Times.Once);
}
[Fact]
public void RotateInDegrees()
{
float angle = 90;
this.mockPath.Setup(x => x.Transform(It.IsAny<Matrix3x2>()))
.Callback<Matrix3x2>(m =>
{
//validate matrix in here
float radians = (float)(Math.PI * angle / 180.0);
Matrix3x2 targetMatrix = Matrix3x2.CreateRotation(radians, RectangleF.Center(this.bounds));
Assert.Equal(targetMatrix, m);
}).Returns(this.mockPath.Object);
this.mockPath.Object.RotateDegree(angle);
this.mockPath.Verify(x => x.Transform(It.IsAny<Matrix3x2>()), Times.Once);
}
[Fact]
public void TranslateVector()
{
Vector2 point = new Vector2(98, 120);
this.mockPath.Setup(x => x.Transform(It.IsAny<Matrix3x2>()))
.Callback<Matrix3x2>(m =>
{
//validate matrix in here
Matrix3x2 targetMatrix = Matrix3x2.CreateTranslation(point);
Assert.Equal(targetMatrix, m);
}).Returns(this.mockPath.Object);
this.mockPath.Object.Translate(point);
this.mockPath.Verify(x => x.Transform(It.IsAny<Matrix3x2>()), Times.Once);
}
[Fact]
public void TranslateXY()
{
float x = 76;
float y = 7;
this.mockPath.Setup(p => p.Transform(It.IsAny<Matrix3x2>()))
.Callback<Matrix3x2>(m =>
{
//validate matrix in here
Matrix3x2 targetMatrix = Matrix3x2.CreateTranslation(new Vector2(x, y));
Assert.Equal(targetMatrix, m);
}).Returns(this.mockPath.Object);
this.mockPath.Object.Translate(x, y);
this.mockPath.Verify(p => p.Transform(It.IsAny<Matrix3x2>()), Times.Once);
}
}
}