/Silverlight4/Source/Controls.Testing.Toolkit/Rating/LinearClipperTest.cs

https://github.com/kvervo/HorizontalLoopingSelector
C# | 271 lines | 211 code | 12 blank | 48 comment | 8 complexity | cc134d44fd8621fb0d4b07684d44350e MD5 | raw file
  1. // (c) Copyright Microsoft Corporation.
  2. // This source is subject to the Microsoft Public License (Ms-PL).
  3. // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  4. // All other rights reserved.
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Windows.Controls.Internals;
  9. using System.Windows.Controls.Primitives;
  10. using System.Windows.Media;
  11. using Microsoft.Silverlight.Testing;
  12. using Microsoft.VisualStudio.TestTools.UnitTesting;
  13. namespace System.Windows.Controls.Testing
  14. {
  15. /// <summary>
  16. /// LinearClipper unit tests.
  17. /// </summary>
  18. [TestClass]
  19. [Tag("RatingTest")]
  20. public class LinearClipperTest : ClipperTest
  21. {
  22. /// <summary>
  23. /// Initializes a new instance of the LinearClipperTest class.
  24. /// </summary>
  25. public LinearClipperTest()
  26. {
  27. }
  28. /// <summary>
  29. /// Gets an instance of the LinearClipper class.
  30. /// </summary>
  31. public override Clipper DefaultClipperToTest
  32. {
  33. get { return new LinearClipper(); }
  34. }
  35. /// <summary>
  36. /// Gets a sequence of clippers to test.
  37. /// </summary>
  38. public override System.Collections.Generic.IEnumerable<Clipper> ClippersToTest
  39. {
  40. get { yield return new LinearClipper(); }
  41. }
  42. /// <summary>
  43. /// Tests that the clip property is null when the RatioVisible is 1.0
  44. /// and the ExpandDirection is Right.
  45. /// </summary>
  46. [TestMethod]
  47. [Description("Tests that the clip property is null when RatioVisible is 1.0 and the ExpandDirection is Right.")]
  48. [Asynchronous]
  49. public void TestRightVisible()
  50. {
  51. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  52. clipper.Content = new TextBlock { Text = "Testing" };
  53. TestPanel.Children.Add(clipper);
  54. TestPanel
  55. .GetLayoutUpdated()
  56. .Take(1)
  57. .Do(_ =>
  58. {
  59. clipper.ExpandDirection = ExpandDirection.Right;
  60. clipper.RatioVisible = 1.0;
  61. })
  62. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Width == clipper.RenderSize.Width)
  63. .Subscribe(_ =>
  64. {
  65. TestPanel.Children.Remove(clipper);
  66. EnqueueTestComplete();
  67. });
  68. }
  69. /// <summary>
  70. /// Tests that the clip property is null when the RatioVisible is 1.0
  71. /// and the ExpandDirection is Left.
  72. /// </summary>
  73. [TestMethod]
  74. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Left.")]
  75. [Asynchronous]
  76. public void TestLeftVisible()
  77. {
  78. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  79. clipper.Content = new TextBlock { Text = "Testing" };
  80. TestPanel.Children.Add(clipper);
  81. TestPanel
  82. .GetLayoutUpdated()
  83. .Take(1)
  84. .Do(_ =>
  85. {
  86. clipper.ExpandDirection = ExpandDirection.Left;
  87. clipper.RatioVisible = 1.0;
  88. })
  89. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Width == clipper.RenderSize.Width)
  90. .Subscribe(_ =>
  91. {
  92. TestPanel.Children.Remove(clipper);
  93. EnqueueTestComplete();
  94. });
  95. }
  96. /// <summary>
  97. /// Tests that the clip property is null when the RatioVisible is 1.0
  98. /// and the ExpandDirection is Up.
  99. /// </summary>
  100. [TestMethod]
  101. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Up.")]
  102. [Asynchronous]
  103. public void TestUpVisible()
  104. {
  105. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  106. clipper.Content = new TextBlock { Text = "Testing" };
  107. TestPanel.Children.Add(clipper);
  108. TestPanel
  109. .GetLayoutUpdated()
  110. .Take(1)
  111. .Do(_ =>
  112. {
  113. clipper.ExpandDirection = ExpandDirection.Up;
  114. clipper.RatioVisible = 1.0;
  115. })
  116. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Height == clipper.RenderSize.Height)
  117. .Subscribe(_ =>
  118. {
  119. TestPanel.Children.Remove(clipper);
  120. EnqueueTestComplete();
  121. });
  122. }
  123. /// <summary>
  124. /// Tests that the clip property is null when the RatioVisible is 1.0
  125. /// and the ExpandDirection is Down.
  126. /// </summary>
  127. [TestMethod]
  128. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Down.")]
  129. [Asynchronous]
  130. public void TestDownVisible()
  131. {
  132. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  133. clipper.Content = new TextBlock { Text = "Testing" };
  134. TestPanel.Children.Add(clipper);
  135. TestPanel
  136. .GetLayoutUpdated()
  137. .Take(1)
  138. .Do(_ =>
  139. {
  140. clipper.ExpandDirection = ExpandDirection.Down;
  141. clipper.RatioVisible = 1.0;
  142. })
  143. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Height == clipper.RenderSize.Height)
  144. .Subscribe(_ =>
  145. {
  146. TestPanel.Children.Remove(clipper);
  147. EnqueueTestComplete();
  148. });
  149. }
  150. /// <summary>
  151. /// Tests that the clip property is null when the RatioVisible is 1.0
  152. /// and the ExpandDirection is Right.
  153. /// </summary>
  154. [TestMethod]
  155. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Right.")]
  156. [Asynchronous]
  157. public void TestRightEmpty()
  158. {
  159. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  160. clipper.Content = new TextBlock { Text = "Testing" };
  161. TestPanel.Children.Add(clipper);
  162. TestPanel
  163. .GetLayoutUpdated()
  164. .Take(1)
  165. .Do(_ =>
  166. {
  167. clipper.ExpandDirection = ExpandDirection.Right;
  168. clipper.RatioVisible = 0.0;
  169. })
  170. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Width == 0)
  171. .Subscribe(_ =>
  172. {
  173. TestPanel.Children.Remove(clipper);
  174. EnqueueTestComplete();
  175. });
  176. }
  177. /// <summary>
  178. /// Tests that the clip property is null when the RatioVisible is 1.0
  179. /// and the ExpandDirection is Left.
  180. /// </summary>
  181. [TestMethod]
  182. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Left.")]
  183. [Asynchronous]
  184. public void TestLeftEmpty()
  185. {
  186. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  187. clipper.Content = new TextBlock { Text = "Testing" };
  188. TestPanel.Children.Add(clipper);
  189. TestPanel
  190. .GetLayoutUpdated()
  191. .Take(1)
  192. .Do(_ =>
  193. {
  194. clipper.ExpandDirection = ExpandDirection.Left;
  195. clipper.RatioVisible = 0.0;
  196. })
  197. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Width == 0)
  198. .Subscribe(_ =>
  199. {
  200. TestPanel.Children.Remove(clipper);
  201. EnqueueTestComplete();
  202. });
  203. }
  204. /// <summary>
  205. /// Tests that the clip property is null when the RatioVisible is 1.0
  206. /// and the ExpandDirection is Up.
  207. /// </summary>
  208. [TestMethod]
  209. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Up.")]
  210. [Asynchronous]
  211. public void TestUpEmpty()
  212. {
  213. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  214. clipper.Content = new TextBlock { Text = "Testing" };
  215. TestPanel.Children.Add(clipper);
  216. TestPanel
  217. .GetLayoutUpdated()
  218. .Take(1)
  219. .Do(_ =>
  220. {
  221. clipper.ExpandDirection = ExpandDirection.Up;
  222. clipper.RatioVisible = 0.0;
  223. })
  224. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Height == 0)
  225. .Subscribe(_ =>
  226. {
  227. TestPanel.Children.Remove(clipper);
  228. EnqueueTestComplete();
  229. });
  230. }
  231. /// <summary>
  232. /// Tests that the clip property is null when the RatioVisible is 1.0
  233. /// and the ExpandDirection is Down.
  234. /// </summary>
  235. [TestMethod]
  236. [Description("Tests that the clip property is null when the RatioVisible is 1.0 and the ExpandDirection is Down.")]
  237. [Asynchronous]
  238. public void TestDownEmpty()
  239. {
  240. LinearClipper clipper = (LinearClipper)DefaultClipperToTest;
  241. clipper.Content = new TextBlock { Text = "Testing" };
  242. TestPanel.Children.Add(clipper);
  243. TestPanel
  244. .GetLayoutUpdated()
  245. .Take(1)
  246. .Do(_ =>
  247. {
  248. clipper.ExpandDirection = ExpandDirection.Down;
  249. clipper.RatioVisible = 0.0;
  250. })
  251. .Assert(() => ((RectangleGeometry)clipper.Clip).Rect.Height == 0)
  252. .Subscribe(_ =>
  253. {
  254. TestPanel.Children.Remove(clipper);
  255. EnqueueTestComplete();
  256. });
  257. }
  258. }
  259. }