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