コード例 #1
0
        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));
        }
コード例 #2
0
        public static object Deserialize(string xamlString)
        {
            if (xamlString == null)
            {
                throw new ArgumentNullException("xamlString");
            }

            return(XamlTestDriver.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xamlString))));
        }
コード例 #3
0
 public static string Serialize(object obj)
 {
     using (MemoryStream xamlStream = new MemoryStream())
     {
         XamlTestDriver.Serialize(obj, xamlStream);
         xamlStream.Position = 0;
         return(XamlTestDriver.GetStringFromMemoryStream(xamlStream));
     }
 }
コード例 #4
0
        public static object Deserialize(Stream xamlStream)
        {
            if (xamlStream == null)
            {
                throw new ArgumentNullException("xamlStream");
            }

            using (XmlReader reader = XmlReader.Create(xamlStream))
            {
                return(XamlTestDriver.Deserialize(reader));
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
 static void TraceXamlFile(MemoryStream xamlStream)
 {
     XamlTestDriver.TraceXamlFile(XamlTestDriver.GetStringFromMemoryStream(xamlStream));
     xamlStream.Position = 0;
 }
コード例 #8
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)));
 }
コード例 #9
0
 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()));
 }
コード例 #10
0
 public static string RemoveNode(string xaml, string xpath)
 {
     return(XamlTestDriver.RemoveNode(xaml, xpath, null));
 }
コード例 #11
0
 public static string AddNode(string xaml, string xpath, XElement node, IEnumerable <KeyValuePair <string, string> > namespaceMappings)
 {
     return(XamlTestDriver.AddObject(xaml, xpath, node, namespaceMappings));
 }
コード例 #12
0
 public static string AddNode(string xaml, string xpath, XElement node)
 {
     return(XamlTestDriver.AddNode(xaml, xpath, node, null));
 }
コード例 #13
0
 public static string AddAttribute(string xaml, string xpath, XAttribute attr, IEnumerable <KeyValuePair <string, string> > namespaceMappings)
 {
     return(XamlTestDriver.AddObject(xaml, xpath, attr, namespaceMappings));
 }
コード例 #14
0
 public static string AddAttribute(string xaml, string xpath, XAttribute attr)
 {
     return(XamlTestDriver.AddAttribute(xaml, xpath, attr, null));
 }