public static void ModifyAndValidateException(TestActivity testActivity, Type exceptionType, string errorString) { string originalXaml = XamlTestDriver.Serialize(testActivity.ProductActivity); string modifiedXaml = testActivity.ModifyXamlDelegate(originalXaml); ExceptionHelpers.CheckForException(exceptionType, errorString, () => Deserialize(modifiedXaml)); }
public static object Deserialize(string xamlString) { if (xamlString == null) { throw new ArgumentNullException("xamlString"); } return(XamlTestDriver.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xamlString)))); }
public static string Serialize(object obj) { using (MemoryStream xamlStream = new MemoryStream()) { XamlTestDriver.Serialize(obj, xamlStream); xamlStream.Position = 0; return(XamlTestDriver.GetStringFromMemoryStream(xamlStream)); } }
public static object Deserialize(Stream xamlStream) { if (xamlStream == null) { throw new ArgumentNullException("xamlStream"); } using (XmlReader reader = XmlReader.Create(xamlStream)) { return(XamlTestDriver.Deserialize(reader)); } }
public static object RoundTripAndExamineXAML(object obj, string[] xPathExpressions, XmlNamespaceManager namespaceManager) { if (obj == null) { throw new ArgumentNullException("obj"); } if (xPathExpressions == null) { throw new ArgumentNullException("xPathExpressions"); } MemoryStream xamlStream; object roundTrippedObject = XamlTestDriver.RoundTrip(obj, out xamlStream); using (xamlStream) { XPathDocument doc = new XPathDocument(xamlStream); XPathNavigator navigator = doc.CreateNavigator(); foreach (string xPathExpression in xPathExpressions) { XPathNodeIterator iterator = null; if (namespaceManager != null) { iterator = navigator.Select(xPathExpression, namespaceManager); } else { iterator = navigator.Select(xPathExpression); } if (iterator == null) { //Log.TraceInternal("XAML file generated during serializing: "); XamlTestDriver.TraceXamlFile(xamlStream); throw new Exception(string.Format("The xpath '{0}' does not map to any node in the above xaml document.", xPathExpression)); } } return(roundTrippedObject); } }
public static object RoundTripAndCompareObjects(object obj, params string[] propertyNamesToBeIgnored) { if (obj == null) { throw new ArgumentNullException("obj"); } MemoryStream xamlStream = null; object roundTrippedObject = XamlTestDriver.RoundTrip(obj, out xamlStream); using (xamlStream) { Dictionary <string, PropertyToIgnore> ignore = new Dictionary <string, PropertyToIgnore>(); foreach (string propertyName in propertyNamesToBeIgnored) { ignore.Add(propertyName, new PropertyToIgnore() { WhatToIgnore = IgnoreProperty.IgnoreValueOnly }); } TreeComparerResult result; if (ignore.Count == 0) { result = TreeComparer.CompareLogical(obj, roundTrippedObject); } else { result = TreeComparer.CompareLogical(obj, roundTrippedObject, ignore); } if (result.Result == CompareResult.Different) { string source = new ObjectDumper().DumpToString(null, obj); string target = new ObjectDumper().DumpToString(null, roundTrippedObject); XamlTestDriver.TraceXamlFile(xamlStream); throw new Exception("Two objects are different."); } return(roundTrippedObject); } }
static void TraceXamlFile(MemoryStream xamlStream) { XamlTestDriver.TraceXamlFile(XamlTestDriver.GetStringFromMemoryStream(xamlStream)); xamlStream.Position = 0; }
private static string AddObject <DataType>(string xaml, string xpath, DataType data, IEnumerable <KeyValuePair <string, string> > namespaceMappings) { return(XamlTestDriver.ExecuteQuery <XContainer>(xaml, xpath, data, namespaceMappings, (container, dataToAdd) => container.Add(dataToAdd))); }
public static string RemoveNode(string xaml, string xpath, IEnumerable <KeyValuePair <string, string> > namespaceMappings) { return(XamlTestDriver.ExecuteQuery <XNode>(xaml, xpath, null, namespaceMappings, (result, notUsed) => result.Remove())); }
public static string RemoveNode(string xaml, string xpath) { return(XamlTestDriver.RemoveNode(xaml, xpath, null)); }
public static string AddNode(string xaml, string xpath, XElement node, IEnumerable <KeyValuePair <string, string> > namespaceMappings) { return(XamlTestDriver.AddObject(xaml, xpath, node, namespaceMappings)); }
public static string AddNode(string xaml, string xpath, XElement node) { return(XamlTestDriver.AddNode(xaml, xpath, node, null)); }
public static string AddAttribute(string xaml, string xpath, XAttribute attr, IEnumerable <KeyValuePair <string, string> > namespaceMappings) { return(XamlTestDriver.AddObject(xaml, xpath, attr, namespaceMappings)); }
public static string AddAttribute(string xaml, string xpath, XAttribute attr) { return(XamlTestDriver.AddAttribute(xaml, xpath, attr, null)); }