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