UITest.cs 53 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. using System.Drawing;
  24. using System.Drawing.Imaging;
  25. namespace WhiteTests
  26. {
  27. [TestClass]
  28. public class UITest
  29. {
  30. private TestStack.White.Application application;
  31. /// <summary>
  32. /// The directory of the input files, saved for repeated use
  33. /// </summary>
  34. private String input_file_dir = null;
  35. /// <summary>
  36. /// instance of TestContext to be able to access deployed files
  37. /// </summary>
  38. private TestContext testContextInstance;
  39. /// <summary>
  40. ///Gets or sets the test context which provides
  41. ///information about and functionality for the current test run.
  42. ///</summary>
  43. public TestContext TestContext
  44. {
  45. get
  46. {
  47. return testContextInstance;
  48. }
  49. set
  50. {
  51. testContextInstance = value;
  52. }
  53. }
  54. /// <summary>
  55. /// A function that returns the path to the test_input_files folder.
  56. /// Do with it what you want.
  57. /// </summary>
  58. /// <returns>the path to the test_input_files folder</returns>
  59. public String getSketchAssistantDirectory()
  60. {
  61. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  62. Match match = rx.Match(TestContext.DeploymentDirectory);
  63. String SketchAssistDir = match.Groups[1].Value;
  64. if (input_file_dir == null)
  65. {
  66. if (Directory.Exists(SketchAssistDir + @"WhiteTests\test_input_files\"))
  67. {
  68. input_file_dir = SketchAssistDir + @"WhiteTests\test_input_files\";
  69. }
  70. else if (Directory.Exists(SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\"))
  71. {
  72. input_file_dir = SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\";
  73. }
  74. else
  75. {
  76. Regex rx_0 = new Regex(@"^(.*\\projects\\)");
  77. Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
  78. String ProjectsDir = match_0.Groups[1].Value;
  79. var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
  80. input_file_dir = dirs[0];
  81. }
  82. }
  83. return input_file_dir;
  84. }
  85. public Window setupapp()
  86. {
  87. string outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  88. string editedDir = outputDir.Replace("WhiteTests", "SketchAssistantWPF");
  89. string app_path = editedDir + @"\SketchAssistantWPF.exe";
  90. ProcessStartInfo processStart = new ProcessStartInfo(app_path, "-debug");
  91. application = Application.Launch(processStart);
  92. return application.GetWindow("Sketch Assistant");
  93. }
  94. public void printscreen()
  95. {
  96. Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
  97. Match match = rx.Match(TestContext.DeploymentDirectory);
  98. String SketchAssistDir = match.Groups[1].Value;
  99. Bitmap bitmap = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
  100. System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
  101. Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
  102. graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
  103. bitmap.Save(SketchAssistDir + "screen" + ".jpg", ImageFormat.Jpeg);
  104. }
  105. [DataTestMethod]
  106. [TestCategory("FileIO")]
  107. [DataRow("line")]
  108. public void LoadSVGFileTest(String filename)
  109. {
  110. Window mainWindow = setupapp();
  111. InputSimulator inputSimulator = new InputSimulator();
  112. Thread.Sleep(20);
  113. string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories);
  114. Thread.Sleep(20);
  115. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("LoadMenuButton")).Click();
  116. Thread.Sleep(20);
  117. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("SVGMenuButton")).Click();
  118. Thread.Sleep(20);
  119. printscreen();
  120. Thread.Sleep(1000);
  121. printscreen();
  122. inputSimulator.Keyboard.TextEntry(getSketchAssistantDirectory() + @"whitelisted\" + filename + ".svg");
  123. Thread.Sleep(1000);
  124. inputSimulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);
  125. Thread.Sleep(1000);
  126. //Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  127. mainWindow.Close();
  128. }
  129. [TestMethod]
  130. [TestCategory("DirectInput")]
  131. public void DrawLineOnCanvasTest()
  132. {
  133. Window mainWindow = setupapp();
  134. Thread.Sleep(20);
  135. InputSimulator inputSimulator = new InputSimulator();
  136. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  137. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  138. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  139. Thread.Sleep(20);
  140. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  141. Thread.Sleep(20);
  142. inputSimulator.Mouse.MoveMouseBy(100,100);
  143. inputSimulator.Mouse.LeftButtonDown();
  144. Thread.Sleep(20);
  145. inputSimulator.Mouse.MoveMouseBy(100, 100);
  146. Thread.Sleep(20);
  147. inputSimulator.Mouse.LeftButtonUp();
  148. Thread.Sleep(20);
  149. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  150. mainWindow.Close();
  151. }
  152. [TestMethod]
  153. [TestCategory("DirectInput")]
  154. public void UndoLineOnCanvasTest()
  155. {
  156. Window mainWindow = setupapp();
  157. Thread.Sleep(20);
  158. InputSimulator inputSimulator = new InputSimulator();
  159. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  160. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  161. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  162. Thread.Sleep(20);
  163. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  164. Thread.Sleep(20);
  165. inputSimulator.Mouse.MoveMouseBy(0, 200);
  166. inputSimulator.Mouse.LeftButtonDown();
  167. Thread.Sleep(20);
  168. inputSimulator.Mouse.MoveMouseBy(500, 300);
  169. Thread.Sleep(20);
  170. inputSimulator.Mouse.LeftButtonUp();
  171. Thread.Sleep(20);
  172. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  173. Thread.Sleep(20);
  174. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  175. Thread.Sleep(100);
  176. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  177. mainWindow.Close();
  178. }
  179. [TestMethod]
  180. [TestCategory("DirectInput")]
  181. public void InvalidLineTest()
  182. {
  183. Window mainWindow = setupapp();
  184. Thread.Sleep(20);
  185. InputSimulator inputSimulator = new InputSimulator();
  186. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  187. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  188. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  189. Thread.Sleep(20);
  190. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  191. Thread.Sleep(20);
  192. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DrawButton")).Click();
  193. Thread.Sleep(20);
  194. inputSimulator.Mouse.LeftButtonDown();
  195. inputSimulator.Mouse.MoveMouseBy(0, 200);
  196. Thread.Sleep(20);
  197. inputSimulator.Mouse.MoveMouseBy(500, 300);
  198. Thread.Sleep(20);
  199. inputSimulator.Mouse.LeftButtonUp();
  200. Thread.Sleep(20);
  201. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  202. Thread.Sleep(20);
  203. inputSimulator.Mouse.MoveMouseBy(-1000, 0);
  204. Thread.Sleep(20);
  205. inputSimulator.Mouse.LeftButtonDown();
  206. inputSimulator.Mouse.MoveMouseBy(1000, 0);
  207. inputSimulator.Mouse.LeftButtonUp();
  208. Thread.Sleep(20);
  209. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  210. mainWindow.Close();
  211. }
  212. [TestMethod]
  213. [TestCategory("DirectInput")]
  214. public void PointsOnCanvasSimilarityTest()
  215. {
  216. Window mainWindow = setupapp();
  217. Thread.Sleep(20);
  218. InputSimulator inputSimulator = new InputSimulator();
  219. MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator);
  220. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  221. Assert.AreEqual("-", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  222. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  223. inputSimulator.Mouse.MoveMouseBy(0, 200);
  224. inputSimulator.Mouse.LeftButtonDown();
  225. Thread.Sleep(20);
  226. inputSimulator.Mouse.LeftButtonUp();
  227. Thread.Sleep(20);
  228. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  229. Assert.AreEqual("-", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  230. Thread.Sleep(20);
  231. inputSimulator.Mouse.LeftButtonDown();
  232. Thread.Sleep(20);
  233. inputSimulator.Mouse.LeftButtonUp();
  234. Thread.Sleep(20);
  235. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  236. Assert.AreEqual("1", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  237. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  238. Thread.Sleep(20);
  239. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  240. Assert.AreEqual("-", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  241. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  242. Thread.Sleep(20);
  243. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  244. Assert.AreEqual("1", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LineSimilarityBox")).Text.ToString());
  245. mainWindow.Close();
  246. }
  247. /*
  248. [TestMethod]
  249. [TestCategory("DebugInput")]
  250. public void CreateCanvasTest()
  251. {
  252. Window mainWindow = setupapp();
  253. Thread.Sleep(20);
  254. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  255. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  256. Thread.Sleep(20);
  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(20);
  266. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  267. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  268. Thread.Sleep(20);
  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(20);
  272. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  273. Thread.Sleep(20);
  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(20);
  285. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  286. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  287. Thread.Sleep(20);
  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(20);
  291. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  292. Thread.Sleep(20);
  293. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  294. Thread.Sleep(20);
  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(20);
  299. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  300. Thread.Sleep(20);
  301. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  302. Thread.Sleep(20);
  303. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  304. Thread.Sleep(20);
  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(20);
  316. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  317. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  318. Thread.Sleep(20);
  319. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  320. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  321. Thread.Sleep(20);
  322. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  323. Thread.Sleep(20);
  324. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  325. Thread.Sleep(7000);
  326. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  327. Thread.Sleep(20);
  328. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  329. Thread.Sleep(20);
  330. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  331. mainWindow.Close();
  332. }
  333. [TestMethod]
  334. [TestCategory("DebugInput")]
  335. public void RedoTest()
  336. {
  337. Window mainWindow = setupapp();
  338. Thread.Sleep(20);
  339. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  340. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  341. Thread.Sleep(20);
  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(20);
  345. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  346. Thread.Sleep(20);
  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(20);
  351. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  352. Thread.Sleep(20);
  353. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  354. Thread.Sleep(20);
  355. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  356. Thread.Sleep(20);
  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(20);
  366. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  367. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  368. Thread.Sleep(20);
  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(20);
  372. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  373. Thread.Sleep(20);
  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(20);
  378. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  379. Thread.Sleep(20);
  380. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  381. Thread.Sleep(20);
  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(20);
  386. mainWindow.Close();
  387. }
  388. [TestMethod]
  389. [TestCategory("DebugInput")]
  390. public void DeleteSeveralLinesTest()
  391. {
  392. Window mainWindow = setupapp();
  393. Thread.Sleep(20);
  394. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  395. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  396. Thread.Sleep(20);
  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(20);
  400. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  401. Thread.Sleep(20);
  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(20);
  406. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  407. Thread.Sleep(20);
  408. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  409. Thread.Sleep(20);
  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(20);
  414. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  415. Thread.Sleep(20);
  416. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  417. Thread.Sleep(20);
  418. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  419. Thread.Sleep(20);
  420. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  421. Thread.Sleep(20);
  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(20);
  433. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  434. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  435. Thread.Sleep(20);
  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(20);
  439. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  440. Thread.Sleep(20);
  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(20);
  445. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  446. Thread.Sleep(20);
  447. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  448. Thread.Sleep(20);
  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(20);
  453. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  454. Thread.Sleep(20);
  455. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  456. Thread.Sleep(20);
  457. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  458. Thread.Sleep(20);
  459. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  460. Thread.Sleep(20);
  461. mainWindow.Close();
  462. }
  463. [TestMethod]
  464. [TestCategory("DebugInput")]
  465. public void RedoSeveralLinesTest()
  466. {
  467. Window mainWindow = setupapp();
  468. Thread.Sleep(20);
  469. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  470. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  471. Thread.Sleep(20);
  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(20);
  475. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  476. Thread.Sleep(20);
  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(20);
  481. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  482. Thread.Sleep(20);
  483. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  484. Thread.Sleep(20);
  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(20);
  489. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  490. Thread.Sleep(20);
  491. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  492. Thread.Sleep(20);
  493. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  494. Thread.Sleep(20);
  495. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  496. Thread.Sleep(20);
  497. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  498. Thread.Sleep(20);
  499. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  500. Thread.Sleep(20);
  501. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  502. Thread.Sleep(20);
  503. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  504. Thread.Sleep(20);
  505. mainWindow.Close();
  506. }
  507. [TestMethod]
  508. [TestCategory("DebugInput")]
  509. public void UndoAndRedoTest()
  510. {
  511. Window mainWindow = setupapp();
  512. Thread.Sleep(20);
  513. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  514. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  515. Thread.Sleep(20);
  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(20);
  519. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  520. Thread.Sleep(20);
  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(20);
  525. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  526. Thread.Sleep(20);
  527. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  528. Thread.Sleep(20);
  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(20);
  533. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  534. Thread.Sleep(20);
  535. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  536. Thread.Sleep(20);
  537. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  538. Thread.Sleep(20);
  539. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  540. Thread.Sleep(20);
  541. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  542. Thread.Sleep(20);
  543. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  544. Thread.Sleep(20);
  545. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  546. Thread.Sleep(20);
  547. Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  548. Thread.Sleep(20);
  549. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  550. Thread.Sleep(20);
  551. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  552. Thread.Sleep(20);
  553. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  554. Thread.Sleep(20);
  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(20);
  559. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  560. Thread.Sleep(20);
  561. Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  562. Thread.Sleep(20);
  563. mainWindow.Close();
  564. }
  565. [TestMethod]
  566. [TestCategory("DebugInput")]
  567. public void UndoAndDrawTest()
  568. {
  569. Window mainWindow = setupapp();
  570. Thread.Sleep(20);
  571. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  572. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  573. Thread.Sleep(20);
  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(20);
  577. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  578. Thread.Sleep(20);
  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(20);
  583. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  584. Thread.Sleep(20);
  585. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  586. Thread.Sleep(20);
  587. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  588. Thread.Sleep(20);
  589. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  590. Thread.Sleep(20);
  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(20);
  595. mainWindow.Close();
  596. }
  597. [TestMethod]
  598. [TestCategory("DebugInput")]
  599. public void DeleteSeveralLinesAtOnceTest()
  600. {
  601. Window mainWindow = setupapp();
  602. Thread.Sleep(20);
  603. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  604. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  605. Thread.Sleep(20);
  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(20);
  609. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  610. Thread.Sleep(20);
  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(20);
  615. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  616. Thread.Sleep(20);
  617. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  618. Thread.Sleep(20);
  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(20);
  623. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  624. Thread.Sleep(20);
  625. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  626. Thread.Sleep(20);
  627. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  628. Thread.Sleep(20);
  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(20);
  633. mainWindow.Close();
  634. }
  635. [TestMethod]
  636. [TestCategory("DebugInput")]
  637. public void PointDrawTest()
  638. {
  639. Window mainWindow = setupapp();
  640. Thread.Sleep(20);
  641. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  642. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  643. Thread.Sleep(20);
  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(20);
  647. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  648. Thread.Sleep(20);
  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(20);
  653. mainWindow.Close();
  654. }
  655. [TestMethod]
  656. [TestCategory("DebugInput")]
  657. public void NewCanvasAfterDrawTest()
  658. {
  659. Window mainWindow = setupapp();
  660. Thread.Sleep(20);
  661. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  662. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  663. Thread.Sleep(20);
  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(20);
  667. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  668. Thread.Sleep(20);
  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(20);
  673. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  674. Thread.Sleep(20);
  675. // Click on No button in warning
  676. Window messageBox0 = mainWindow.MessageBox("Warning");
  677. messageBox0.Get<Button>(SearchCriteria.ByText("No")).Click();
  678. Thread.Sleep(20);
  679. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  680. Thread.Sleep(20);
  681. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  682. Thread.Sleep(20);
  683. // close warning
  684. Window messageBox1 = mainWindow.MessageBox("Warning");
  685. messageBox1.Close();
  686. Thread.Sleep(20);
  687. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  688. Thread.Sleep(20);
  689. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  690. Thread.Sleep(20);
  691. // click yes button on warning
  692. Window messageBox2 = mainWindow.MessageBox("Warning");
  693. messageBox2.Get<Button>(SearchCriteria.ByText("Yes")).Click();
  694. Thread.Sleep(20);
  695. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  696. Thread.Sleep(20);
  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. }