Пример #1
0
        public void LibraryProviderFileSystem_NavigationWorking()
        {
            StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            string meshFileName        = "Box20x20x10.stl";
            string meshPathAndFileName = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "Tests", "TestData", "TestMeshes", "LibraryProviderData", meshFileName);
            int    dataReloadedCount   = 0;

            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 += (s, e) => { dataReloadedCount++; };

            AutomationRunner.StaticDelay(() => { return(dataReloadedCount > 0); }, 1);
            dataReloadedCount = 0;

            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
            Assert.AreEqual(0, dataReloadedCount);             // it has been loaded for the default set of parts

            string collectionName   = "Collection1";
            string createdDirectory = Path.Combine(testLibraryDirectory, collectionName);

            Assert.IsFalse(Directory.Exists(createdDirectory), "CreatedDirectory should *not* exist");
            Assert.AreEqual(0, dataReloadedCount, "Reload should *not* have occurred");

            testProvider.AddCollectionToLibrary(collectionName);
            AutomationRunner.StaticDelay(() => { return(testProvider.CollectionCount == 1); }, 1);

            Assert.AreEqual(1, testProvider.CollectionCount, "Incorrect collection count");
            Assert.IsTrue(dataReloadedCount > 0, "Reload should *have* occurred");
            Assert.IsTrue(Directory.Exists(createdDirectory), "CreatedDirectory *should* exist");

            // add an item works correctly
            LibraryProvider subProvider = testProvider.GetProviderForCollection(testProvider.GetCollectionItem(0));

            subProvider.DataReloaded += (sender, e) => { dataReloadedCount++; };
            dataReloadedCount         = 0;
            string subPathAndFile = Path.Combine(createdDirectory, meshFileName);

            Assert.IsFalse(File.Exists(subPathAndFile), "File should *not* exist: " + subPathAndFile);
            Assert.AreEqual(0, dataReloadedCount, "Reload should *not* have occurred");

            // WIP: saving the name incorrectly for this location (does not need to be changed).
            subProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
            AutomationRunner.StaticDelay(() => { return(subProvider.ItemCount == 1); }, 1);

            PrintItemWrapper itemAtRoot = subProvider.GetPrintItemWrapperAsync(0).Result;

            Assert.IsTrue(subProvider.ItemCount == 1);
            Assert.IsTrue(dataReloadedCount > 0);
            //Assert.IsTrue(itemAdded == true);
            Assert.IsTrue(File.Exists(subPathAndFile));

            // make sure the provider locater is correct

            // remove item works
            dataReloadedCount = 0;
            Assert.IsTrue(dataReloadedCount == 0);
            subProvider.RemoveItem(0);
            AutomationRunner.StaticDelay(() => { return(subProvider.ItemCount == 0); }, 1);
            Assert.IsTrue(dataReloadedCount > 0);
            Assert.IsTrue(!File.Exists(subPathAndFile));

            // remove collection gets rid of it
            dataReloadedCount = 0;
            testProvider.RemoveCollection(0);
            AutomationRunner.StaticDelay(() => { return(testProvider.CollectionCount == 0); }, 1);
            Assert.IsTrue(dataReloadedCount > 0);
            Assert.IsTrue(testProvider.CollectionCount == 0);
            Assert.IsTrue(!Directory.Exists(createdDirectory));

            if (Directory.Exists(testLibraryDirectory))
            {
                Directory.Delete(testLibraryDirectory, true);
            }
        }