UITest.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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. using System.Threading.Tasks;
  20. using System.Linq;
  21. using Application = TestStack.White.Application;
  22. using Window = TestStack.White.UIItems.WindowItems.Window;
  23. namespace WhiteTests
  24. {
  25. [TestClass]
  26. public class UITest
  27. {
  28. private TestStack.White.Application application;
  29. /// <summary>
  30. /// The directory of the input files, saved for repeated use
  31. /// </summary>
  32. private String input_file_dir = null;
  33. /// <summary>
  34. /// instance of TestContext to be able to access deployed files
  35. /// </summary>
  36. private TestContext testContextInstance;
  37. /// <summary>
  38. ///Gets or sets the test context which provides
  39. ///information about and functionality for the current test run.
  40. ///</summary>
  41. public TestContext TestContext
  42. {
  43. get
  44. {
  45. return testContextInstance;
  46. }
  47. set
  48. {
  49. testContextInstance = value;
  50. }
  51. }
  52. /// <summary>
  53. /// A function that returns the path to the test_input_files folder.
  54. /// Do with it what you want.
  55. /// </summary>
  56. /// <returns>the path to the test_input_files folder</returns>
  57. public String getSketchAssistantDirectory()
  58. {
  59. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  60. Match match = rx.Match(TestContext.DeploymentDirectory);
  61. String SketchAssistDir = match.Groups[1].Value;
  62. if (input_file_dir == null)
  63. {
  64. if (Directory.Exists(SketchAssistDir + @"WhiteTests\test_input_files\"))
  65. {
  66. input_file_dir = SketchAssistDir + @"WhiteTests\test_input_files\";
  67. }
  68. else if (Directory.Exists(SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\"))
  69. {
  70. input_file_dir = SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\";
  71. }
  72. else
  73. {
  74. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  75. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  76. String ProjectsDir = match_0.Groups[1].Value;
  77. var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
  78. input_file_dir = dirs[0];
  79. }
  80. }
  81. return input_file_dir;
  82. }
  83. public Window setupapp()
  84. {
  85. string[] files;
  86. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  87. Match match = rx.Match(TestContext.DeploymentDirectory);
  88. String SketchAssistDir = match.Groups[1].Value;
  89. try
  90. {
  91. files = Directory.GetFiles(SketchAssistDir + @"SketchAssistantWPF\bin\", "SketchAssistantWPF.exe", SearchOption.AllDirectories);
  92. }
  93. catch
  94. {
  95. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  96. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  97. String ProjectsDir = match_0.Groups[1].Value;
  98. files = Directory.GetFiles(ProjectsDir, "SketchAssistantWPF.exe", SearchOption.AllDirectories);
  99. }
  100. ProcessStartInfo processStart = new ProcessStartInfo(files[0], "-debug");
  101. /*
  102. string outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  103. string editedDir = outputDir.Replace("WhiteTests", "SketchAssistantWPF");
  104. string app_path = editedDir + @"\SketchAssistantWPF.exe";
  105. ProcessStartInfo processStart = new ProcessStartInfo(app_path, "-debug");*/
  106. application = Application.Launch(processStart);
  107. return application.GetWindow("Sketch Assistant");
  108. }
  109. [DataTestMethod]
  110. [TestCategory("Local")]
  111. [DataRow("line")]
  112. [DataRow("all")]
  113. [DataRow("circle_ellipse")]
  114. [DataRow("path")]
  115. [DataRow("polygon")]
  116. [DataRow("polyline")]
  117. [DataRow("rect")]
  118. public void LoadSVGFileTest(String filename)
  119. {
  120. Window mainWindow = setupapp();
  121. InputSimulator inputSimulator = new InputSimulator();
  122. Thread.Sleep(30);
  123. string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories);
  124. Thread.Sleep(30);
  125. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("LoadMenuButton")).Click();
  126. Thread.Sleep(30);
  127. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("SVGMenuButton")).Click();
  128. Thread.Sleep(1000);
  129. inputSimulator.Keyboard.TextEntry(getSketchAssistantDirectory() + @"whitelisted\" + filename + ".svg");
  130. Thread.Sleep(1000);
  131. inputSimulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);
  132. Thread.Sleep(1000);
  133. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  134. mainWindow.Close();
  135. }
  136. [TestMethod]
  137. [TestCategory("DirectInput")]
  138. public void DrawLineOnCanvasTest()
  139. {
  140. Window mainWindow = setupapp();
  141. Thread.Sleep(30);
  142. InputSimulator inputSimulator = new InputSimulator();
  143. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  144. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  145. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  146. Thread.Sleep(30);
  147. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  148. Thread.Sleep(30);
  149. inputSimulator.Mouse.MoveMouseBy(100, 100);
  150. inputSimulator.Mouse.LeftButtonDown();
  151. Thread.Sleep(30);
  152. inputSimulator.Mouse.MoveMouseBy(100, 100);
  153. Thread.Sleep(30);
  154. inputSimulator.Mouse.LeftButtonUp();
  155. Thread.Sleep(30);
  156. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  157. mainWindow.Close();
  158. }
  159. [TestMethod]
  160. [TestCategory("DirectInput")]
  161. public void UndoLineOnCanvasTest()
  162. {
  163. Window mainWindow = setupapp();
  164. Thread.Sleep(30);
  165. InputSimulator inputSimulator = new InputSimulator();
  166. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  167. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  168. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  169. Thread.Sleep(30);
  170. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  171. Thread.Sleep(30);
  172. inputSimulator.Mouse.MoveMouseBy(0, 200);
  173. inputSimulator.Mouse.LeftButtonDown();
  174. Thread.Sleep(30);
  175. inputSimulator.Mouse.MoveMouseBy(500, 300);
  176. Thread.Sleep(30);
  177. inputSimulator.Mouse.LeftButtonUp();
  178. Thread.Sleep(30);
  179. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  180. Thread.Sleep(30);
  181. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  182. Thread.Sleep(100);
  183. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  184. mainWindow.Close();
  185. }
  186. [TestMethod]
  187. [TestCategory("DirectInput")]
  188. public void InvalidLineTest()
  189. {
  190. Window mainWindow = setupapp();
  191. Thread.Sleep(30);
  192. InputSimulator inputSimulator = new InputSimulator();
  193. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  194. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  195. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  196. Thread.Sleep(30);
  197. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  198. Thread.Sleep(30);
  199. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DrawButton")).Click();
  200. Thread.Sleep(30);
  201. inputSimulator.Mouse.LeftButtonDown();
  202. inputSimulator.Mouse.MoveMouseBy(0, 200);
  203. Thread.Sleep(30);
  204. inputSimulator.Mouse.MoveMouseBy(500, 300);
  205. Thread.Sleep(30);
  206. inputSimulator.Mouse.LeftButtonUp();
  207. Thread.Sleep(30);
  208. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  209. Thread.Sleep(30);
  210. inputSimulator.Mouse.MoveMouseBy(-1000, 0);
  211. Thread.Sleep(30);
  212. inputSimulator.Mouse.LeftButtonDown();
  213. inputSimulator.Mouse.MoveMouseBy(1000, 0);
  214. inputSimulator.Mouse.LeftButtonUp();
  215. Thread.Sleep(30);
  216. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  217. mainWindow.Close();
  218. }
  219. [TestMethod]
  220. [TestCategory("DirectInput")]
  221. public void PointsOnCanvasSimilarityTest()
  222. {
  223. Window mainWindow = setupapp();
  224. Thread.Sleep(30);
  225. InputSimulator inputSimulator = new InputSimulator();
  226. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  227. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  228. Assert.AreEqual("-", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  229. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  230. inputSimulator.Mouse.MoveMouseBy(0, 200);
  231. inputSimulator.Mouse.LeftButtonDown();
  232. Thread.Sleep(30);
  233. inputSimulator.Mouse.LeftButtonUp();
  234. Thread.Sleep(30);
  235. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  236. Assert.AreEqual("-", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  237. Thread.Sleep(30);
  238. inputSimulator.Mouse.LeftButtonDown();
  239. Thread.Sleep(30);
  240. inputSimulator.Mouse.LeftButtonUp();
  241. Thread.Sleep(30);
  242. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  243. Assert.AreEqual("1", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  244. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  245. Thread.Sleep(30);
  246. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  247. Assert.AreEqual("-", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  248. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  249. Thread.Sleep(30);
  250. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  251. Assert.AreEqual("1", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  252. mainWindow.Close();
  253. }
  254. [TestMethod]
  255. [TestCategory("DebugInput")]
  256. public void CreateCanvasTest()
  257. {
  258. Window mainWindow = setupapp();
  259. Thread.Sleep(30);
  260. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  261. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  262. Thread.Sleep(30);
  263. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  264. mainWindow.Close();
  265. }
  266. [TestMethod]
  267. [TestCategory("DebugInput")]
  268. public void DrawLineTest()
  269. {
  270. Window mainWindow = setupapp();
  271. Thread.Sleep(30);
  272. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  273. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  274. Thread.Sleep(30);
  275. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  276. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  277. Thread.Sleep(30);
  278. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  279. Thread.Sleep(30);
  280. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  281. Thread.Sleep(7000);
  282. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  283. mainWindow.Close();
  284. }
  285. [TestMethod]
  286. [TestCategory("DebugInput")]
  287. public void DeleteLineTest()
  288. {
  289. Window mainWindow = setupapp();
  290. Thread.Sleep(30);
  291. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  292. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  293. Thread.Sleep(30);
  294. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  295. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DrawButton")).Click();
  296. Thread.Sleep(30);
  297. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  298. Thread.Sleep(30);
  299. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  300. Thread.Sleep(30);
  301. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  302. Thread.Sleep(7000);
  303. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  304. Thread.Sleep(30);
  305. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  306. Thread.Sleep(30);
  307. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  308. Thread.Sleep(30);
  309. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  310. Thread.Sleep(30);
  311. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  312. Thread.Sleep(7000);
  313. Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  314. mainWindow.Close();
  315. }
  316. [TestMethod]
  317. [TestCategory("DebugInput")]
  318. public void UndoTest()
  319. {
  320. Window mainWindow = setupapp();
  321. Thread.Sleep(30);
  322. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  323. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  324. Thread.Sleep(30);
  325. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  326. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  327. Thread.Sleep(30);
  328. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  329. Thread.Sleep(30);
  330. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  331. Thread.Sleep(7000);
  332. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  333. Thread.Sleep(30);
  334. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  335. Thread.Sleep(30);
  336. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  337. mainWindow.Close();
  338. }
  339. [TestMethod]
  340. [TestCategory("DebugInput")]
  341. public void RedoTest()
  342. {
  343. Window mainWindow = setupapp();
  344. Thread.Sleep(30);
  345. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  346. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  347. Thread.Sleep(30);
  348. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  349. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  350. Thread.Sleep(30);
  351. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  352. Thread.Sleep(30);
  353. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  354. Thread.Sleep(7000);
  355. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  356. Thread.Sleep(30);
  357. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  358. Thread.Sleep(30);
  359. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  360. Thread.Sleep(30);
  361. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  362. Thread.Sleep(30);
  363. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  364. mainWindow.Close();
  365. }
  366. [TestMethod]
  367. [TestCategory("DebugInput")]
  368. public void DrawSeveralLinesTest()
  369. {
  370. Window mainWindow = setupapp();
  371. Thread.Sleep(30);
  372. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  373. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  374. Thread.Sleep(30);
  375. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  376. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  377. Thread.Sleep(30);
  378. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  379. Thread.Sleep(30);
  380. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  381. Thread.Sleep(7000);
  382. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  383. Thread.Sleep(30);
  384. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  385. Thread.Sleep(30);
  386. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  387. Thread.Sleep(30);
  388. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  389. Thread.Sleep(30000);
  390. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  391. Thread.Sleep(30);
  392. mainWindow.Close();
  393. }
  394. [TestMethod]
  395. [TestCategory("DebugInput")]
  396. public void DeleteSeveralLinesTest()
  397. {
  398. Window mainWindow = setupapp();
  399. Thread.Sleep(30);
  400. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  401. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  402. Thread.Sleep(30);
  403. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  404. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  405. Thread.Sleep(30);
  406. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  407. Thread.Sleep(30);
  408. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  409. Thread.Sleep(7000);
  410. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  411. Thread.Sleep(30);
  412. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  413. Thread.Sleep(30);
  414. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  415. Thread.Sleep(30);
  416. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  417. Thread.Sleep(24000);
  418. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  419. Thread.Sleep(30);
  420. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  421. Thread.Sleep(30);
  422. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  423. Thread.Sleep(30);
  424. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  425. Thread.Sleep(30);
  426. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  427. Thread.Sleep(30);
  428. Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  429. Thread.Sleep(10000);
  430. Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  431. mainWindow.Close();
  432. }
  433. [TestMethod]
  434. [TestCategory("DebugInput")]
  435. public void UndoSeveralLinesTest()
  436. {
  437. Window mainWindow = setupapp();
  438. Thread.Sleep(30);
  439. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  440. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  441. Thread.Sleep(30);
  442. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  443. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  444. Thread.Sleep(30);
  445. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  446. Thread.Sleep(30);
  447. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  448. Thread.Sleep(7000);
  449. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  450. Thread.Sleep(30);
  451. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  452. Thread.Sleep(30);
  453. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  454. Thread.Sleep(30);
  455. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  456. Thread.Sleep(30000);
  457. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  458. Thread.Sleep(30);
  459. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  460. Thread.Sleep(30);
  461. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  462. Thread.Sleep(30);
  463. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  464. Thread.Sleep(30);
  465. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  466. Thread.Sleep(30);
  467. mainWindow.Close();
  468. }
  469. [TestMethod]
  470. [TestCategory("DebugInput")]
  471. public void RedoSeveralLinesTest()
  472. {
  473. Window mainWindow = setupapp();
  474. Thread.Sleep(30);
  475. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  476. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  477. Thread.Sleep(30);
  478. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  479. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  480. Thread.Sleep(30);
  481. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  482. Thread.Sleep(30);
  483. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  484. Thread.Sleep(7000);
  485. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  486. Thread.Sleep(30);
  487. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  488. Thread.Sleep(30);
  489. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  490. Thread.Sleep(30);
  491. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  492. Thread.Sleep(24000);
  493. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  494. Thread.Sleep(30);
  495. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  496. Thread.Sleep(30);
  497. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  498. Thread.Sleep(30);
  499. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  500. Thread.Sleep(30);
  501. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  502. Thread.Sleep(30);
  503. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  504. Thread.Sleep(30);
  505. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  506. Thread.Sleep(30);
  507. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  508. Thread.Sleep(30);
  509. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  510. Thread.Sleep(30);
  511. mainWindow.Close();
  512. }
  513. [TestMethod]
  514. [TestCategory("DebugInput")]
  515. public void UndoAndRedoTest()
  516. {
  517. Window mainWindow = setupapp();
  518. Thread.Sleep(30);
  519. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  520. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  521. Thread.Sleep(30);
  522. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  523. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  524. Thread.Sleep(30);
  525. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  526. Thread.Sleep(30);
  527. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  528. Thread.Sleep(7000);
  529. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  530. Thread.Sleep(30);
  531. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  532. Thread.Sleep(30);
  533. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  534. Thread.Sleep(30);
  535. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
  536. Thread.Sleep(24000);
  537. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  538. Thread.Sleep(30);
  539. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  540. Thread.Sleep(30);
  541. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  542. Thread.Sleep(30);
  543. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  544. Thread.Sleep(30);
  545. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  546. Thread.Sleep(30);
  547. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  548. Thread.Sleep(30);
  549. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  550. Thread.Sleep(30);
  551. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  552. Thread.Sleep(30);
  553. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  554. Thread.Sleep(30);
  555. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  556. Thread.Sleep(30);
  557. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  558. Thread.Sleep(30);
  559. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  560. Thread.Sleep(30);
  561. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  562. Thread.Sleep(7000);
  563. Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  564. Thread.Sleep(30);
  565. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  566. Thread.Sleep(30);
  567. Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  568. Thread.Sleep(30);
  569. mainWindow.Close();
  570. }
  571. [TestMethod]
  572. [TestCategory("DebugInput")]
  573. public void UndoAndDrawTest()
  574. {
  575. Window mainWindow = setupapp();
  576. Thread.Sleep(30);
  577. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  578. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  579. Thread.Sleep(30);
  580. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  581. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  582. Thread.Sleep(30);
  583. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  584. Thread.Sleep(30);
  585. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  586. Thread.Sleep(2000);
  587. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  588. Thread.Sleep(30);
  589. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  590. Thread.Sleep(30);
  591. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  592. Thread.Sleep(30);
  593. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  594. Thread.Sleep(30);
  595. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  596. Thread.Sleep(30);
  597. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  598. Thread.Sleep(2000);
  599. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  600. Thread.Sleep(30);
  601. mainWindow.Close();
  602. }
  603. [TestMethod]
  604. [TestCategory("DebugInput")]
  605. public void DeleteSeveralLinesAtOnceTest()
  606. {
  607. Window mainWindow = setupapp();
  608. Thread.Sleep(30);
  609. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  610. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  611. Thread.Sleep(30);
  612. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  613. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  614. Thread.Sleep(30);
  615. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  616. Thread.Sleep(30);
  617. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  618. Thread.Sleep(2000);
  619. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  620. Thread.Sleep(30);
  621. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  622. Thread.Sleep(30);
  623. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  624. Thread.Sleep(30);
  625. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  626. Thread.Sleep(2000);
  627. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  628. Thread.Sleep(30);
  629. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  630. Thread.Sleep(30);
  631. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  632. Thread.Sleep(30);
  633. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  634. Thread.Sleep(30);
  635. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  636. Thread.Sleep(2000);
  637. Assert.AreEqual("Last Action: Several Lines were deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  638. Thread.Sleep(30);
  639. mainWindow.Close();
  640. }
  641. [TestMethod]
  642. [TestCategory("DebugInput")]
  643. public void PointDrawTest()
  644. {
  645. Window mainWindow = setupapp();
  646. Thread.Sleep(30);
  647. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  648. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  649. Thread.Sleep(30);
  650. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  651. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  652. Thread.Sleep(30);
  653. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  654. Thread.Sleep(30);
  655. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
  656. Thread.Sleep(4000);
  657. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  658. Thread.Sleep(30);
  659. mainWindow.Close();
  660. }
  661. [TestMethod]
  662. [TestCategory("DebugInput")]
  663. public void NewCanvasAfterDrawTest()
  664. {
  665. Window mainWindow = setupapp();
  666. Thread.Sleep(30);
  667. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  668. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  669. Thread.Sleep(30);
  670. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  671. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  672. Thread.Sleep(30);
  673. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  674. Thread.Sleep(30);
  675. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  676. Thread.Sleep(4000);
  677. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  678. Thread.Sleep(30);
  679. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  680. Thread.Sleep(30);
  681. // Click on No button in warning
  682. Window messageBox0 = mainWindow.MessageBox("Warning");
  683. messageBox0.Get<Button>(SearchCriteria.ByText("No")).Click();
  684. Thread.Sleep(30);
  685. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  686. Thread.Sleep(30);
  687. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  688. Thread.Sleep(30);
  689. // close warning
  690. Window messageBox1 = mainWindow.MessageBox("Warning");
  691. messageBox1.Close();
  692. Thread.Sleep(30);
  693. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  694. Thread.Sleep(30);
  695. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  696. Thread.Sleep(30);
  697. // click yes button on warning
  698. Window messageBox2 = mainWindow.MessageBox("Warning");
  699. messageBox2.Get<Button>(SearchCriteria.ByText("Yes")).Click();
  700. Thread.Sleep(30);
  701. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  702. Thread.Sleep(30);
  703. mainWindow.Close();
  704. }
  705. }
  706. [TestClass]
  707. public class FileImporterTests
  708. {
  709. /// <summary>
  710. /// The directory of the input files, saved for repeated use
  711. /// </summary>
  712. private String input_file_dir = null;
  713. /// <summary>
  714. /// instance of TestContext to be able to access deployed files
  715. /// </summary>
  716. private TestContext testContextInstance;
  717. /// <summary>
  718. ///Gets or sets the test context which provides
  719. ///information about and functionality for the current test run.
  720. ///</summary>
  721. public TestContext TestContext
  722. {
  723. get
  724. {
  725. return testContextInstance;
  726. }
  727. set
  728. {
  729. testContextInstance = value;
  730. }
  731. }
  732. /// <summary>
  733. /// A function that returns the path to the test_input_files folder.
  734. /// Do with it what you want.
  735. /// </summary>
  736. /// <returns>the path to the test_input_files folder</returns>
  737. public String getSketchAssistantDirectory()
  738. {
  739. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  740. Match match = rx.Match(TestContext.DeploymentDirectory);
  741. String SketchAssistDir = match.Groups[1].Value;
  742. if (input_file_dir == null)
  743. {
  744. if (Directory.Exists(SketchAssistDir + @"\WhiteTests\test_input_files\"))
  745. {
  746. input_file_dir = SketchAssistDir + @"\WhiteTests\test_input_files\";
  747. }
  748. else if (Directory.Exists(SketchAssistDir + @"\WhiteTests\bin\Debug\test_input_files\"))
  749. {
  750. input_file_dir = SketchAssistDir + @"\WhiteTests\bin\Debug\test_input_files\";
  751. }
  752. else
  753. {
  754. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  755. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  756. String ProjectsDir = match_0.Groups[1].Value;
  757. var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
  758. input_file_dir = dirs[0];
  759. }
  760. }
  761. return input_file_dir;
  762. }
  763. /// <summary>
  764. /// 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
  765. /// </summary>
  766. /// <param name="xCoordinates">an array containing the x coordinates of the points that will be created (length divisible by 3)</param>
  767. /// <param name="yCoordinates">an array containing the y coordinates of the points that will be created (length divisible by 3)</param>
  768. [DataTestMethod]
  769. [TestCategory("FileIO")]
  770. [DataRow(new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
  771. [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
  772. [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 })]
  773. public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
  774. {
  775. FileImporter uut = new FileImporter();
  776. List<String> file = new List<string>();
  777. file.Add("drawing");
  778. file.Add("300x200");
  779. for (int i = 0; i < xCoordinates.Length - 2; i += 3)
  780. {
  781. file.Add("line");
  782. file.Add(xCoordinates[i] + ";" + yCoordinates[i]);
  783. file.Add(xCoordinates[i + 1] + ";" + yCoordinates[i + 1]);
  784. file.Add(xCoordinates[i + 2] + ";" + yCoordinates[i + 2]);
  785. file.Add("endline");
  786. }
  787. file.Add("enddrawing");
  788. Tuple<int, int, List<InternalLine>> values = uut.ParseISADInputForTesting(file.ToArray());
  789. Assert.AreEqual(xCoordinates.Length / 3, values.Item3.Count);
  790. InternalLine[] lines = values.Item3.ToArray();
  791. for (int i = 0; i < xCoordinates.Length - 2; i += 3)
  792. {
  793. Point[] currentLine = lines[i / 3].GetPoints().ToArray();
  794. Assert.AreEqual(3, currentLine.Length);
  795. for (int j = 0; j < 3; j++)
  796. {
  797. Assert.IsTrue(currentLine[j].X == xCoordinates[i + j] && currentLine[j].Y == yCoordinates[i + j]);
  798. }
  799. }
  800. }
  801. /// <summary>
  802. /// parses teh given invalid .isad files and verifies that a FileImporterException is thrown, but no other exception
  803. /// </summary>
  804. /// <param name="file">the input file represented as an array of lines</param>
  805. [DataTestMethod]
  806. [TestCategory("FileIO")]
  807. [DataRow(new String[] { })]
  808. [DataRow(new String[] { "begindrawing", "300x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  809. [DataRow(new String[] { "drawing", "300;300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  810. [DataRow(new String[] { "drawing", "30.5x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  811. [DataRow(new String[] { "drawing", "line", "50;50", "100;50", "endline", "enddrawing" })]
  812. [DataRow(new String[] { "drawing", "300x300", "beginline", "50;50", "100;50", "endline", "enddrawing" })]
  813. [DataRow(new String[] { "drawing", "300x300", "line", "500;50", "100;50", "endline", "enddrawing" })]
  814. [DataRow(new String[] { "drawing", "300x300", "line", "50x50", "100;50", "endline", "enddrawing" })]
  815. [DataRow(new String[] { "drawing", "300x300", "line", "50", "100", "endline", "enddrawing" })]
  816. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "line", "endline", "enddrawing" })]
  817. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "stopline", "enddrawing" })]
  818. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "enddrawing" })]
  819. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline", "endrawing" })]
  820. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline" })]
  821. public void ParseISADInputExceptionTest(String[] file)
  822. {
  823. bool correctExceptionThrown = false;
  824. FileImporter uut = new FileImporter();
  825. try
  826. {
  827. //try to initialize the left image with an invalid isad drawing
  828. Tuple<int, int, List<InternalLine>> values1 = uut.ParseISADInputForTesting(file);
  829. }
  830. catch (FileImporterException e)
  831. {
  832. //save the occurence of an exception
  833. correctExceptionThrown = true;
  834. System.Diagnostics.Debug.WriteLine(e.ToString());
  835. }
  836. catch (Exception)
  837. {
  838. //don't set success flag
  839. }
  840. //check that an exception has been thrown
  841. Assert.IsTrue(correctExceptionThrown);
  842. }
  843. /// <summary>
  844. /// 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)
  845. /// </summary>
  846. [TestMethod]
  847. [TestCategory("FileIO")]
  848. public void ParseSVGInputNoErrorForWhitelistedFilesTest()
  849. {
  850. FileImporter uut = new FileImporter();
  851. string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories);
  852. Assert.IsTrue(files.Length > 0);
  853. foreach (string s in files) //parse each of the whitelisted files
  854. {
  855. Console.WriteLine(s);
  856. bool noExceptionThrown = true;
  857. try
  858. {
  859. uut.ParseSVGInputFile(s, 10000, 10000);
  860. }
  861. catch (Exception)
  862. {
  863. noExceptionThrown = false;
  864. }
  865. Assert.IsTrue(noExceptionThrown);
  866. }
  867. }
  868. /// <summary>
  869. /// parses all blacklisted files and ensures an instance of FileIporterException is thrown for each file, but no other exceptions occur
  870. /// </summary>
  871. [TestMethod]
  872. [TestCategory("FileIO")]
  873. public void ParseSVGInputNoErrorForBlacklistedFilesTest()
  874. {
  875. FileImporter uut = new FileImporter();
  876. string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\blacklisted", "*.svg", SearchOption.AllDirectories);
  877. Assert.IsTrue(files.Length > 0);
  878. foreach (string s in files) //parse each of the blacklisted files
  879. {
  880. bool correctExceptionThrown = false;
  881. try
  882. {
  883. uut.ParseSVGInputFile(s, 10000, 10000);
  884. }
  885. catch (FileImporterException e)
  886. {
  887. System.Diagnostics.Debug.WriteLine(e.ToString());
  888. correctExceptionThrown = true;
  889. }
  890. catch (Exception)
  891. {
  892. }
  893. Assert.IsTrue(correctExceptionThrown);
  894. }
  895. }
  896. }
  897. [TestClass]
  898. public class SimilarityCalculationTests
  899. {
  900. /// <summary>
  901. /// The debug data element used to generate random lines.
  902. /// </summary>
  903. private DebugData DebugData = new DebugData();
  904. /// <summary>
  905. /// Generates random lines and tests how similar they are.
  906. /// To test the similarity score always stays between 0 and 1.
  907. /// </summary>
  908. [TestMethod]
  909. [TestCategory("UnitTest")]
  910. public void StaysWithinParameters()
  911. {
  912. Parallel.For(1, 100,
  913. i =>
  914. {
  915. InternalLine l0 = DebugData.GetRandomLine(1, (uint)i);
  916. InternalLine l1 = DebugData.GetRandomLine(1, (uint)i);
  917. var sim = GeometryCalculator.CalculateSimilarity(l0, l1);
  918. Assert.IsTrue((sim >= 0));
  919. Assert.IsTrue((sim <= 1));
  920. });
  921. }
  922. [TestMethod]
  923. [TestCategory("UnitTest")]
  924. public void CorrectSimilarity()
  925. {
  926. Parallel.ForEach(DebugData.GetSimilarityTestData(),
  927. tup =>
  928. {
  929. InternalLine l0 = tup.Item1;
  930. InternalLine l1 = tup.Item2;
  931. var sim = GeometryCalculator.CalculateSimilarity(l0, l1);
  932. Assert.AreEqual(tup.Item3, sim, 0.00000001);
  933. });
  934. }
  935. }
  936. [TestClass]
  937. public class InternalLineUnitTests
  938. {
  939. /// <summary>
  940. /// The debug data element used to generate random lines.
  941. /// </summary>
  942. private DebugData DebugData = new DebugData();
  943. [TestMethod]
  944. [TestCategory("UnitTest")]
  945. public void MakePermanentTest()
  946. {
  947. List<Point> points = new List<Point>();
  948. points.AddRange(DebugData.debugPoints4);
  949. InternalLine uut = new InternalLine(points);
  950. Assert.AreEqual(false, uut.isPoint);
  951. uut.MakePermanent(5);
  952. Assert.AreEqual(true, uut.isPoint);
  953. Assert.AreEqual(5, uut.GetID());
  954. Assert.AreEqual(0, uut.GetLength());
  955. }
  956. [DataTestMethod]
  957. [TestCategory("UnitTest")]
  958. [DataRow(new int[] { 1, 1, 3, 3 }, new int[] { 1, 1, 2, 2, 3, 3 }, false, 2.828427125)]
  959. [DataRow(new int[] { 1, 1, 3, 3 }, new int[] { 1, 1, 2, 2, 3, 3 }, true, 2.828427125)]
  960. [DataRow(new int[] { 1, 1, 1, 4, 3, 4 }, new int[] { 1, 1, 1, 2, 1, 3, 1, 4, 2, 4, 3, 4 }, false, 5)]
  961. [DataRow(new int[] { 1, 1, 1, 4, 3, 4 }, new int[] { 1, 1, 1, 2, 1, 3, 1, 4, 2, 4, 3, 4 }, true, 5)]
  962. public void PermanentLineTest(int[] inPoints, int[] outPoints, bool isTemp, double len)
  963. {
  964. List<Point> inLine = new List<Point>(); List<Point> outLine = new List<Point>();
  965. for (int i = 0; i < inPoints.Length; i += 2) inLine.Add(new Point(inPoints[i], inPoints[i + 1]));
  966. for (int i = 0; i < outPoints.Length; i += 2) outLine.Add(new Point(outPoints[i], outPoints[i + 1]));
  967. InternalLine uut;
  968. if (isTemp)
  969. {
  970. uut = new InternalLine(inLine);
  971. var zip = inLine.Zip(uut.GetPoints(), (a, b) => new Tuple<Point, Point>(a, b));
  972. foreach (Tuple<Point, Point> tup in zip)
  973. {
  974. Assert.AreEqual(tup.Item1, tup.Item2);
  975. }
  976. }
  977. else
  978. {
  979. uut = new InternalLine(inLine, 0);
  980. var zip = outLine.Zip(uut.GetPoints(), (a, b) => new Tuple<Point, Point>(a, b));
  981. foreach (Tuple<Point, Point> tup in zip)
  982. {
  983. Assert.AreEqual(tup.Item1, tup.Item2);
  984. }
  985. }
  986. Assert.AreEqual(len, uut.GetLength(), 0.000001);
  987. }
  988. }
  989. }