UITest.cs 53 KB

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