@@ -10,12 +10,15 @@ public class PathExtentionTests
1010{
1111 private RectangleF bounds ;
1212 private readonly Mock < IPath > mockPath ;
13+ private readonly Mock < IPathCollection > mockPathCollection ;
1314
1415 public PathExtentionTests ( )
1516 {
1617 this . bounds = new RectangleF ( 10 , 10 , 20 , 20 ) ;
1718 this . mockPath = new Mock < IPath > ( ) ;
1819 this . mockPath . Setup ( x => x . Bounds ) . Returns ( ( ) => this . bounds ) ;
20+ this . mockPathCollection = new Mock < IPathCollection > ( ) ;
21+ this . mockPathCollection . Setup ( x => x . Bounds ) . Returns ( ( ) => this . bounds ) ;
1922 }
2023
2124 [ Fact ]
@@ -96,4 +99,105 @@ public void TranslateXY()
9699
97100 this . mockPath . Verify ( p => p . Transform ( It . IsAny < Matrix4x4 > ( ) ) , Times . Once ) ;
98101 }
102+
103+ [ Fact ]
104+ public void TranslatePoint ( )
105+ {
106+ PointF point = new ( 98 , 120 ) ;
107+ Matrix4x4 targetMatrix = Matrix4x4 . CreateTranslation ( point . X , point . Y , 0 ) ;
108+
109+ this . VerifyPathTransform ( path => path . Translate ( point ) , targetMatrix ) ;
110+ }
111+
112+ [ Fact ]
113+ public void ScaleXY ( )
114+ {
115+ Matrix4x4 targetMatrix = Matrix4x4 . CreateScale ( 2 , 3 , 1 , new Vector3 ( RectangleF . Center ( this . bounds ) , 0 ) ) ;
116+
117+ this . VerifyPathTransform ( path => path . Scale ( 2 , 3 ) , targetMatrix ) ;
118+ }
119+
120+ [ Fact ]
121+ public void ScaleUniform ( )
122+ {
123+ Matrix4x4 targetMatrix = Matrix4x4 . CreateScale ( 4 , 4 , 1 , new Vector3 ( RectangleF . Center ( this . bounds ) , 0 ) ) ;
124+
125+ this . VerifyPathTransform ( path => path . Scale ( 4 ) , targetMatrix ) ;
126+ }
127+
128+ [ Fact ]
129+ public void CollectionRotateInRadians ( )
130+ {
131+ const float Angle = ( float ) Math . PI ;
132+ Matrix4x4 targetMatrix = new ( Matrix3x2 . CreateRotation ( Angle , RectangleF . Center ( this . bounds ) ) ) ;
133+
134+ this . VerifyPathCollectionTransform ( path => path . Rotate ( Angle ) , targetMatrix ) ;
135+ }
136+
137+ [ Fact ]
138+ public void CollectionRotateInDegrees ( )
139+ {
140+ const float Angle = 90 ;
141+ const float Radians = ( float ) ( Math . PI * Angle / 180.0 ) ;
142+ Matrix4x4 targetMatrix = new ( Matrix3x2 . CreateRotation ( Radians , RectangleF . Center ( this . bounds ) ) ) ;
143+
144+ this . VerifyPathCollectionTransform ( path => path . RotateDegree ( Angle ) , targetMatrix ) ;
145+ }
146+
147+ [ Fact ]
148+ public void CollectionTranslatePoint ( )
149+ {
150+ PointF point = new ( 98 , 120 ) ;
151+ Matrix4x4 targetMatrix = Matrix4x4 . CreateTranslation ( point . X , point . Y , 0 ) ;
152+
153+ this . VerifyPathCollectionTransform ( path => path . Translate ( point ) , targetMatrix ) ;
154+ }
155+
156+ [ Fact ]
157+ public void CollectionTranslateXY ( )
158+ {
159+ const float X = 76 ;
160+ const float Y = 7 ;
161+ Matrix4x4 targetMatrix = Matrix4x4 . CreateTranslation ( X , Y , 0 ) ;
162+
163+ this . VerifyPathCollectionTransform ( path => path . Translate ( X , Y ) , targetMatrix ) ;
164+ }
165+
166+ [ Fact ]
167+ public void CollectionScaleXY ( )
168+ {
169+ Matrix4x4 targetMatrix = Matrix4x4 . CreateScale ( 2 , 3 , 1 , new Vector3 ( RectangleF . Center ( this . bounds ) , 0 ) ) ;
170+
171+ this . VerifyPathCollectionTransform ( path => path . Scale ( 2 , 3 ) , targetMatrix ) ;
172+ }
173+
174+ [ Fact ]
175+ public void CollectionScaleUniform ( )
176+ {
177+ Matrix4x4 targetMatrix = Matrix4x4 . CreateScale ( 4 , 4 , 1 , new Vector3 ( RectangleF . Center ( this . bounds ) , 0 ) ) ;
178+
179+ this . VerifyPathCollectionTransform ( path => path . Scale ( 4 ) , targetMatrix ) ;
180+ }
181+
182+ private void VerifyPathTransform ( Action < IPath > transform , Matrix4x4 targetMatrix )
183+ {
184+ this . mockPath . Setup ( x => x . Transform ( It . IsAny < Matrix4x4 > ( ) ) )
185+ . Callback < Matrix4x4 > ( m => Assert . Equal ( targetMatrix , m ) )
186+ . Returns ( this . mockPath . Object ) ;
187+
188+ transform ( this . mockPath . Object ) ;
189+
190+ this . mockPath . Verify ( x => x . Transform ( It . IsAny < Matrix4x4 > ( ) ) , Times . Once ) ;
191+ }
192+
193+ private void VerifyPathCollectionTransform ( Action < IPathCollection > transform , Matrix4x4 targetMatrix )
194+ {
195+ this . mockPathCollection . Setup ( x => x . Transform ( It . IsAny < Matrix4x4 > ( ) ) )
196+ . Callback < Matrix4x4 > ( m => Assert . Equal ( targetMatrix , m ) )
197+ . Returns ( this . mockPathCollection . Object ) ;
198+
199+ transform ( this . mockPathCollection . Object ) ;
200+
201+ this . mockPathCollection . Verify ( x => x . Transform ( It . IsAny < Matrix4x4 > ( ) ) , Times . Once ) ;
202+ }
99203}
0 commit comments