UITest.cs 36 KB

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