UITest.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using TestStack.White;
  6. using TestStack.White.UIItems;
  7. using TestStack.White.UIItems.WindowItems;
  8. using TestStack.White.UIItems.Finders;
  9. using System.Threading;
  10. using SketchAssistantWPF;
  11. using System.Windows;
  12. using System.Diagnostics;
  13. using TestStack.White.UIItems.WindowStripControls;
  14. using TestStack.White.UIItems.MenuItems;
  15. using System.Collections.Generic;
  16. using System.Text.RegularExpressions;
  17. //using WindowsInput;
  18. //using WindowsInput.Native;
  19. namespace WhiteTests
  20. {
  21. [TestClass]
  22. public class UITest
  23. {
  24. private TestStack.White.Application application;
  25. /// <summary>
  26. /// The directory of the input files, saved for repeated use
  27. /// </summary>
  28. private String input_file_dir = null;
  29. /// <summary>
  30. /// instance of TestContext to be able to access deployed files
  31. /// </summary>
  32. private TestContext testContextInstance;
  33. /// <summary>
  34. ///Gets or sets the test context which provides
  35. ///information about and functionality for the current test run.
  36. ///</summary>
  37. public TestContext TestContext
  38. {
  39. get
  40. {
  41. return testContextInstance;
  42. }
  43. set
  44. {
  45. testContextInstance = value;
  46. }
  47. }
  48. /// <summary>
  49. /// A function that returns the path to the test_input_files folder.
  50. /// Do with it what you want.
  51. /// </summary>
  52. /// <returns>the path to the test_input_files folder</returns>
  53. public String getSketchAssistantDirectory()
  54. {
  55. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  56. Match match = rx.Match(TestContext.DeploymentDirectory);
  57. String SketchAssistDir = match.Groups[1].Value;
  58. if (input_file_dir == null)
  59. {
  60. if (Directory.Exists(SketchAssistDir + @"WhiteTests\test_input_files\"))
  61. {
  62. input_file_dir = SketchAssistDir + @"WhiteTests\test_input_files\";
  63. }
  64. else if (Directory.Exists(SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\"))
  65. {
  66. input_file_dir = SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\";
  67. }
  68. else
  69. {
  70. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  71. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  72. String ProjectsDir = match_0.Groups[1].Value;
  73. var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
  74. input_file_dir = dirs[0];
  75. }
  76. }
  77. return input_file_dir;
  78. }
  79. public Window setupapp()
  80. {
  81. string[] files;
  82. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  83. Match match = rx.Match(TestContext.DeploymentDirectory);
  84. String SketchAssistDir = match.Groups[1].Value;
  85. try
  86. {
  87. files = Directory.GetFiles(SketchAssistDir + @"SketchAssistantWPF\bin\", "SketchAssistantWPF.exe", SearchOption.AllDirectories);
  88. }
  89. catch
  90. {
  91. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  92. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  93. String ProjectsDir = match_0.Groups[1].Value;
  94. files = Directory.GetFiles(ProjectsDir, "SketchAssistantWPF.exe", SearchOption.AllDirectories);
  95. }
  96. ProcessStartInfo processStart = new ProcessStartInfo(files[0], "-debug");
  97. application = Application.Launch(processStart);
  98. return application.GetWindow("Sketch Assistant");
  99. }
  100. [TestMethod]
  101. [TestCategory("bla")]
  102. public void CreateCanvasTest()
  103. {
  104. Window mainWindow = setupapp();
  105. Thread.Sleep(20);
  106. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  107. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  108. Thread.Sleep(20);
  109. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  110. mainWindow.Close();
  111. }
  112. [TestMethod]
  113. [TestCategory("bla")]
  114. public void DrawLineTest()
  115. {
  116. Window mainWindow = setupapp();
  117. Thread.Sleep(20);
  118. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  119. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  120. Thread.Sleep(20);
  121. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  122. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  123. Thread.Sleep(20);
  124. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  125. Thread.Sleep(20);
  126. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  127. Thread.Sleep(7000);
  128. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  129. mainWindow.Close();
  130. }
  131. [TestMethod]
  132. public void DeleteLineTest()
  133. {
  134. Window mainWindow = setupapp();
  135. Thread.Sleep(20);
  136. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  137. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  138. Thread.Sleep(20);
  139. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  140. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DrawButton")).Click();
  141. Thread.Sleep(20);
  142. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  143. Thread.Sleep(20);
  144. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  145. Thread.Sleep(20);
  146. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  147. Thread.Sleep(7000);
  148. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  149. Thread.Sleep(20);
  150. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  151. Thread.Sleep(20);
  152. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  153. Thread.Sleep(20);
  154. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  155. Thread.Sleep(20);
  156. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  157. Thread.Sleep(7000);
  158. Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  159. mainWindow.Close();
  160. }
  161. [TestMethod]
  162. [TestCategory("bla")]
  163. public void UndoTest()
  164. {
  165. Window mainWindow = setupapp();
  166. Thread.Sleep(20);
  167. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  168. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  169. Thread.Sleep(20);
  170. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  171. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  172. Thread.Sleep(20);
  173. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  174. Thread.Sleep(20);
  175. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  176. Thread.Sleep(7000);
  177. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  178. Thread.Sleep(20);
  179. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  180. Thread.Sleep(20);
  181. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  182. mainWindow.Close();
  183. }
  184. [TestMethod]
  185. [TestCategory("bla")]
  186. public void RedoTest()
  187. {
  188. Window mainWindow = setupapp();
  189. Thread.Sleep(20);
  190. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  191. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  192. Thread.Sleep(20);
  193. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  194. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  195. Thread.Sleep(20);
  196. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  197. Thread.Sleep(20);
  198. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  199. Thread.Sleep(7000);
  200. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  201. Thread.Sleep(20);
  202. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  203. Thread.Sleep(20);
  204. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  205. Thread.Sleep(20);
  206. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  207. Thread.Sleep(20);
  208. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  209. mainWindow.Close();
  210. }
  211. [TestMethod]
  212. public void DrawSeveralLines()
  213. {
  214. Window mainWindow = setupapp();
  215. Thread.Sleep(20);
  216. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  217. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  218. Thread.Sleep(20);
  219. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  220. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  221. Thread.Sleep(20);
  222. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  223. Thread.Sleep(20);
  224. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  225. Thread.Sleep(7000);
  226. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  227. Thread.Sleep(20);
  228. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  229. Thread.Sleep(20);
  230. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  231. Thread.Sleep(20);
  232. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  233. Thread.Sleep(30000);
  234. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  235. Thread.Sleep(20);
  236. mainWindow.Close();
  237. }
  238. [TestMethod]
  239. public void DeleteSeveralLines()
  240. {
  241. Window mainWindow = setupapp();
  242. Thread.Sleep(20);
  243. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  244. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  245. Thread.Sleep(20);
  246. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  247. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  248. Thread.Sleep(20);
  249. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  250. Thread.Sleep(20);
  251. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  252. Thread.Sleep(7000);
  253. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  254. Thread.Sleep(20);
  255. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  256. Thread.Sleep(20);
  257. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  258. Thread.Sleep(20);
  259. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  260. Thread.Sleep(24000);
  261. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  262. Thread.Sleep(20);
  263. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  264. Thread.Sleep(20);
  265. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  266. Thread.Sleep(20);
  267. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  268. Thread.Sleep(20);
  269. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  270. Thread.Sleep(20);
  271. Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  272. Thread.Sleep(10000);
  273. Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  274. mainWindow.Close();
  275. }
  276. [TestMethod]
  277. public void UndoSeveralLines()
  278. {
  279. Window mainWindow = setupapp();
  280. Thread.Sleep(20);
  281. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  282. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  283. Thread.Sleep(20);
  284. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  285. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  286. Thread.Sleep(20);
  287. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  288. Thread.Sleep(20);
  289. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  290. Thread.Sleep(7000);
  291. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  292. Thread.Sleep(20);
  293. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  294. Thread.Sleep(20);
  295. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  296. Thread.Sleep(20);
  297. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  298. Thread.Sleep(30000);
  299. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  300. Thread.Sleep(20);
  301. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  302. Thread.Sleep(20);
  303. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  304. Thread.Sleep(20);
  305. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  306. Thread.Sleep(20);
  307. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  308. Thread.Sleep(20);
  309. mainWindow.Close();
  310. }
  311. [TestMethod]
  312. public void RedoSeveralLines()
  313. {
  314. Window mainWindow = setupapp();
  315. Thread.Sleep(20);
  316. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  317. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  318. Thread.Sleep(20);
  319. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  320. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  321. Thread.Sleep(20);
  322. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  323. Thread.Sleep(20);
  324. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  325. Thread.Sleep(7000);
  326. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  327. Thread.Sleep(20);
  328. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  329. Thread.Sleep(20);
  330. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  331. Thread.Sleep(20);
  332. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  333. Thread.Sleep(24000);
  334. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  335. Thread.Sleep(20);
  336. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  337. Thread.Sleep(20);
  338. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  339. Thread.Sleep(20);
  340. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  341. Thread.Sleep(20);
  342. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  343. Thread.Sleep(20);
  344. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  345. Thread.Sleep(20);
  346. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  347. Thread.Sleep(20);
  348. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  349. Thread.Sleep(20);
  350. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  351. Thread.Sleep(20);
  352. mainWindow.Close();
  353. }
  354. [TestMethod]
  355. public void UndoAndRedoTests()
  356. {
  357. Window mainWindow = setupapp();
  358. Thread.Sleep(20);
  359. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  360. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  361. Thread.Sleep(20);
  362. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  363. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  364. Thread.Sleep(20);
  365. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  366. Thread.Sleep(20);
  367. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  368. Thread.Sleep(7000);
  369. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  370. Thread.Sleep(20);
  371. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  372. Thread.Sleep(20);
  373. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  374. Thread.Sleep(20);
  375. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  376. Thread.Sleep(24000);
  377. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  378. Thread.Sleep(20);
  379. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  380. Thread.Sleep(20);
  381. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  382. Thread.Sleep(20);
  383. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  384. Thread.Sleep(20);
  385. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  386. Thread.Sleep(20);
  387. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  388. Thread.Sleep(20);
  389. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  390. Thread.Sleep(20);
  391. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  392. Thread.Sleep(20);
  393. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  394. Thread.Sleep(20);
  395. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  396. Thread.Sleep(20);
  397. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  398. Thread.Sleep(20);
  399. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  400. Thread.Sleep(20);
  401. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  402. Thread.Sleep(7000);
  403. Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  404. Thread.Sleep(20);
  405. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  406. Thread.Sleep(20);
  407. Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  408. Thread.Sleep(20);
  409. mainWindow.Close();
  410. }
  411. [TestMethod]
  412. public void PointDraw()
  413. {
  414. Window mainWindow = setupapp();
  415. Thread.Sleep(20);
  416. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  417. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  418. Thread.Sleep(20);
  419. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  420. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  421. Thread.Sleep(20);
  422. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  423. Thread.Sleep(20);
  424. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  425. Thread.Sleep(4000);
  426. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  427. Thread.Sleep(20);
  428. mainWindow.Close();
  429. }
  430. [TestMethod]
  431. public void NewCanvasAfterDraw()
  432. {
  433. Window mainWindow = setupapp();
  434. Thread.Sleep(20);
  435. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  436. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  437. Thread.Sleep(20);
  438. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  439. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  440. Thread.Sleep(20);
  441. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  442. Thread.Sleep(20);
  443. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  444. Thread.Sleep(4000);
  445. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  446. Thread.Sleep(20);
  447. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  448. Thread.Sleep(20);
  449. // Click on No button in warning
  450. Window messageBox0 = mainWindow.MessageBox("Warning");
  451. messageBox0.Get<Button>(SearchCriteria.ByText("No")).Click();
  452. Thread.Sleep(20);
  453. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  454. Thread.Sleep(20);
  455. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  456. Thread.Sleep(20);
  457. // close warning
  458. Window messageBox1 = mainWindow.MessageBox("Warning");
  459. messageBox1.Close();
  460. Thread.Sleep(20);
  461. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  462. Thread.Sleep(20);
  463. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  464. Thread.Sleep(20);
  465. // click yes button on warning
  466. Window messageBox2 = mainWindow.MessageBox("Warning");
  467. messageBox2.Get<Button>(SearchCriteria.ByText("Yes")).Click();
  468. Thread.Sleep(20);
  469. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  470. Thread.Sleep(20);
  471. mainWindow.Close();
  472. }
  473. }
  474. [TestClass]
  475. [DeploymentItem(@"WhiteTests\test_input_files\")]
  476. public class FileImporterTests
  477. {
  478. /// <summary>
  479. /// The directory of the input files, saved for repeated use
  480. /// </summary>
  481. private String input_file_dir = null;
  482. /// <summary>
  483. /// instance of TestContext to be able to access deployed files
  484. /// </summary>
  485. private TestContext testContextInstance;
  486. /// <summary>
  487. ///Gets or sets the test context which provides
  488. ///information about and functionality for the current test run.
  489. ///</summary>
  490. public TestContext TestContext
  491. {
  492. get
  493. {
  494. return testContextInstance;
  495. }
  496. set
  497. {
  498. testContextInstance = value;
  499. }
  500. }
  501. /// <summary>
  502. /// A function that returns the path to the test_input_files folder.
  503. /// Do with it what you want.
  504. /// </summary>
  505. /// <returns>the path to the test_input_files folder</returns>
  506. public String getSketchAssistantDirectory()
  507. {
  508. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  509. Match match = rx.Match(TestContext.DeploymentDirectory);
  510. String SketchAssistDir = match.Groups[1].Value;
  511. if (input_file_dir == null)
  512. {
  513. if (Directory.Exists(SketchAssistDir + @"\WhiteTests\test_input_files\"))
  514. {
  515. input_file_dir = SketchAssistDir + @"\WhiteTests\test_input_files\";
  516. }
  517. else if (Directory.Exists(SketchAssistDir + @"\WhiteTests\bin\Debug\test_input_files\"))
  518. {
  519. input_file_dir = SketchAssistDir + @"\WhiteTests\bin\Debug\test_input_files\";
  520. }
  521. else
  522. {
  523. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  524. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  525. String ProjectsDir = match_0.Groups[1].Value;
  526. var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
  527. input_file_dir = dirs[0];
  528. }
  529. }
  530. return input_file_dir;
  531. }
  532. /// <summary>
  533. /// creates a valid .isad file from the given sets of coordinates (number divisible by 3) by creating a line for every three consecutive points, parses the file and verifies that all lines and their points have been parsed correctly
  534. /// </summary>
  535. /// <param name="xCoordinates">an array containing the x coordinates of the points that will be created (length divisible by 3)</param>
  536. /// <param name="yCoordinates">an array containing the y coordinates of the points that will be created (length divisible by 3)</param>
  537. [DataTestMethod]
  538. [TestCategory("bla")]
  539. [DataRow(new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
  540. [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
  541. [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 })]
  542. public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
  543. {
  544. FileImporter uut = new FileImporter();
  545. List<String> file = new List<string>();
  546. file.Add("drawing");
  547. file.Add("300x200");
  548. for (int i = 0; i < xCoordinates.Length - 2; i += 3)
  549. {
  550. file.Add("line");
  551. file.Add(xCoordinates[i] + ";" + yCoordinates[i]);
  552. file.Add(xCoordinates[i + 1] + ";" + yCoordinates[i + 1]);
  553. file.Add(xCoordinates[i + 2] + ";" + yCoordinates[i + 2]);
  554. file.Add("endline");
  555. }
  556. file.Add("enddrawing");
  557. Tuple<int, int, List<InternalLine>> values = uut.ParseISADInputForTesting(file.ToArray());
  558. Assert.AreEqual(xCoordinates.Length / 3, values.Item3.Count);
  559. InternalLine[] lines = values.Item3.ToArray();
  560. for (int i = 0; i < xCoordinates.Length - 2; i += 3)
  561. {
  562. Point[] currentLine = lines[i / 3].GetPoints().ToArray();
  563. Assert.AreEqual(3, currentLine.Length);
  564. for (int j = 0; j < 3; j++)
  565. {
  566. Assert.IsTrue(currentLine[j].X == xCoordinates[i + j] && currentLine[j].Y == yCoordinates[i + j]);
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// parses teh given invalid .isad files and verifies that a FileImporterException is thrown, but no other exception
  572. /// </summary>
  573. /// <param name="file">the input file represented as an array of lines</param>
  574. [DataTestMethod]
  575. [TestCategory("bla")]
  576. [DataRow(new String[] { })]
  577. [DataRow(new String[] { "begindrawing", "300x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  578. [DataRow(new String[] { "drawing", "300;300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  579. [DataRow(new String[] { "drawing", "30.5x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  580. [DataRow(new String[] { "drawing", "line", "50;50", "100;50", "endline", "enddrawing" })]
  581. [DataRow(new String[] { "drawing", "300x300", "beginline", "50;50", "100;50", "endline", "enddrawing" })]
  582. [DataRow(new String[] { "drawing", "300x300", "line", "500;50", "100;50", "endline", "enddrawing" })]
  583. [DataRow(new String[] { "drawing", "300x300", "line", "50x50", "100;50", "endline", "enddrawing" })]
  584. [DataRow(new String[] { "drawing", "300x300", "line", "50", "100", "endline", "enddrawing" })]
  585. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "line", "endline", "enddrawing" })]
  586. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "stopline", "enddrawing" })]
  587. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "enddrawing" })]
  588. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline", "endrawing" })]
  589. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline" })]
  590. public void ParseISADInputExceptionTest(String[] file)
  591. {
  592. bool correctExceptionThrown = false;
  593. FileImporter uut = new FileImporter();
  594. try
  595. {
  596. //try to initialize the left image with an invalid isad drawing
  597. Tuple<int, int, List<InternalLine>> values1 = uut.ParseISADInputForTesting(file);
  598. }
  599. catch (FileImporterException)
  600. {
  601. //save the occurence of an exception
  602. correctExceptionThrown = true;
  603. }
  604. catch (Exception e)
  605. {
  606. //don't set success flag
  607. }
  608. //check that an exception has been thrown
  609. Assert.IsTrue(correctExceptionThrown);
  610. }
  611. /// <summary>
  612. /// parses all whitelisted files and ensures no exceptions are thrown (parsing abortion, e.g. due to corrupted input files, are realized by throwing a FileImporterException)
  613. /// </summary>
  614. [TestMethod]
  615. [TestCategory("FileIO")]
  616. public void ParseSVGInputNoErrorForWhitelistedFilesTest()
  617. {
  618. FileImporter uut = new FileImporter();
  619. string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories);
  620. Assert.IsTrue(files.Length > 0);
  621. foreach (string s in files) //parse each of the whitelisted files
  622. {
  623. Console.WriteLine(s);
  624. bool noExceptionThrown = true;
  625. try
  626. {
  627. uut.ParseSVGInputFile(s, 10000, 10000);
  628. }
  629. catch (Exception e)
  630. {
  631. noExceptionThrown = false;
  632. }
  633. Assert.IsTrue(noExceptionThrown);
  634. }
  635. }
  636. /// <summary>
  637. /// parses all blacklisted files and ensures an instance of FileIporterException is thrown for each file, but no other exceptions occur
  638. /// </summary>
  639. [TestMethod]
  640. [TestCategory("FileIO")]
  641. public void ParseSVGInputNoErrorForBlacklistedFilesTest()
  642. {
  643. FileImporter uut = new FileImporter();
  644. string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\blacklisted", "*.svg", SearchOption.AllDirectories);
  645. Assert.IsTrue(files.Length > 0);
  646. foreach (string s in files) //parse each of the blacklisted files
  647. {
  648. bool correctExceptionThrown = false;
  649. try
  650. {
  651. uut.ParseSVGInputFile(s, 10000, 10000);
  652. }
  653. catch (FileImporterException e)
  654. {
  655. correctExceptionThrown = true;
  656. }
  657. catch (Exception e)
  658. {
  659. }
  660. Assert.IsTrue(correctExceptionThrown);
  661. }
  662. }
  663. }
  664. }