示例#1
0
        public void Test_service_singleton_mapping_should_work()
        {
            /* Arrange */
            var cfg = new ConfigWithBasicProps();

            /* Act */
            cfg.MapSingletonInstance();

            var res1 = ConfigMaster.GetSettings<ConfigWithBasicProps>();

            cfg.UnmapSingletonInstance();

            var res2 = ConfigMaster.GetSettings<ConfigWithBasicProps>();

            /* Assert */
            res1.Should().BeSameAs(cfg);
            res2.Should().BeNull();
        }
示例#2
0
        public void Setting_a_section_multiple_times_should_only_set_the_last_value()
        {
            /* Arrange */
            var doc = TestConfigFactory.CreateConfig();

            var p = A.Fake<IConfigProvider>();
            A.CallTo(() => p.LoadConfig()).Returns(new[] { doc });

            var settingsOne = new ConfigWithBasicProps
            {
                StringValue = "One"
            };

            var settingsTwo = new ConfigWithBasicProps
            {
                StringValue = "Two"
            };

            /* Act */
            var mgr = ConfigManager.Create(p);

            mgr.SetSettings(TestSection.SectionOne, settingsOne);
            mgr.SetSettings(TestSection.SectionOne, settingsOne);
            mgr.SetSettings(TestSection.SectionOne, settingsTwo);

            var readSectionOne = mgr.GetSettings<ConfigWithBasicProps>(TestSection.SectionOne);

            int sectionCount = mgr.Sections.Count();

            /* Assert */
            A.CallTo(() => p.SaveConfig(doc)).MustNotHaveHappened();

            readSectionOne.Should().NotBeNull();
            readSectionOne.ShouldBeEquivalentTo(settingsTwo);

            sectionCount.Should().Be(1);
        }
示例#3
0
        public void Setting_and_getting_complex_settings_should_work()
        {
            /* Arrange */
            var doc = TestConfigFactory.CreateConfig();

            var p = A.Fake<IConfigProvider>();
            A.CallTo(() => p.LoadConfig()).Returns(new[] { doc });

            var settingsOne = new ConfigWithBasicProps
            {
                StringValue = "One"
            };

            var settingsTwo = new ConfigWithBasicProps
            {
                StringValue = "Two"
            };

            var settingsThree = new ConfigComplex
            {
                Name = "Three"
            };

            /* Act */
            var mgr = ConfigManager.Create(p);
            mgr.MonitorEvents();

            mgr.SetSettings(TestSection.SectionOne, settingsOne);
            mgr.SetSettings(settingsTwo);
            mgr.SetSettings(settingsThree);

            var readSectionOne = mgr.GetSettings<ConfigWithBasicProps>(TestSection.SectionOne);
            var readSectionTwo = mgr.GetSettings<ConfigWithBasicProps>();
            var allBasics = mgr.GetSettingsList<ConfigWithBasicProps>();

            mgr.Reload();

            var readSectionOneAfterReload = mgr.GetSettings<ConfigWithBasicProps>(TestSection.SectionOne);
            var readSectionTwoAfterReload = mgr.GetSettings<ConfigWithBasicProps>();

            int sectionCount = mgr.Sections.Count();

            /* Assert */
            A.CallTo(() => p.SaveConfig(doc)).MustNotHaveHappened();

            readSectionOne.Should().NotBeNull();
            readSectionOne.Should().NotBeSameAs(settingsOne);
            readSectionOne.ShouldBeEquivalentTo(settingsOne);

            readSectionTwo.Should().NotBeNull();
            readSectionTwo.Should().NotBeSameAs(settingsTwo);
            readSectionTwo.ShouldBeEquivalentTo(settingsTwo);

            readSectionOneAfterReload.Should().NotBeNull();
            readSectionOneAfterReload.ShouldBeEquivalentTo(settingsOne);

            readSectionTwoAfterReload.Should().NotBeNull();
            readSectionTwoAfterReload.ShouldBeEquivalentTo(settingsTwo);

            allBasics.Count.Should().Be(2);
            sectionCount.Should().Be(3);

            mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "SectionOne" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionChanged && e.SectionType == typeof(ConfigWithBasicProps));
            mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "ConfigWithBasicProps" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionChanged);
            mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "ConfigComplex" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionChanged);
        }
示例#4
0
        public void Section_removal_should_work()
        {
            /* Arrange */
            var doc = TestConfigFactory.CreateConfig();

            var p = A.Fake<IConfigProvider>();
            A.CallTo(() => p.LoadConfig()).Returns(new[] { doc });

            var settingsOne = new ConfigWithBasicProps
            {
                StringValue = "One"
            };

            /* Act */
            var mgr = ConfigManager.Create(p);

            mgr.MonitorEvents();

            mgr.SetSettings(TestSection.SectionOne, settingsOne);
            mgr.SetSettings(TestSection.SectionTwo, settingsOne);

            bool existsPre = mgr.HasSection(TestSection.SectionOne);

            mgr.RemoveSection(TestSection.SectionOne);
            mgr.RemoveSection("NoSuchSection");
            mgr.RemoveSection((Enum)null);
            mgr.RemoveSection(string.Empty);

            bool existsPost = mgr.HasSection(TestSection.SectionOne);

            var readSectionOne = mgr.GetSettings<ConfigWithBasicProps>(TestSection.SectionOne);

            int sectionCount = mgr.Sections.Count();

            /* Assert */
            A.CallTo(() => p.SaveConfig(doc)).MustNotHaveHappened();

            readSectionOne.Should().BeNull();

            existsPre.Should().BeTrue();
            existsPost.Should().BeFalse();
            sectionCount.Should().Be(1);

            mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "SectionOne" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionRemoved);
        }
示例#5
0
        public void Has_section_should_work()
        {
            /* Arrange */
            var doc = TestConfigFactory.CreateConfig();

            var p = A.Fake<IConfigProvider>();
            A.CallTo(() => p.LoadConfig()).Returns(new[] { doc });

            var settingsOne = new ConfigWithBasicProps
            {
                StringValue = "One"
            };

            /* Act */
            var mgr = ConfigManager.Create(p);

            mgr.SetSettings(settingsOne);

            bool exists = mgr.HasSection<ConfigWithBasicProps>();

            /* Assert */
            exists.Should().BeTrue();
        }
示例#6
0
 public ConfigSilly(ConfigWithBasicProps getOnlyProp)
 {
     _getOnlyProp = getOnlyProp;
 }