public void LibraryProviderFileSystem_NavigationWorking() { Datastore.Instance.Initialize(); Thread.Sleep(3000); // wait for the library to finish initializing LibraryProviderFileSystem testProvider = new LibraryProviderFileSystem(pathToMesh, "TestPath", null); testProvider.DataReloaded += (sender, e) => { dataReloaded = true; }; Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests."); Assert.IsTrue(testProvider.ItemCount == 1, "Start with a new database for these tests."); // create a collection and make sure it is on disk dataReloaded = false; // it has been loaded for the default set of parts string collectionName = "Collection1"; string createdDirectory = Path.Combine(pathToMesh, collectionName); Assert.IsTrue(!Directory.Exists(createdDirectory)); Assert.IsTrue(dataReloaded == false); testProvider.AddCollectionToLibrary(collectionName); Assert.IsTrue(testProvider.CollectionCount == 1); Assert.IsTrue(dataReloaded == true); Assert.IsTrue(Directory.Exists(createdDirectory)); PrintItemWrapper itemAtRoot = testProvider.GetPrintItemWrapperAsync(0).Result; // add an item works correctly LibraryProvider subProvider = testProvider.GetProviderForCollection(testProvider.GetCollectionItem(0)); subProvider.DataReloaded += (sender, e) => { dataReloaded = true; }; dataReloaded = false; //itemAdded = false; string subPathAndFile = Path.Combine(createdDirectory, meshFileName); Assert.IsTrue(!File.Exists(subPathAndFile)); Assert.IsTrue(dataReloaded == false); //Assert.IsTrue(itemAdded == false); // WIP: saving the name incorectly for this location (does not need to be changed). subProvider.AddFilesToLibrary(new string[] { meshPathAndFileName }); Thread.Sleep(3000); // wait for the add to finihs Assert.IsTrue(subProvider.ItemCount == 1); Assert.IsTrue(dataReloaded == true); //Assert.IsTrue(itemAdded == true); Assert.IsTrue(File.Exists(subPathAndFile)); // make sure the provider locator is correct // remove item works dataReloaded = false; Assert.IsTrue(dataReloaded == false); subProvider.RemoveItem(0); Assert.IsTrue(dataReloaded == true); Assert.IsTrue(!File.Exists(subPathAndFile)); // remove collection gets rid of it dataReloaded = false; Assert.IsTrue(dataReloaded == false); testProvider.RemoveCollection(0); Assert.IsTrue(dataReloaded == true); Assert.IsTrue(testProvider.CollectionCount == 0); Assert.IsTrue(!Directory.Exists(createdDirectory)); }
public void LibraryProviderFileSystem_NavigationWorking() { StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", "..", "StaticData")); string downloadsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); string testLibraryDirectory = Path.Combine(downloadsDirectory, "LibraryProviderFileSystemTest"); if (Directory.Exists(testLibraryDirectory)) { Directory.Delete(testLibraryDirectory, true); } Directory.CreateDirectory(testLibraryDirectory); LibraryProviderFileSystem testProvider = new LibraryProviderFileSystem(testLibraryDirectory, "TestPath", null, null); testProvider.DataReloaded += (sender, e) => { dataReloaded = true; }; Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests."); Assert.IsTrue(testProvider.ItemCount == 0, "Start with a new database for these tests."); // create a collection and make sure it is on disk dataReloaded = false; // it has been loaded for the default set of parts string collectionName = "Collection1"; string createdDirectory = Path.Combine(testLibraryDirectory, collectionName); Assert.IsTrue(!Directory.Exists(createdDirectory)); Assert.IsTrue(dataReloaded == false); testProvider.AddCollectionToLibrary(collectionName); Thread.Sleep(500); // wait for the add to finish Assert.IsTrue(testProvider.CollectionCount == 1); Assert.IsTrue(dataReloaded == true); Assert.IsTrue(Directory.Exists(createdDirectory)); // add an item works correctly LibraryProvider subProvider = testProvider.GetProviderForCollection(testProvider.GetCollectionItem(0)); subProvider.DataReloaded += (sender, e) => { dataReloaded = true; }; dataReloaded = false; //itemAdded = false; string subPathAndFile = Path.Combine(createdDirectory, meshFileName); Assert.IsTrue(!File.Exists(subPathAndFile)); Assert.IsTrue(dataReloaded == false); //Assert.IsTrue(itemAdded == false); // WIP: saving the name incorectly for this location (does not need to be changed). subProvider.AddFilesToLibrary(new string[] { meshPathAndFileName }); Thread.Sleep(3000); // wait for the add to finish PrintItemWrapper itemAtRoot = subProvider.GetPrintItemWrapperAsync(0).Result; Assert.IsTrue(subProvider.ItemCount == 1); Assert.IsTrue(dataReloaded == true); //Assert.IsTrue(itemAdded == true); Assert.IsTrue(File.Exists(subPathAndFile)); // make sure the provider locator is correct // remove item works dataReloaded = false; Assert.IsTrue(dataReloaded == false); subProvider.RemoveItem(0); Thread.Sleep(500); // wait for the remove to finish Assert.IsTrue(dataReloaded == true); Assert.IsTrue(!File.Exists(subPathAndFile)); // remove collection gets rid of it dataReloaded = false; Assert.IsTrue(dataReloaded == false); testProvider.RemoveCollection(0); Thread.Sleep(500); // wait for the remove to finish Assert.IsTrue(dataReloaded == true); Assert.IsTrue(testProvider.CollectionCount == 0); Assert.IsTrue(!Directory.Exists(createdDirectory)); if (Directory.Exists(testLibraryDirectory)) { Directory.Delete(testLibraryDirectory, true); } }