public void Should_pass_sections_to_section_merger_starting_from_most_important() { NSectionMerger <TestSection> mergerStub = MockRepository.GenerateStub <NSectionMerger <TestSection> >(); // Just concatenate all section Values. Func <IEnumerable <TestSection>, TestSection> mergeFunc = sections => new TestSection() { Value = sections.Aggregate("", (v, s) => v += s.Value) }; mergerStub.Stub(m => m.Merge((IEnumerable <TestSection>)null)).IgnoreArguments().Do(mergeFunc); try { NConfigurator.RegisterSectionMerger(mergerStub); var testSection = NConfigurator.UsingFiles("Configs\\Aliased.config", "Configs\\NConfigTest.config").GetSection <TestSection>(); //Concatenated values should be concatenated in order: from the most important section to lower. Assert.That(testSection.Value, Is.EqualTo("Tests.AliasedAliased")); } finally { NConfigurator.RegisterSectionMerger <TestSection>(new DefaultMerger()); } }
public void Should_call_section_merger_registered_for_section_type() { NSectionMerger <TestSection> mergerStub = MockRepository.GenerateStub <NSectionMerger <TestSection> >(); mergerStub.Stub(m => m.Merge((IEnumerable <TestSection>)null)).IgnoreArguments().Return(null); try { NConfigurator.RegisterSectionMerger <TestSection>(mergerStub); var testSection = NConfigurator.UsingFiles("Configs\\Aliased.config", "Configs\\NConfigTest.config").GetSection <TestSection>(); mergerStub.AssertWasCalled(m => m.Merge((IEnumerable <TestSection>)null), opt => opt.IgnoreArguments()); } finally { NConfigurator.RegisterSectionMerger <TestSection>(new DefaultMerger()); } }