123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
- using System;
- using System.IO;
- using System.Reflection;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using TestStack.White;
- using TestStack.White.UIItems;
- using TestStack.White.UIItems.WindowItems;
- using TestStack.White.UIItems.Finders;
- using System.Threading;
- using SketchAssistantWPF;
- using System.Windows;
- using System.Diagnostics;
- using TestStack.White.UIItems.WindowStripControls;
- using TestStack.White.UIItems.MenuItems;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- //using WindowsInput;
- //using WindowsInput.Native;
- namespace WhiteTests
- {
- [TestClass]
- public class UITest
- {
- private TestStack.White.Application application;
- /// <summary>
- /// The directory of the input files, saved for repeated use
- /// </summary>
- private String input_file_dir = null;
- /// <summary>
- /// instance of TestContext to be able to access deployed files
- /// </summary>
- private TestContext testContextInstance;
- /// <summary>
- ///Gets or sets the test context which provides
- ///information about and functionality for the current test run.
- ///</summary>
- public TestContext TestContext
- {
- get
- {
- return testContextInstance;
- }
- set
- {
- testContextInstance = value;
- }
- }
- /// <summary>
- /// A function that returns the path to the test_input_files folder.
- /// Do with it what you want.
- /// </summary>
- /// <returns>the path to the test_input_files folder</returns>
- public String getSketchAssistantDirectory()
- {
- Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
- Match match = rx.Match(TestContext.DeploymentDirectory);
- String SketchAssistDir = match.Groups[1].Value;
- if (input_file_dir == null)
- {
- if (Directory.Exists(SketchAssistDir + @"WhiteTests\test_input_files\"))
- {
- input_file_dir = SketchAssistDir + @"WhiteTests\test_input_files\";
- }
- else if (Directory.Exists(SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\"))
- {
- input_file_dir = SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\";
- }
- else
- {
- Regex rx_0 = new Regex(@"^(.*\\projects\\)");
- Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
- String ProjectsDir = match_0.Groups[1].Value;
- var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
- input_file_dir = dirs[0];
- }
- }
- return input_file_dir;
- }
- public Window setupapp()
- {
- string[] files;
- Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
- Match match = rx.Match(TestContext.DeploymentDirectory);
- String SketchAssistDir = match.Groups[1].Value;
- try
- {
- files = Directory.GetFiles(SketchAssistDir + @"SketchAssistantWPF\bin\", "SketchAssistantWPF.exe", SearchOption.AllDirectories);
- }
- catch
- {
- Regex rx_0 = new Regex(@"^(.*\\projects\\)");
- Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
- String ProjectsDir = match_0.Groups[1].Value;
- files = Directory.GetFiles(ProjectsDir, "SketchAssistantWPF.exe", SearchOption.AllDirectories);
- }
- ProcessStartInfo processStart = new ProcessStartInfo(files[0], "-debug");
- application = Application.Launch(processStart);
- return application.GetWindow("Sketch Assistant");
- }
- [TestMethod]
- [TestCategory("bla")]
- public void CreateCanvasTest()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Close();
- }
- [TestMethod]
- [TestCategory("bla")]
- public void DrawLineTest()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Close();
- }
- [TestMethod]
- public void DeleteLineTest()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DrawButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Close();
- }
- [TestMethod]
- [TestCategory("bla")]
- public void UndoTest()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Close();
- }
- [TestMethod]
- [TestCategory("bla")]
- public void RedoTest()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Close();
- }
- [TestMethod]
- public void DrawSeveralLines()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
- Thread.Sleep(30000);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Close();
- }
- [TestMethod]
- public void DeleteSeveralLines()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
- Thread.Sleep(24000);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(10000);
- Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Close();
- }
- [TestMethod]
- public void UndoSeveralLines()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
- Thread.Sleep(30000);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Close();
- }
- [TestMethod]
- public void RedoSeveralLines()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
- Thread.Sleep(24000);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Close();
- }
- [TestMethod]
- public void UndoAndRedoTests()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugTwo")).Click();
- Thread.Sleep(24000);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 1 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
- Thread.Sleep(7000);
- Assert.AreEqual("Last Action: Line number 0 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 1 was deleted.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Close();
- }
- [TestMethod]
- public void PointDraw()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugFour")).Click();
- Thread.Sleep(4000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Close();
- }
- [TestMethod]
- public void NewCanvasAfterDraw()
- {
- Window mainWindow = setupapp();
- Thread.Sleep(20);
- Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
- Thread.Sleep(20);
- mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
- Thread.Sleep(4000);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- // Click on No button in warning
- Window messageBox0 = mainWindow.MessageBox("Warning");
- messageBox0.Get<Button>(SearchCriteria.ByText("No")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- // close warning
- Window messageBox1 = mainWindow.MessageBox("Warning");
- messageBox1.Close();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
- Thread.Sleep(20);
- // click yes button on warning
- Window messageBox2 = mainWindow.MessageBox("Warning");
- messageBox2.Get<Button>(SearchCriteria.ByText("Yes")).Click();
- Thread.Sleep(20);
- Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
- Thread.Sleep(20);
- mainWindow.Close();
- }
- }
- [TestClass]
- [DeploymentItem(@"WhiteTests\test_input_files\")]
- public class FileImporterTests
- {
- /// <summary>
- /// The directory of the input files, saved for repeated use
- /// </summary>
- private String input_file_dir = null;
- /// <summary>
- /// instance of TestContext to be able to access deployed files
- /// </summary>
- private TestContext testContextInstance;
- /// <summary>
- ///Gets or sets the test context which provides
- ///information about and functionality for the current test run.
- ///</summary>
- public TestContext TestContext
- {
- get
- {
- return testContextInstance;
- }
- set
- {
- testContextInstance = value;
- }
- }
- /// <summary>
- /// A function that returns the path to the test_input_files folder.
- /// Do with it what you want.
- /// </summary>
- /// <returns>the path to the test_input_files folder</returns>
- public String getSketchAssistantDirectory()
- {
- Regex rx = new Regex(@"^(.*\\SketchAssistant\\)");
- Match match = rx.Match(TestContext.DeploymentDirectory);
- String SketchAssistDir = match.Groups[1].Value;
- if (input_file_dir == null)
- {
- if (Directory.Exists(SketchAssistDir + @"\WhiteTests\test_input_files\"))
- {
- input_file_dir = SketchAssistDir + @"\WhiteTests\test_input_files\";
- }
- else if (Directory.Exists(SketchAssistDir + @"\WhiteTests\bin\Debug\test_input_files\"))
- {
- input_file_dir = SketchAssistDir + @"\WhiteTests\bin\Debug\test_input_files\";
- }
- else
- {
- Regex rx_0 = new Regex(@"^(.*\\projects\\)");
- Match match_0 = rx_0.Match(TestContext.DeploymentDirectory);
- String ProjectsDir = match_0.Groups[1].Value;
- var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories);
- input_file_dir = dirs[0];
- }
- }
- return input_file_dir;
- }
- /// <summary>
- /// 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
- /// </summary>
- /// <param name="xCoordinates">an array containing the x coordinates of the points that will be created (length divisible by 3)</param>
- /// <param name="yCoordinates">an array containing the y coordinates of the points that will be created (length divisible by 3)</param>
- [DataTestMethod]
- [TestCategory("bla")]
- [DataRow(new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
- [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
- [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 })]
- public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
- {
- FileImporter uut = new FileImporter();
- List<String> file = new List<string>();
- file.Add("drawing");
- file.Add("300x200");
- for (int i = 0; i < xCoordinates.Length - 2; i += 3)
- {
- file.Add("line");
- file.Add(xCoordinates[i] + ";" + yCoordinates[i]);
- file.Add(xCoordinates[i + 1] + ";" + yCoordinates[i + 1]);
- file.Add(xCoordinates[i + 2] + ";" + yCoordinates[i + 2]);
- file.Add("endline");
- }
- file.Add("enddrawing");
- Tuple<int, int, List<InternalLine>> values = uut.ParseISADInputForTesting(file.ToArray());
- Assert.AreEqual(xCoordinates.Length / 3, values.Item3.Count);
- InternalLine[] lines = values.Item3.ToArray();
- for (int i = 0; i < xCoordinates.Length - 2; i += 3)
- {
- Point[] currentLine = lines[i / 3].GetPoints().ToArray();
- Assert.AreEqual(3, currentLine.Length);
- for (int j = 0; j < 3; j++)
- {
- Assert.IsTrue(currentLine[j].X == xCoordinates[i + j] && currentLine[j].Y == yCoordinates[i + j]);
- }
- }
- }
- /// <summary>
- /// parses teh given invalid .isad files and verifies that a FileImporterException is thrown, but no other exception
- /// </summary>
- /// <param name="file">the input file represented as an array of lines</param>
- [DataTestMethod]
- [TestCategory("bla")]
- [DataRow(new String[] { })]
- [DataRow(new String[] { "begindrawing", "300x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300;300", "line", "50;50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "30.5x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "line", "50;50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "beginline", "50;50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "500;50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50x50", "100;50", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50", "100", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "line", "endline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "stopline", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "enddrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline", "endrawing" })]
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline" })]
- public void ParseISADInputExceptionTest(String[] file)
- {
- bool correctExceptionThrown = false;
- FileImporter uut = new FileImporter();
- try
- {
- //try to initialize the left image with an invalid isad drawing
- Tuple<int, int, List<InternalLine>> values1 = uut.ParseISADInputForTesting(file);
- }
- catch (FileImporterException)
- {
- //save the occurence of an exception
- correctExceptionThrown = true;
- }
- catch (Exception e)
- {
- //don't set success flag
- }
- //check that an exception has been thrown
- Assert.IsTrue(correctExceptionThrown);
- }
- /// <summary>
- /// 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)
- /// </summary>
- [TestMethod]
- [TestCategory("FileIO")]
- public void ParseSVGInputNoErrorForWhitelistedFilesTest()
- {
- FileImporter uut = new FileImporter();
- string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories);
- Assert.IsTrue(files.Length > 0);
- foreach (string s in files) //parse each of the whitelisted files
- {
- Console.WriteLine(s);
- bool noExceptionThrown = true;
- try
- {
- uut.ParseSVGInputFile(s, 10000, 10000);
- }
- catch (Exception e)
- {
- noExceptionThrown = false;
- }
- Assert.IsTrue(noExceptionThrown);
- }
- }
- /// <summary>
- /// parses all blacklisted files and ensures an instance of FileIporterException is thrown for each file, but no other exceptions occur
- /// </summary>
- [TestMethod]
- [TestCategory("FileIO")]
- public void ParseSVGInputNoErrorForBlacklistedFilesTest()
- {
- FileImporter uut = new FileImporter();
- string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\blacklisted", "*.svg", SearchOption.AllDirectories);
- Assert.IsTrue(files.Length > 0);
- foreach (string s in files) //parse each of the blacklisted files
- {
- bool correctExceptionThrown = false;
- try
- {
- uut.ParseSVGInputFile(s, 10000, 10000);
- }
- catch (FileImporterException e)
- {
- correctExceptionThrown = true;
- }
- catch (Exception e)
- {
- }
- Assert.IsTrue(correctExceptionThrown);
- }
- }
- }
- }
|