|
@@ -13,14 +13,74 @@ 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 outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
@@ -32,6 +92,7 @@ namespace WhiteTests
|
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
|
+ [TestCategory("bla")]
|
|
|
public void CreateCanvasTest()
|
|
|
{
|
|
|
Window mainWindow = setupapp();
|
|
@@ -44,6 +105,7 @@ namespace WhiteTests
|
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
|
+ [TestCategory("bla")]
|
|
|
public void DrawLineTest()
|
|
|
{
|
|
|
Window mainWindow = setupapp();
|
|
@@ -94,6 +156,7 @@ namespace WhiteTests
|
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
|
+ [TestCategory("bla")]
|
|
|
public void UndoTest()
|
|
|
{
|
|
|
Window mainWindow = setupapp();
|
|
@@ -117,6 +180,7 @@ namespace WhiteTests
|
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
|
+ [TestCategory("bla")]
|
|
|
public void RedoTest()
|
|
|
{
|
|
|
Window mainWindow = setupapp();
|
|
@@ -144,7 +208,7 @@ namespace WhiteTests
|
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
|
- public void DarwSeveralLines()
|
|
|
+ public void DrawSeveralLines()
|
|
|
{
|
|
|
Window mainWindow = setupapp();
|
|
|
Thread.Sleep(20);
|
|
@@ -347,13 +411,80 @@ namespace WhiteTests
|
|
|
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>
|
|
@@ -374,12 +505,45 @@ namespace WhiteTests
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <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 })]
|
|
@@ -420,6 +584,7 @@ namespace WhiteTests
|
|
|
/// </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" })]
|
|
@@ -466,8 +631,7 @@ namespace WhiteTests
|
|
|
public void ParseSVGInputNoErrorForWhitelistedFilesTest()
|
|
|
{
|
|
|
FileImporter uut = new FileImporter();
|
|
|
-
|
|
|
- string[] files = Directory.GetFiles(TestContext.DeploymentDirectory + @"\test_input_files\whitelisted", "*.svg", SearchOption.AllDirectories);
|
|
|
+ string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories);
|
|
|
|
|
|
Assert.IsTrue(files.Length > 0);
|
|
|
|
|
@@ -496,7 +660,7 @@ namespace WhiteTests
|
|
|
{
|
|
|
FileImporter uut = new FileImporter();
|
|
|
|
|
|
- string[] files = Directory.GetFiles(TestContext.DeploymentDirectory + @"\test_input_files\blacklisted", "*.svg", SearchOption.AllDirectories);
|
|
|
+ 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
|
|
|
{
|