public void WriteValues_TestFile_ValuesAreChanged() { XPathComposer composer = new XPathComposer(testFile1); IList<KeyValuePair<string, string>> valueList = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). SelectAllChildNodes(). GetList<string,string>(); Assert.IsTrue(valueList.Count != 0); for (int i=0; i < valueList.Count; i++) { valueList[i] = new KeyValuePair<string, string>(valueList[i].Key, "newvalue"); } composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). WriteValues<string,string>(valueList); valueList = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). SelectAllChildNodes(). GetList<string, string>(); Assert.IsTrue(valueList.Count != 0); foreach (KeyValuePair<string, string> node in valueList) { Assert.AreEqual("newvalue", node.Value); Assert.AreEqual("newvalue", node.Value); Assert.AreEqual("newvalue", node.Value); } }
public void WriteValue_TestFile1_ValueIsChanged() { XPathComposer composer = new XPathComposer(testFile1); composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). WriteValue("title", "newvalue"); string newValue = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). GetValueOf<string>("title"); Assert.AreEqual("newvalue", newValue); }
public void Remove_RemoveParentNodeWithAllChilds_TestFile1_NodeNotFound() { XPathComposer composer = new XPathComposer(testFile1); composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). Remove(); IList<KeyValuePair<string, string>> valueList = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK").GetList<string, string>(); Assert.IsTrue(valueList.Count == 0); }
public void SelectMoreElementSpecifingFileNotInLine_TestFile1_ValuesAreTheSame() { //use the same file for more xml queries XPathComposer composer = new XPathComposer(testFile1); IList<KeyValuePair<string, string>> valueList = composer.RootNode("catalog").Select("cd").Last<string,string>(); Assert.IsTrue(valueList.Count != 0); Assert.AreEqual("Greatest Hits", valueList[0].Value); Assert.AreEqual("Dolly Parton", valueList[1].Value); Assert.AreEqual("9.90", valueList[2].Value); valueList = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). SelectAllChildNodes(). GetList<string, string>(); Assert.IsTrue(valueList.Count != 0); Assert.AreEqual("Hide your heart", valueList[0].Value); Assert.AreEqual("Bonnie Tyler", valueList[1].Value); Assert.AreEqual("10.0", valueList[2].Value); }
public void RemoveChildNode_TestFile1_ValueHasBeenRemoved() { XPathComposer composer = new XPathComposer(testFile1); composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). RemoveNode("price"); IList<KeyValuePair<string, string>> valueList = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). SelectAllChildNodes(). GetList<string, string>(); Assert.IsTrue(valueList.Count == 2); }
public void InsertBefore_TestFile1_ValueHasBeenAdded() { XPathComposer composer = new XPathComposer(testFile1); KeyValuePair<string, string> node = new KeyValuePair<string, string>("label", "finalmuzik"); composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). InsertBefore<string,string>("price", node); IList<KeyValuePair<string, string>> valueList = composer.RootNode("catalog"). Select("cd"). Where("country"). Equals("UK"). SelectAllChildNodes(). GetList<string, string>(); Assert.IsTrue(valueList.Count != 0); Assert.AreEqual("Hide your heart", valueList[0].Value); Assert.AreEqual("Bonnie Tyler", valueList[1].Value); Assert.AreEqual("finalmuzik", valueList[2].Value); Assert.AreEqual("10.0", valueList[3].Value); }
public void HowToUseLibraryExample_CreateCompleteXmlFile_FileAreEqualToStub() { XPathComposer composer = new XPathComposer(); string xmlPath = TestContext.DeploymentDirectory + "\\temp\\" + "test.xml"; IList<KeyValuePair<string, string>> nodeList = new List<KeyValuePair<string, string>>(); //create parent nodes CD cd1 = new CD("LifeForms", "Future Sound Of London", "1995"); CD cd2 = new CD("Insides - LP", "Orbital", "1996"); //create xml file, adding a parent node,an attribute and a list of child nodes composer.CreateXmlFile(xmlPath, "root").AddParentNode("cd").AddAttribute("id", "bestprice").AddNodeList<string, string>(cd1.GetList()); //add attribute to a child node composer.RootNode("root").Select("cd").Where("id").Equals("bestprice").Select("artist").AddAttribute("country", "uk"); //creatre other parent node adding an attribute and a list of child nodes composer.RootNode("root").AddParentNode("cd").AddAttribute("id", "limited ed").AddNodeList<string, string>(cd2.GetList()); //add attribute to a child node composer.RootNode("root").Select("cd").Where("id").Equals("limited ed").Select("artist").AddAttribute("country", "uk"); string fileContent = Regex.Replace(string.Join("", File.ReadAllText(xmlPath)), @"[\n\t] + ", "").Trim(); Assert.AreEqual(stubXmlFile, fileContent); }
public void CreateFile_AddElementList_ElementsHaveBeenAdded() { XPathComposer composer = new XPathComposer(); string xmlPath = TestContext.DeploymentDirectory + "\\temp\\" + "test.xml"; IList<KeyValuePair<string, string>> nodeList = new List<KeyValuePair<string, string>>(); KeyValuePair<string, string> node1 = new KeyValuePair<string, string>("title", "LifeForms"); KeyValuePair<string, string> node2 = new KeyValuePair<string, string>("artist", "Future Sound Of London"); KeyValuePair<string, string> node3 = new KeyValuePair<string, string>("tear", "1995"); nodeList.Add(node1); nodeList.Add(node2); nodeList.Add(node3); composer.CreateXmlFile(xmlPath, "root").AddNodeList<string, string>(nodeList); File.Exists(xmlPath); nodeList = composer.RootNode("root").SelectAllChildNodes().GetList<string, string>(); Assert.IsTrue(nodeList.Count != 0); Assert.AreEqual("LifeForms", nodeList[0].Value); Assert.AreEqual("Future Sound Of London", nodeList[1].Value); Assert.AreEqual("1995", nodeList[2].Value); }
public void CreateFile_AddAttributeToNode_NodeHasBeenFoundByAttribute() { XPathComposer composer = new XPathComposer(); string xmlPath = TestContext.DeploymentDirectory + "\\temp\\" + "test.xml"; IList<KeyValuePair<string, string>> nodeList = new List<KeyValuePair<string, string>>(); KeyValuePair<string, string> node1 = new KeyValuePair<string, string>("title", "LifeForms"); KeyValuePair<string, string> node2 = new KeyValuePair<string, string>("artist", "Future Sound Of London"); KeyValuePair<string, string> node3 = new KeyValuePair<string, string>("year", "1995"); nodeList.Add(node1); nodeList.Add(node2); nodeList.Add(node3); composer.CreateXmlFile(xmlPath, "root").AddNodeList<string, string>(nodeList); composer.FileName(xmlPath).RootNode("root").AddAttribute("id", "bestprice"); File.Exists(xmlPath); string title = composer.RootNode("root").Where("id").Equals("bestprice").GetValueOf<string>("title"); Assert.AreEqual("LifeForms", title); }