public void Loading_and_saving_a_file_should_work()
        {
            /* Arrange */
            var fileName = "testexisting.xml";
            TestConfigFactory.CreateXmlFile(fileName, "<configuration><section1 /></configuration>", false);
            var p = new FileConfigProvider(fileName);

            /* Act */
            Action a1 = () =>
            {
                //Calling init for code coverage
                p.Initialize();
                var doc = p.LoadConfig().First();
                doc.Root.FirstNode.Remove();
                p.SaveConfig(doc);
            };

            Action a2 = () => p.SaveConfig(null);

            /* Assert */
            a1.ShouldNotThrow();
            a2.ShouldNotThrow();
            p.ModifiedSinceLoad.Should().BeFalse();
        }
        public void Loading_invalid_xml_should_fail()
        {
            /* Arrange */
            var fileName = "testfail.xml";
            TestConfigFactory.CreateXmlFile(fileName, "garblegarble", false);
            var p = new FileConfigProvider(fileName);

            /* Act */
            Action a1 = () => p.LoadConfig().First();

            /* Assert */
            a1.ShouldThrow<XmlException>();
        }
        public void Modified_since_load_should_work_as_expected()
        {
            /* Arrange */
            var fileName = "testmultiedit.xml";
            TestConfigFactory.CreateXmlFile(fileName, "<configuration><section1 /></configuration>", false);
            var p1 = new FileConfigProvider(fileName);
            var p2 = new FileConfigProvider(fileName);

            /* Act */
            var doc1 = p1.LoadConfig().First();
            var doc2 = p2.LoadConfig().First();

            Thread.Sleep(10);
            p1.SaveConfig(doc1);

            /* Assert */
            p1.ModifiedSinceLoad.Should().BeFalse();
            p2.ModifiedSinceLoad.Should().BeTrue();
        }
        public void Loading_and_saving_a_new_file_should_work()
        {
            /* Arrange */
            var fileName = "testnew.xml";
            File.Delete(fileName);
            var p = new FileConfigProvider(fileName);

            /* Act */
            var existsPre = File.Exists(fileName);
            var doc = p.LoadConfig().First();
            p.SaveConfig(doc);
            var existsPost = File.Exists(fileName);

            /* Assert */
            existsPre.Should().BeFalse();
            existsPost.Should().BeTrue();
            doc.Root.Name.LocalName.Should().Be(ConfigElement.RootNode);
        }