예제 #1
0
        public void can_find_first_node_under_a_particular_parent()
        {
            var doc = FluentXmlDocument.FromString(@"
				<stuff>
					<thing>hi</thing>
					<more>
						<notThing>Ah ha! The first more has no thing!</notThing>
						<other>
						  <whatever/>
						</other>
					</more>
					<more>
						<thing>more thing 1</thing>
						<thing>more thing 2</thing>
						<whatever>
							<thing>whatever thing 1</thing>
						</whatever>
					</more>
					<other>
						<whatever>
							<thing>other thing 1</thing>
							<thing>other thing 2</thing>
						</whatever>
					</other>
				</stuff>	
				"                );

            doc.Node("thing").Text().ShouldEqual("hi");
            doc.Node("more thing").Text().ShouldEqual("more thing 1");
            doc.Node("other thing").Text().ShouldEqual("other thing 1");
            doc.Node("whatever thing").Text().ShouldEqual("whatever thing 1");
            doc.Node("other whatever thing").Text().ShouldEqual("other thing 1");
        }
예제 #2
0
        public void can_easily_get_an_XmlDocument_for_a_given_file()
        {
            var doc = FluentXmlDocument.FromFile(Example("ConsoleApp.csproj"));

            doc.GetElementsByTagName("Project").Count.ShouldEqual(1);
            doc.GetElementsByTagName("PropertyGroup").Count.ShouldEqual(7);
        }
예제 #3
0
        public void can_easily_get_an_XmlDocument_for_a_given_string()
        {
            var doc = FluentXmlDocument.FromString("<dogs><dog name='Lander' /><dog name='Murdoch' /></dogs>");

            doc.GetElementsByTagName("dogs").Count.ShouldEqual(1);
            doc.GetElementsByTagName("dog").Count.ShouldEqual(2);
        }
예제 #4
0
        public void can_find_nodes_that_are_under_other_nodes_by_calling_Nodes_with_multiple_tags()
        {
            var doc = FluentXmlDocument.FromString(@"
				<stuff>
					<more>
						<notThing>Ah ha! The first more has no thing!</notThing>
						<other>
						  <whatever/>
						</other>
					</more>
					<thing>hi</thing>
					<more>
						<thing>more thing 1</thing>
						<thing>more thing 2</thing>
					</more>
					<other>
						<whatever>
							<thing>other thing 1</thing>
							<thing>other thing 2</thing>
						</whatever>
					</other>
				</stuff>	
				"                );

            doc.Nodes("thing").Select(x => x.Text()).ToArray().ShouldEqual(new string[] { "hi", "more thing 1", "more thing 2", "other thing 1", "other thing 2" });
            doc.Nodes("stuff more thing").Select(x => x.Text()).ToArray().ShouldEqual(new string[] { "more thing 1", "more thing 2" });
            doc.Nodes("other whatever thing").Select(x => x.Text()).ToArray().ShouldEqual(new string[] { "other thing 1", "other thing 2" });
            doc.Nodes("whatever thing").Select(x => x.Text()).ToArray().ShouldEqual(new string[] { "other thing 1", "other thing 2" });
        }
예제 #5
0
        public void can_find_or_create_a_node_by_tag_name()
        {
            var doc = FluentXmlDocument.FromString("<dogs><dog name='Lander' /></dogs>");

            doc.Node("dog").Node("breed").Should(Be.Null);

            // Node doesn't exist, so it'll use NewNode
            doc.Node("dog").NodeOrNew("breed").Text("hello world");
            doc.ToXml().ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Lander'>
				    <breed>hello world</breed>
				  </dog>
				</dogs>"                .FixXml());

            // Node doesn't exist, so we just return it
            doc.Node("dog").NodeOrNew("breed").Text("changed!");
            doc.ToXml().ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Lander'>
				    <breed>changed!</breed>
				  </dog>
				</dogs>"                .FixXml());
        }
예제 #6
0
        public void can_call_ToXml_to_get_XML_text_for_XmlDocument()
        {
            var doc = FluentXmlDocument.FromString("<dogs><dog name='Lander'>My Text</dog></dogs>");

            doc.ToXml().ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Lander'>My Text</dog>
				</dogs>"                .FixXml());
        }
예제 #7
0
        private static void UpdateWebConfig(DirectoryInfo webRoot, string dbFileName)
        {
            var configFile = Path.Combine(webRoot.FullName, "Web.config");

            Assert.True(File.Exists(configFile), "{0} does not exist!", configFile);

            Console.WriteLine("updating: {0}", configFile);

            FluentXmlDocument
            .FromFile(configFile)
            .RemoveSqliteFileSetting()
            .AddSqliteFileSetting(dbFileName)
            .Save(configFile);
        }
예제 #8
0
        public void can_set_node_text()
        {
            var doc = FluentXmlDocument.FromString("<dogs><dog name='Lander'>My Text</dog></dogs>");

            doc.Node("dog").Text().ShouldEqual("My Text");
            doc.Node("dog").Text("changed!");
            doc.Node("dog").Text().ShouldEqual("changed!");

            doc.ToXml().ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Lander'>changed!</dog>
				</dogs>"                .FixXml());
        }
예제 #9
0
        public void can_save_to_file()
        {
            var doc = FluentXmlDocument.FromString("<dogs><dog name='Lander'>My Text</dog></dogs>");

            File.Exists(Temp("Foo.xml")).Should(Be.False);
            doc.SaveToFile(Temp("Foo.xml"));
            File.Exists(Temp("Foo.xml")).Should(Be.True);

            File.ReadAllText(Temp("Foo.xml")).ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Lander'>My Text</dog>
				</dogs>"                .FixXml());

            // can overwrite ...
            doc.Node("dog").Attr("name", "Different");
            doc.SaveToFile(Temp("Foo.xml"));
            File.ReadAllText(Temp("Foo.xml")).ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Different'>My Text</dog>
				</dogs>"                .FixXml());
        }
예제 #10
0
        public void can_set_attribute_values()
        {
            var doc = FluentXmlDocument.FromString("<dogs><dog name='Lander'>My Text</dog></dogs>");

            // Modify existing attribute
            doc.Node("dog").Attr("name").ShouldEqual("Lander");
            doc.Node("dog").Attr("name", "Different name");
            doc.Node("dog").Attr("name").ShouldEqual("Different name");
            doc.ToXml().ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Different name'>My Text</dog>
				</dogs>"                .FixXml());

            // Add new attribute
            doc.Node("dog").Attr("breed").Should(Be.Null);
            doc.Node("dog").Attr("breed", "Golden Retriever");
            doc.Node("dog").Attr("breed").ShouldEqual("Golden Retriever");
            doc.ToXml().ShouldEqual(@"
				<?xml version='1.0' encoding='utf-8'?>
				<dogs>
				  <dog name='Different name' breed='Golden Retriever'>My Text</dog>
				</dogs>"                .FixXml());
        }
예제 #11
0
 /// <summary>Parse (or re-Parse) this project file (if it exists).</summary>
 /// <remarks>
 /// This re-reads the file and re-parses references, configurations, etc.
 /// </remarks>
 public virtual Project Reload()
 {
     Doc = this.Exists() ? FluentXmlDocument.FromFile(Path) : FluentXmlDocument.FromString(BlankProjectXML);
     return(this);
 }