コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
 static void TraceXamlFile(MemoryStream xamlStream)
 {
     XamlTestDriver.TraceXamlFile(XamlTestDriver.GetStringFromMemoryStream(xamlStream));
     xamlStream.Position = 0;
 }