public void AddSections() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var spec = customization.GetSpecification(); Assert.False(spec.sections.Any()); //By default empty spec var eventanme = "SpecChanged"; var controller = new Mock <IEventController>(); customization.SpecificationUpdated += (o, e) => controller.Object.RaiseEvent(eventanme); var sections = new[] { "A", "B", "C" }.Select(s => new LayoutSection(s)); Assert.True(customization.AddSections(sections)); spec = customization.GetSpecification(); Assert.AreEqual(3, spec.sections.Count); Assert.AreEqual("A, B, C", string.Join(", ", spec.sections.Select(s => s.text))); //Adding same set of sections returns false Assert.False(customization.AddSections(sections.Take(1))); Assert.False(customization.AddSections(sections)); spec = customization.GetSpecification(); Assert.AreEqual(3, spec.sections.Count); Assert.AreEqual("A, B, C", string.Join(", ", spec.sections.Select(s => s.text))); controller.Verify(c => c.RaiseEvent(eventanme), Times.Once); //Only notified once }
public void CreatingNodeCustomNodeDefinitionOrUpdatingItShouldRaiseUpdate() { var customNodeManager = this.Model.CustomNodeManager; var nodeSearchModel = this.Model.SearchModel; var customization = new LibraryViewCustomization(); var commandExec = new ViewExtensionCommandExecutive(this.ViewModel); var testCallback = new Mock <IJavascriptCallback>(); const string libraryDataUpdated = "libraryDataUpdated"; var resetevent = new AutoResetEvent(false); var refreshCount = 0; var timeout = 50; testCallback.Setup(c => c.CanExecute).Returns(true); testCallback.Setup(c => c.ExecuteAsync()).Callback(() => { refreshCount = refreshCount + 1; resetevent.Set(); }); var controller = new LibraryViewController(this.View, commandExec, customization); controller.On(libraryDataUpdated, testCallback.Object); Assert.AreEqual(0, refreshCount); var path = System.IO.Path.Combine(TempFolder, "customNodeLibraryTest.dyf"); var cnId = Guid.NewGuid(); // lets make a real customnode, this will register the custom node and we should assert a refresh was raised so we can see it. this.Model.ExecuteCommand(new DynamoModel.CreateCustomNodeCommand(cnId, "customNodeLibraryTest", "tests", "", false)); Assert.IsTrue(resetevent.WaitOne(timeout * 100)); Assert.AreEqual(1, refreshCount); resetevent.Reset(); //save will raise an event. this.Model.Workspaces.OfType <CustomNodeWorkspaceModel>().FirstOrDefault().Save(path); Assert.IsTrue(resetevent.WaitOne(timeout * 100)); Assert.AreEqual(2, refreshCount); resetevent.Reset(); // get the searchElement for this custom node and update it. var realNodeData = nodeSearchModel.SearchEntries.OfType <CustomNodeSearchElement>().Where(x => x.ID == cnId).FirstOrDefault(); // updating should raise an event. nodeSearchModel.Update(realNodeData); Assert.IsTrue(resetevent.WaitOne(timeout * 100)); Assert.AreEqual(3, refreshCount); //cleanup the saved custom node System.IO.File.Delete(path); }
public void AddElementsToNewSection() { var customization = new LibraryViewCustomization(); var eventanme = "SpecChanged"; var controller = new Mock <IEventController>(); customization.SpecificationUpdated += (o, e) => controller.Object.RaiseEvent(eventanme); VerifyAddElements(customization, "XYZ"); controller.Verify(c => c.RaiseEvent(eventanme), Times.Once); //Only notified once }
public void LibraryDataUpdatedEventRaised() { const string libraryDataUpdated = "libraryDataUpdated"; var timeout = 50; //50 milliseconds var resetevent = new AutoResetEvent(false); var model = new NodeSearchModel(); var controller = new Mock <IEventController>(); controller.Setup(c => c.RaiseEvent(It.IsAny <string>(), It.IsAny <object[]>())).Callback(() => resetevent.Set()); var customization = new LibraryViewCustomization(); var disposable = LibraryViewController.SetupSearchModelEventsObserver(model, controller.Object, customization, timeout); controller.Verify(c => c.RaiseEvent(libraryDataUpdated, It.IsAny <object[]>()), Times.Never); var d1 = MockNodeSearchElement("A", "B"); var d2 = MockNodeSearchElement("C", "D"); var d3 = MockNodeSearchElement("E", "F"); model.Add(d1.Object); model.Add(d2.Object); model.Add(d3.Object); Assert.AreEqual(3, model.NumElements); Assert.IsTrue(resetevent.WaitOne(timeout * 200)); resetevent.Dispose(); controller.Verify(c => c.RaiseEvent(libraryDataUpdated), Times.Once); var spec = customization.GetSpecification(); var section = spec.sections.FirstOrDefault(); Assert.AreEqual(1, spec.sections.Count); //There must be a section named "Add-ons" now. Assert.AreEqual("Add-ons", section.text); Assert.AreEqual(3, section.include.Count); Assert.AreEqual("A, C, E", string.Join(", ", section.include.Select(i => i.path))); //Dispose disposable.Dispose(); d1 = MockNodeSearchElement("G", "B"); d2 = MockNodeSearchElement("H", "D"); d3 = MockNodeSearchElement("I", "F"); model.Add(d1.Object); model.Add(d2.Object); model.Add(d3.Object); Assert.AreEqual(6, model.NumElements); controller.Verify(c => c.RaiseEvent(libraryDataUpdated, It.IsAny <object[]>()), Times.Once); }
public void ToJSONStream() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var sections = new[] { "A", "B", "C" }.Select(s => new LayoutSection(s)); customization.AddSections(sections); using (var stream = customization.ToJSONStream()) { var spec = LayoutSpecification.FromJSONStream(stream); Assert.AreEqual(3, spec.sections.Count); Assert.AreEqual("A, B, C", string.Join(", ", spec.sections.Select(s => s.text))); } }
public void GetSpecification() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var sections = new[] { "A", "B", "C" }.Select(s => new LayoutSection(s)); customization.AddSections(sections); var spec1 = customization.GetSpecification(); Assert.AreEqual(3, spec1.sections.Count); var spec2 = customization.GetSpecification(); Assert.AreEqual(3, spec2.sections.Count); Assert.AreNotSame(spec1, spec2); Assert.AreEqual("A, B, C", string.Join(", ", spec1.sections.Select(s => s.text))); Assert.AreEqual("A, B, C", string.Join(", ", spec2.sections.Select(s => s.text))); }
public void AddSameIncludeInfoToDifferentSection() { ILibraryViewCustomization customization = new LibraryViewCustomization(); customization.AddSections(new[] { "X", "Y", "Z" }.Select(s => new LayoutSection(s))); var spec = customization.GetSpecification(); Assert.AreEqual(3, spec.sections.Count); var eventanme = "SpecChanged"; var controller = new Mock <IEventController>(); customization.SpecificationUpdated += (o, e) => controller.Object.RaiseEvent(eventanme); VerifyAddIncludeInfo(customization, "Y", 3); VerifyAddIncludeInfo(customization, "Z", 3); controller.Verify(c => c.RaiseEvent(eventanme), Times.Exactly(2)); //Only notified twice since we register the event handler }
public void AddIncludeInfoToExistingSection() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var sectiontext = "X"; customization.AddSections(new[] { "X", "Y", "Z" }.Select(s => new LayoutSection(s))); var spec = customization.GetSpecification(); Assert.AreEqual(3, spec.sections.Count); var eventanme = "SpecChanged"; var controller = new Mock <IEventController>(); customization.SpecificationUpdated += (o, e) => controller.Object.RaiseEvent(eventanme); VerifyAddIncludeInfo(customization, sectiontext, 3); controller.Verify(c => c.RaiseEvent(eventanme), Times.Once); //Only notified once }
public void AddElementsToDefaultSection() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var eventanme = "SpecChanged"; var controller = new Mock <IEventController>(); customization.SpecificationUpdated += (o, e) => controller.Object.RaiseEvent(eventanme); var elements = new[] { "A", "B", "C" }.Select(s => new LayoutElement(s) { elementType = LayoutElementType.category }); Assert.True(customization.AddElements(elements)); var spec = customization.GetSpecification(); var section = spec.sections.FirstOrDefault(); Assert.AreEqual(1, spec.sections.Count); Assert.AreEqual(LibraryViewCustomization.DefaultSectionName, section.text); Assert.AreEqual("A, B, C", string.Join(", ", section.childElements.Select(s => s.text))); //Adding same set of elements to the given section should throw exception Assert.Throws <InvalidOperationException>(() => customization.AddElements(elements.Take(1))); Assert.Throws <InvalidOperationException>(() => customization.AddElements(elements)); spec = customization.GetSpecification(); section = spec.sections.FirstOrDefault(); Assert.AreEqual(1, spec.sections.Count); Assert.AreEqual(LibraryViewCustomization.DefaultSectionName, section.text); Assert.AreEqual("A, B, C", string.Join(", ", section.childElements.Select(s => s.text))); controller.Verify(c => c.RaiseEvent(eventanme), Times.Once); //Only notified once }
public void InstantiatingLazyLoadedCustomNodeShouldNotRaiseUpdate() { var customNodeManager = this.Model.CustomNodeManager; var nodeSearchModel = this.Model.SearchModel; var customization = new LibraryViewCustomization(); var commandExec = new ViewExtensionCommandExecutive(this.ViewModel); var testCallback = new Mock <IJavascriptCallback>(); const string libraryDataUpdated = "libraryDataUpdated"; var refreshCount = 0; var infoUpdated = false; testCallback.Setup(c => c.CanExecute).Returns(true); testCallback.Setup(c => c.ExecuteAsync()).Callback(() => { refreshCount = refreshCount + 1; }); var controller = new LibraryViewController(this.View, commandExec, customization); controller.On(libraryDataUpdated, testCallback.Object); //lets grab a real customNode which was loaded from the package directory specified above var customNodeSearchEntry = nodeSearchModel.SearchEntries.OfType <CustomNodeSearchElement>().FirstOrDefault(); var cnId = customNodeSearchEntry.ID; //lets attempt to create this, we should not raise an update, but we should see info get updated in the search. customNodeManager.InfoUpdated += (data) => { Assert.AreEqual(data.FunctionId, cnId); infoUpdated = true; }; controller.CreateNode(cnId.ToString()); DispatcherUtil.DoEvents(); Assert.AreEqual(0, refreshCount); Assert.IsTrue(infoUpdated); }
public void AddIncludeInfoToDefaultSection() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var eventanme = "SpecChanged"; var controller = new Mock <IEventController>(); customization.SpecificationUpdated += (o, e) => controller.Object.RaiseEvent(eventanme); var includes = new[] { "A", "B", "C", "D" }.Select(s => new LayoutIncludeInfo() { path = s }); Assert.True(customization.AddIncludeInfo(includes)); var spec = customization.GetSpecification(); var section = spec.sections.FirstOrDefault(); Assert.AreEqual(1, spec.sections.Count); Assert.AreEqual(LibraryViewCustomization.DefaultSectionName, section.text); Assert.AreEqual("A, B, C, D", string.Join(", ", section.include.Select(s => s.path))); //Adding same set of includes should throw exception Assert.Throws <InvalidOperationException>(() => customization.AddIncludeInfo(includes.Take(1))); Assert.Throws <InvalidOperationException>(() => customization.AddIncludeInfo(includes)); spec = customization.GetSpecification(); section = spec.sections.FirstOrDefault(); Assert.AreEqual(1, spec.sections.Count); Assert.AreEqual(LibraryViewCustomization.DefaultSectionName, section.text); Assert.AreEqual("A, B, C, D", string.Join(", ", section.include.Select(s => s.path))); controller.Verify(c => c.RaiseEvent(eventanme), Times.Once); //Only notified once }
/// <summary> /// Additional constructor used to access customization resources and dll resource provider directly during icon lookup. /// </summary> /// <param name="pathManager"></param> /// <param name="dllResourceProvider"></param> /// <param name="customization"></param> /// <param name="defaultIcon"></param> public IconResourceProvider(IPathManager pathManager, DllResourceProvider dllResourceProvider, LibraryViewCustomization customization, string defaultIcon = "default-icon.svg") : this(pathManager, defaultIcon) { this.customization = customization; this.embeddedDllResourceProvider = dllResourceProvider; }