Total Seconds is what we really wanted.

Making the tests have more common code for less errors.
This commit is contained in:
Lars Brubaker 2015-09-04 11:28:01 -07:00
parent a82490c70a
commit 1b5c1e6a3e
11 changed files with 87 additions and 116 deletions

View file

@ -83,13 +83,7 @@ namespace MatterHackers.MatterControl.UI
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 1000);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
// NOTE: In the future we may want to make the "Local Library Row Item Collection" not clickable.
// If that is the case fix this test to click on a child of "Local Library Row Item Collection" instead.

View file

@ -72,13 +72,7 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 10);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests

View file

@ -44,16 +44,8 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
string testDBFolder = "MC_Three_Queue_Items";
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting(testDBFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 45);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
@ -86,16 +78,8 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
string testDBFolder = "MC_Three_Queue_Items";
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting(testDBFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 45);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}

View file

@ -68,16 +68,10 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 60);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
@ -111,13 +105,7 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 60);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
@ -154,19 +142,10 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
string testDBFolder = "MC_Three_Queue_Items";
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting(testDBFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 60);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
}
@ -191,16 +170,8 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
string testDBFolder = "MC_Fresh_Installation";
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting(testDBFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 300);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Fresh_Installation");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 1); // make sure we ran all our tests
}
@ -232,16 +203,8 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
string testDBFolder = "MC_Three_Queue_Items";
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting(testDBFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 300);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests
}
@ -271,15 +234,8 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting();
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 300);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun);
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 0); // make sure we ran all our tests
}

View file

@ -44,16 +44,8 @@ namespace MatterHackers.MatterControl.UI
}
};
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData"));
#endif
bool showWindow;
string testDBFolder = "MC_One_Queue_No_Library";
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting(testDBFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 45);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_One_Queue_No_Library");
Assert.IsTrue(testHarness.AllTestsPassed);
Assert.IsTrue(testHarness.TestCount == 8); // make sure we ran all our tests
}

View file

@ -63,7 +63,7 @@ namespace MatterControl.Tests
[Test, RunInApplicationDomain]
public void LibraryProviderSqlite_NavigationWorking()
{
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting();
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting2();
LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null, null, "Local Library");
testProvider.DataReloaded += (sender, e) => { dataReloaded = true; };

View file

@ -28,11 +28,14 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.UI.Tests;
using MatterHackers.GuiAutomation;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintLibrary.Provider;
using NUnit.Framework;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
@ -99,7 +102,7 @@ namespace MatterHackers.MatterControl.UI
internal string renamedUserDataPath;
}
public static DataFolderState MakeNewStaticDataForTesting(string testDBFolderName = null)
public static DataFolderState MakeNewStaticDataForTesting2(string testDBFolderName = null)
{
DataFolderState state = new DataFolderState();
state.userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
@ -120,6 +123,14 @@ namespace MatterHackers.MatterControl.UI
state.undoDataRename = true;
}
Stopwatch time = Stopwatch.StartNew();
// Wait for up to some amount of time for the directory to be moved.
while (!Directory.Exists(state.renamedUserDataPath)
&& time.ElapsedMilliseconds < 1000)
{
Thread.Sleep(1); // make sure we are not eating all the cpu time.
}
if (testDBFolderName != null)
{
string fullPathToDataContents = Path.Combine("..", "..", "..", "TestData", "TestDatabaseStates", testDBFolderName);
@ -160,7 +171,18 @@ namespace MatterHackers.MatterControl.UI
{
Datastore.Instance.Exit();
}
Directory.Delete(state.userDataPath, true);
Stopwatch timeTryingToDelete = Stopwatch.StartNew();
while (Directory.Exists(state.userDataPath)
&& timeTryingToDelete.Elapsed.TotalSeconds < 10)
{
try
{
Directory.Delete(state.userDataPath, true);
}
catch (Exception)
{
}
}
Stopwatch time = Stopwatch.StartNew();
// Wait for up to some amount of time for the directory to be gone.
while (Directory.Exists(state.userDataPath)
@ -168,7 +190,10 @@ namespace MatterHackers.MatterControl.UI
{
Thread.Sleep(1); // make sure we are not eating all the cpu time.
}
Directory.Move(state.renamedUserDataPath, state.userDataPath);
if (!Directory.Exists(state.userDataPath))
{
Directory.Move(state.renamedUserDataPath, state.userDataPath);
}
}
}
@ -188,5 +213,24 @@ namespace MatterHackers.MatterControl.UI
File.Copy(fileName, newFileFullName, true);
}
}
public static AutomationTesterHarness RunTest(Action<AutomationTesterHarness> testToRun, string testDbFolder = null, string staticDataPathOverride = null)
{
if (staticDataPathOverride == null)
{
staticDataPathOverride = Path.Combine("..", "..", "..", "..", "StaticData");
}
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(staticDataPathOverride);
#endif
bool showWindow;
MatterControlUtilities.DataFolderState staticDataState = MatterControlUtilities.MakeNewStaticDataForTesting2(testDbFolder);
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 60);
MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
return testHarness;
}
}
}