UITest.cs 54 KB

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