public Task TestExistsForEachUIFieldType() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); var testClass = this.GetType(); var thisClassMethods = testClass.GetMethods(BindingFlags.Public | BindingFlags.Instance); // Find and validate all UIField types, skipping abstract classes foreach (var fieldType in PluginFinder.FindTypes <UIField>().Where(fieldType => !fieldType.IsAbstract)) { if (fieldType.Name == "UIField") { continue; } string expectedTestName = $"{fieldType.Name}Test"; Assert.AreEqual( 1, thisClassMethods.Where(m => m.Name == expectedTestName).Count(), "Required test missing: " + expectedTestName); } return(Task.CompletedTask); }
public PluginManager() { if (File.Exists(pluginStateFile)) { try { this.Disabled = JsonConvert.DeserializeObject <HashSet <string> >(File.ReadAllText(pluginStateFile)); } catch { this.Disabled = new HashSet <string>(); } } else { this.Disabled = new HashSet <string>(); } if (File.Exists(knownPluginsFile)) { try { this.KnownPlugins = JsonConvert.DeserializeObject <List <PluginState> >(File.ReadAllText(knownPluginsFile)); } catch { } } var plugins = new List <IApplicationPlugin>(); foreach (var containerType in PluginFinder.FindTypes <IApplicationPlugin>().Where(type => Disabled.Contains(type.FullName) == false)) { try { plugins.Add(Activator.CreateInstance(containerType) as IApplicationPlugin); } catch (Exception ex) { Console.WriteLine("Error constructing plugin: " + ex.Message); } } this.Plugins = plugins; /* * // Uncomment to generate new KnownPlugins.json file * KnownPlugins = plugins.Where(p => p.MetaData != null).Select(p => new PluginState { TypeName = p.GetType().FullName, Name = p.MetaData.Name }).ToList(); * * File.WriteAllText( * Path.Combine("..", "..", "knownPlugins.json"), * JsonConvert.SerializeObject(KnownPlugins, Formatting.Indented)); */ }
public Task TestExistsForEachContainerType() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); // Find all test methods on this test class var thisClassMethods = this.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance); // Find and validate all ILibraryContainer types, skipping abstract classes foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract)) { string expectedTestName = $"{containerType.Name}Test"; Assert.AreEqual( 1, thisClassMethods.Where(m => m.Name == expectedTestName).Count(), "Test for LibraryContainer missing, not yet created or typo'd - Expected: " + expectedTestName); } return(Task.CompletedTask); }
public Task TestExistsForEachUIFieldType() { var testClass = this.GetType(); var thisClassMethods = testClass.GetMethods(BindingFlags.Public | BindingFlags.Instance); // Find and validate all UIField types, skipping abstract classes foreach (var fieldType in PluginFinder.FindTypes <UIField>().Where(fieldType => !fieldType.IsAbstract)) { if (fieldType.Name == "UIField") { continue; } string expectedTestName = $"{fieldType.Name}Test"; Assert.AreEqual( 1, thisClassMethods.Where(m => m.Name == expectedTestName).Count(), "Required test missing: " + expectedTestName); } return(Task.CompletedTask); }
public async Task NoContentChangedOnLoad() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); bool onIdlePumpActive = true; var uiPump = Task.Run(() => { while (onIdlePumpActive) { UiThread.InvokePendingActions(); Thread.Sleep(10); } ; Console.Write("Exiting"); }); // Find and validate all ILibraryContainer types, skipping abstract classes foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract)) { var args = new List <object>(); if (containerType == typeof(FileSystemContainer)) { args.Add(TestContext.CurrentContext.ResolveProjectPath(4)); } else if (containerType == typeof(RootLibraryContainer)) { // TODO: Not sure how to test RootLibrary given content loads after MatterControl init is finished, skipping for now continue; } if (Activator.CreateInstance(containerType, args.ToArray()) is ILibraryContainer libraryContainer) { if (libraryContainer is ZipMemoryContainer zipContainer) { zipContainer.Path = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.zip"); zipContainer.RelativeDirectory = Path.GetDirectoryName(zipContainer.Path); } int changedCount = 0; libraryContainer.ContentChanged += (s, e) => { changedCount++; }; await Task.Run(() => { libraryContainer.Load(); }); // Allow time for invalid additional reloads await Task.Delay(300); // Verify Reload is called; Assert.AreEqual(0, changedCount, "Expected reload count not hit - container should fire reload event after acquiring content"); } } onIdlePumpActive = false; }
public async Task AddFiresContentChangedEvent() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); string filePath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.stl"); bool onIdlePumpActive = true; var uiPump = Task.Run(() => { while (onIdlePumpActive) { UiThread.InvokePendingActions(); Thread.Sleep(10); } ; Console.Write("Exiting"); }); Type writable = typeof(ILibraryWritableContainer); // Find and validate all ILibraryContainer types, skipping abstract classes foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract)) { var args = new List <object>(); if (containerType == typeof(FileSystemContainer)) { Directory.CreateDirectory(ApplicationDataStorage.Instance.ApplicationTempDataPath); args.Add(ApplicationDataStorage.Instance.ApplicationTempDataPath); } else if (containerType == typeof(RootLibraryContainer) || !writable.IsAssignableFrom(containerType)) { // TODO: Not sure how to test RootLibrary given content loads after MatterControl init is finished, skipping for now continue; } if (Activator.CreateInstance(containerType, args.ToArray()) is ILibraryWritableContainer libraryContainer) { if (!libraryContainer.AllowAction(ContainerActions.AddItems)) { continue; } if (libraryContainer is ZipMemoryContainer zipContainer) { zipContainer.Path = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.zip"); zipContainer.RelativeDirectory = Path.GetDirectoryName(zipContainer.Path); } int changedCount = 0; libraryContainer.ContentChanged += (s, e) => { changedCount++; }; var waitUntil = DateTime.Now.AddSeconds(15); var result = Task.Run(() => { libraryContainer.Load(); libraryContainer.Add(new[] { new FileSystemFileItem(filePath) }); }); // Wait for reload while (DateTime.Now <= waitUntil) { if (changedCount > 0) { break; } await Task.Delay(200); } // Allow time for invalid additional reloads await Task.Delay(300); Console.WriteLine($"ContentChanged for {containerType.Name}"); // Verify Reload is called; Assert.AreEqual(1, changedCount, $"Expected reload count for {containerType.Name} not hit - container should fire reload event after acquiring content"); } } onIdlePumpActive = false; }