public Update ( string &ObjectXml ) : void | ||
ObjectXml | string | The XML used to update the connection manager XML. |
리턴 | void |
public override void Update(ref string ObjectXml)
{
var xDocument = XDocument.Parse(ObjectXml);
// Check if the Ssl property already exists, if not, we must create it
var ssl = xDocument.Root.Descendants("Ssl").SingleOrDefault();
if (ssl == null)
{
// We expect the SlaveOk property to exist, so we can model the Ssl property after it
var slaveOk = xDocument.Root.Descendants("SlaveOk").SingleOrDefault();
if (slaveOk != null)
{
ssl = XElement.Parse(slaveOk.ToString());
ssl.Name = "Ssl";
ssl.SetAttributeValue("Value", 0); // Default Ssl to false
slaveOk.AddAfterSelf(ssl);
ObjectXml = xDocument.ToString();
}
}
}
public void UpdateTest() { MongoConnectionManager target = new MongoConnectionManager(); string ObjectXml = "<ConnectionManager><ObjectData><InnerObject><SlaveOk Type=\"11\" Value=\"-1\" /></InnerObject></ObjectData></ConnectionManager>"; string ObjectXmlExpected = "<ConnectionManager><ObjectData><InnerObject><SlaveOk Type=\"11\" Value=\"-1\" /><Ssl Type=\"11\" Value=\"0\" /></InnerObject></ObjectData></ConnectionManager>"; target.Update(ref ObjectXml); Assert.AreEqual(XDocument.Parse(ObjectXmlExpected).ToString(), ObjectXml); }