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:
Lars Brubaker 2015-08-25 11:56:21 -07:00
parent 62a579788b
commit b30bae0abf
10 changed files with 165 additions and 65 deletions

View file

@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
}
}
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider)
{
return new LibraryProviderFileSystem(rootPath, Description, parentLibraryProvider);
}

View file

@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
public class LibraryProviderHistoryCreator : ILibraryCreator
{
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider)
{
return new LibraryProviderHistory(null, parentLibraryProvider);
}

View file

@ -39,14 +39,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
public interface ILibraryCreator
{
LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider);
LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider);
string ProviderKey { get; }
}
public class LibraryProviderPlugin : ILibraryCreator
{
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider)
{
throw new NotImplementedException();
}

View file

@ -48,7 +48,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
public class LibraryProviderQueueCreator : ILibraryCreator
{
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider)
{
return new LibraryProviderQueue(null, parentLibraryProvider);
}

View file

@ -160,7 +160,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
// If signing out, we need to force selection to this provider
if(e != null && !e.IsAuthenticated)
{
// Switch to the purchased library
// Switch to the selector
setCurrentLibraryProvider(this);
}
@ -233,7 +233,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
public override PrintItemCollection GetCollectionItem(int collectionIndex)
{
LibraryProvider provider = libraryCreators[collectionIndex].CreateLibraryProvider(this);
LibraryProvider provider = libraryCreators[collectionIndex].CreateLibraryProvider(this, setCurrentLibraryProvider);
return new PrintItemCollection(provider.Name, provider.ProviderKey);
}
@ -248,7 +248,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
if (collection.Key == libraryCreator.ProviderKey)
{
return libraryCreator.CreateLibraryProvider(this);
return libraryCreator.CreateLibraryProvider(this, setCurrentLibraryProvider);
}
}
@ -271,7 +271,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
public LibraryProvider GetPurchasedLibrary()
{
return PurchasedLibraryCreator.CreateLibraryProvider(this);
return PurchasedLibraryCreator.CreateLibraryProvider(this, setCurrentLibraryProvider);
}
}
}

View file

@ -48,9 +48,9 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
public class LibraryProviderSQLiteCreator : ILibraryCreator
{
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
public virtual LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider, Action<LibraryProvider> setCurrentLibraryProvider)
{
return new LibraryProviderSQLite(null, parentLibraryProvider, "Local Library");
return new LibraryProviderSQLite(null, setCurrentLibraryProvider, parentLibraryProvider, "Local Library");
}
public string ProviderKey
@ -66,26 +66,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
protected PrintItemCollection baseLibraryCollection;
protected List<PrintItemCollection> childCollections = new List<PrintItemCollection>();
private string keywordFilter = string.Empty;
public ClassicSqliteStorageProvider(LibraryProvider parentLibraryProvider)
: base(parentLibraryProvider)
{
}
public override string KeywordFilter
{
get
{
return keywordFilter;
}
set
{
keywordFilter = value;
}
}
public override PrintItemCollection GetCollectionItem(int collectionIndex)
{
return childCollections[collectionIndex];
@ -195,20 +181,23 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
public class LibraryProviderSQLite : ClassicSqliteStorageProvider
{
Action<LibraryProvider> setCurrentLibraryProvider;
public bool PreloadingCalibrationFiles = false;
private static LibraryProviderSQLite instance = null;
private string keywordFilter = string.Empty;
private List<PrintItemWrapper> printItems = new List<PrintItemWrapper>();
public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider, string visibleName)
public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, Action<LibraryProvider> setCurrentLibraryProvider, LibraryProvider parentLibraryProvider, string visibleName)
: base(parentLibraryProvider)
{
this.setCurrentLibraryProvider = setCurrentLibraryProvider;
this.Name = visibleName;
if (baseLibraryCollection == null)
{
baseLibraryCollection = GetRootLibraryCollection2().Result;
baseLibraryCollection = GetRootLibraryCollection().Result;
}
this.baseLibraryCollection = baseLibraryCollection;
@ -221,7 +210,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
if (instance == null)
{
instance = new LibraryProviderSQLite(null, null, "Local Library");
instance = new LibraryProviderSQLite(null, null, null, "Local Library");
}
return instance;
@ -240,6 +229,59 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
LoadLibraryItems();
}
bool ignoreNextKeywordFilter = false;
public override string KeywordFilter
{
get
{
return keywordFilter;
}
set
{
if (ignoreNextKeywordFilter)
{
ignoreNextKeywordFilter = false;
return;
}
PrintItemCollection rootLibraryCollection = GetRootLibraryCollection().Result;
if (value != ""
&& this.baseLibraryCollection.Id != rootLibraryCollection.Id)
{
LibraryProviderSQLite currentProvider = this.ParentLibraryProvider as LibraryProviderSQLite;
while (currentProvider.ParentLibraryProvider != null
&& currentProvider.baseLibraryCollection.Id != rootLibraryCollection.Id)
{
currentProvider = currentProvider.ParentLibraryProvider as LibraryProviderSQLite;
}
if (currentProvider != null)
{
currentProvider.KeywordFilter = value;
currentProvider.ignoreNextKeywordFilter = true;
UiThread.RunOnIdle(() => setCurrentLibraryProvider(currentProvider));
}
}
else // the search only shows for the cloud library root
{
if (keywordFilter != value)
{
keywordFilter = value;
if (keywordFilter != null && keywordFilter != "")
{
}
else
{
OnDataReloaded(null);
}
}
}
}
}
public override void RenameItem(int itemIndexToRename, string newName)
{
printItems[itemIndexToRename].PrintItem.Name = newName;
@ -315,7 +357,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
{
return new LibraryProviderSQLite(collection, this, collection.Name);
return new LibraryProviderSQLite(collection, setCurrentLibraryProvider, this, collection.Name);
}
public override void RemoveCollection(int collectionIndexToRemove)
@ -392,7 +434,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
return result;
}
private async Task<PrintItemCollection> GetRootLibraryCollection2()
private async Task<PrintItemCollection> GetRootLibraryCollection()
{
// Attempt to initialize the library from the Datastore if null
PrintItemCollection rootLibraryCollection = Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Blend for Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatterControl", "MatterControl.csproj", "{0B8D6F56-BD7F-4426-B858-D9292B084656}"
ProjectSection(ProjectDependencies) = postProject
@ -122,6 +122,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Nat", "..\CloudService
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GuiAutomation", "Submodules\agg-sharp\GuiAutomation\GuiAutomation.csproj", "{E9102310-0029-4D8F-B1E9-88FBA6147D45}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudServices.Tests", "..\CloudServicesPlugin\CloudServices.Tests\CloudServices.Tests.csproj", "{66BAFF8D-3079-4912-B100-41140BAF4DDD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1107,6 +1109,30 @@ Global
{E9102310-0029-4D8F-B1E9-88FBA6147D45}.Release64|x64.Build.0 = Release64|x64
{E9102310-0029-4D8F-B1E9-88FBA6147D45}.Release64|x86.ActiveCfg = Release64|Any CPU
{E9102310-0029-4D8F-B1E9-88FBA6147D45}.Release64|x86.Build.0 = Release64|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug|x64.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug|x86.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug64|Any CPU.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug64|Any CPU.Build.0 = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug64|Mixed Platforms.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug64|Mixed Platforms.Build.0 = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug64|x64.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Debug64|x86.ActiveCfg = Debug|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release|Any CPU.Build.0 = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release|x64.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release|x86.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|Any CPU.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|Any CPU.Build.0 = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|Mixed Platforms.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|Mixed Platforms.Build.0 = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|x64.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1143,6 +1169,7 @@ Global
{26164CC3-29AD-4384-861C-181440934B00} = {4E79BE4E-275E-4901-9173-E9096B7318F0}
{F5D74163-145F-47BF-83DC-D0E07249C6CA} = {4E79BE4E-275E-4901-9173-E9096B7318F0}
{E9102310-0029-4D8F-B1E9-88FBA6147D45} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{66BAFF8D-3079-4912-B100-41140BAF4DDD} = {4E79BE4E-275E-4901-9173-E9096B7318F0}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = MatterControl.csproj

View file

@ -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
}
}

View file

@ -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

View file

@ -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);
}
}
}
}