Made providers take a function to change the provider (used in searching)
Improved tests (made functions to help create a clean run)
This commit is contained in:
parent
62a579788b
commit
b30bae0abf
10 changed files with 165 additions and 65 deletions
|
|
@ -78,7 +78,7 @@ namespace MatterHackers.MatterControl.UI
|
|||
testRunner.Wait(.5);
|
||||
resultsHarness.AddTestResult(checkBoxWidget.Checked == false, "currently not checked");
|
||||
|
||||
UITests.CloseMatterControl(testRunner);
|
||||
MatterControlUITests.CloseMatterControl(testRunner);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -91,7 +91,9 @@ namespace MatterHackers.MatterControl.UI
|
|||
MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow);
|
||||
AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, 1000);
|
||||
|
||||
Assert.IsTrue(testHarness.AllTestsPassed);
|
||||
// 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.
|
||||
Assert.IsTrue(testHarness.AllTestsPassed);
|
||||
Assert.IsTrue(testHarness.TestCount == 4); // make sure we ran all our tests
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ using MatterHackers.Agg.PlatformAbstract;
|
|||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.PrintLibrary.Provider;
|
||||
using MatterHackers.MatterControl.PrintQueue;
|
||||
using MatterHackers.MatterControl.UI;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -62,24 +63,9 @@ namespace MatterControl.Tests
|
|||
[Test, RunInApplicationDomain]
|
||||
public void LibraryProviderSqlite_NavigationWorking()
|
||||
{
|
||||
string userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
|
||||
string renamedUserDataPath = Path.Combine(Path.GetDirectoryName(userDataPath), "-MatterControl");
|
||||
int testCount = 0;
|
||||
while (Directory.Exists(renamedUserDataPath + testCount.ToString()))
|
||||
{
|
||||
testCount++;
|
||||
}
|
||||
renamedUserDataPath = renamedUserDataPath + testCount.ToString();
|
||||
MatterControlUITests.DataFolderState staticDataState = MatterControlUITests.MakeNewStaticDataForTesting();
|
||||
|
||||
bool undoDataRename = false;
|
||||
if (Directory.Exists(userDataPath))
|
||||
{
|
||||
Directory.Move(userDataPath, renamedUserDataPath);
|
||||
undoDataRename = true;
|
||||
}
|
||||
|
||||
Datastore.Instance.Initialize();
|
||||
LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null, "Local Library");
|
||||
LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null, null, "Local Library");
|
||||
testProvider.DataReloaded += (sender, e) => { dataReloaded = true; };
|
||||
Thread.Sleep(3000); // wait for the library to finish initializing
|
||||
Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
|
||||
|
|
@ -127,19 +113,7 @@ namespace MatterControl.Tests
|
|||
Assert.IsTrue(testProvider.CollectionCount == 0);
|
||||
Assert.IsTrue(!NamedCollectionExists(collectionName)); // assert that the record does not exist in the DB
|
||||
|
||||
if (undoDataRename)
|
||||
{
|
||||
Datastore.Instance.Exit();
|
||||
Directory.Delete(userDataPath, true);
|
||||
Stopwatch time = Stopwatch.StartNew();
|
||||
// Wait for up to some amount of time for the directory to be gone.
|
||||
while (Directory.Exists(userDataPath)
|
||||
&& time.ElapsedMilliseconds < 100)
|
||||
{
|
||||
Thread.Sleep(1); // make sure we are not eating all the cpu time.
|
||||
}
|
||||
Directory.Move(renamedUserDataPath, userDataPath);
|
||||
}
|
||||
MatterControlUITests.RestoreStaticDataAfterTesting(staticDataState, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -33,15 +33,18 @@ using MatterHackers.Agg.PlatformAbstract;
|
|||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.UI.Tests;
|
||||
using MatterHackers.GuiAutomation;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MatterHackers.MatterControl.UI
|
||||
{
|
||||
[TestFixture, Category("MatterControl.UI")]
|
||||
public class UITests
|
||||
public class MatterControlUITests
|
||||
{
|
||||
private static bool saveImagesForDebug = true;
|
||||
|
||||
|
|
@ -168,5 +171,57 @@ namespace MatterHackers.MatterControl.UI
|
|||
OutputImage(control, "image-control.tga");
|
||||
OutputImage(test, "image-test.tga");
|
||||
}
|
||||
|
||||
public class DataFolderState
|
||||
{
|
||||
internal bool undoDataRename;
|
||||
internal string userDataPath;
|
||||
internal string renamedUserDataPath;
|
||||
}
|
||||
|
||||
public static DataFolderState MakeNewStaticDataForTesting()
|
||||
{
|
||||
DataFolderState state = new DataFolderState();
|
||||
state.userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
|
||||
state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");
|
||||
int testCount = 0;
|
||||
while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
|
||||
{
|
||||
testCount++;
|
||||
}
|
||||
state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();
|
||||
|
||||
state.undoDataRename = false;
|
||||
if (Directory.Exists(state.userDataPath))
|
||||
{
|
||||
Directory.Move(state.userDataPath, state.renamedUserDataPath);
|
||||
state.undoDataRename = true;
|
||||
}
|
||||
|
||||
Datastore.Instance.Initialize();
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
public static void RestoreStaticDataAfterTesting(DataFolderState state, bool closeDataBase)
|
||||
{
|
||||
if (state.undoDataRename)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
if (closeDataBase)
|
||||
{
|
||||
Datastore.Instance.Exit();
|
||||
}
|
||||
Directory.Delete(state.userDataPath, true);
|
||||
Stopwatch time = Stopwatch.StartNew();
|
||||
// Wait for up to some amount of time for the directory to be gone.
|
||||
while (Directory.Exists(state.userDataPath)
|
||||
&& time.ElapsedMilliseconds < 100)
|
||||
{
|
||||
Thread.Sleep(1); // make sure we are not eating all the cpu time.
|
||||
}
|
||||
Directory.Move(state.renamedUserDataPath, state.userDataPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue