public void Compare2()
        {
            XNodeEqualityComparer c = XNode.EqualityComparer;
            XElement e1             = XElement.Parse("<foo><bar/></foo>");
            XElement e2             = XElement.Parse("<foo><bar/></foo>");

            Assert.IsTrue(c.Equals(e1, e2), "#1");
            Assert.IsTrue(c.Equals(e1.FirstNode, e2.FirstNode), "#2");
        }
Esempio n. 2
0
        public bool Equals(CustomAction other)
        {
            if (other == null)
            {
                return(false);
            }

            XNodeEqualityComparer xnec = new XNodeEqualityComparer();

            return(
                xnec.Equals(this.CommandUIExtension, other.CommandUIExtension) &&
                this.Description == other.Description &&
                this.Enabled == other.Enabled &&
                this.Group == other.Group &&
                this.ImageUrl == other.ImageUrl &&
                this.Location == other.Location &&
                this.Name == other.Name &&
                this.RegistrationId == other.RegistrationId &&
                this.RegistrationType == other.RegistrationType &&
                this.Remove == other.Remove &&
                this.Rights.Equals(other.Rights) &&
                this.ScriptBlock == other.ScriptBlock &&
                this.ScriptSrc == other.ScriptSrc &&
                this.Sequence == other.Sequence &&
                this.Title == other.Title &&
                this.Url == other.Url);
        }
        /// <summary>
        /// Determines whether to lists of XElement are equal.
        /// </summary>
        public static bool IsEqualTo(this IList <XElement> me, IList <XElement> other)
        {
            if (me == null && other == null)
            {
                return(true);
            }
            if (me == null || other == null)
            {
                return(false);
            }
            if (me.Count != other.Count)
            {
                return(false);
            }
            var equalityComparer = new XNodeEqualityComparer();

            for (var i = 0; i < me.Count; i++)
            {
                if (!equalityComparer.Equals(me[i], other[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
        public override bool Matches(object actualParam)
        {
            this.actual = actualParam;
            var actualXml = actualParam as XNode;

            if (actualXml == null)
            {
                var actualXmlNode = actualParam as XmlNode;
                if (actualXmlNode != null)
                {
                    actualXml = XElement.Parse(actualXmlNode.OuterXml);
                }
                else if (actualParam is string)
                {
                    actualXml = XElement.Parse((string)actualParam);
                }
                else if (actualParam == null)
                {
                    return(string.IsNullOrEmpty(_expectedXml));
                }
                else
                {
                    throw new ArgumentException("Don't know how to convert value to XML",
                                                nameof(actualParam));
                }
            }

            var equalityComparer = new XNodeEqualityComparer();

            return(equalityComparer.Equals(XElement.Parse(_expectedXml), actualXml));
        }
Esempio n. 5
0
        /// <summary>
        /// Save type settings if changed.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns>return true if type setting is changed, otherwise return false</returns>
        public async Task <bool> SaveIndexTypeSettings()
        {
            var elem = new XElement("TypeSettings");

            foreach (var s in IndexTypeSettings)
            {
                var e = new XElement(s.IndexType.ToString());
                e.SetAttributeValue("on", s.On);
                elem.Add(e);
            }
            var filename = string.Format("{0}.xml", CountryType.ToString());

            var old = await _serializer.LoadXml(filename, roaming : true);

            if (old != null)
            {
                var xElementEqulality = new XNodeEqualityComparer();
                if (xElementEqulality.Equals(old.Element("TypeSettings"), elem))
                {
                    return(false);
                }
            }

            await _serializer.SaveXml(filename, elem, roaming : true);

            return(true);
        }
        public void Compare1()
        {
            XNodeEqualityComparer c   = XNode.EqualityComparer;
            XDocument             doc = XDocument.Parse("<root><foo/><bar/><foo/></root>");

            Assert.IsTrue(c.Equals(doc.Root.FirstNode, doc.Root.LastNode), "#1");
            Assert.IsFalse(c.Equals(doc.Root.FirstNode, doc.Root.FirstNode.NextNode), "#2");

            doc = XDocument.Parse("<root><foo/><foo a='v'/><foo a='v2' /><foo a='v' b='v' /><foo a='v' b='v' /><foo b='v' a='v' /></root>");
            Assert.IsFalse(c.Equals(doc.Root.FirstNode, doc.Root.LastNode.NextNode), "#3");
            Assert.IsFalse(c.Equals(doc.Root.FirstNode, doc.Root.FirstNode.NextNode.NextNode), "#4");
            Assert.IsFalse(c.Equals(doc.Root.FirstNode, doc.Root.LastNode.PreviousNode), "#5");
            // huh?
            Assert.IsFalse(c.Equals(doc.Root.LastNode.PreviousNode, doc.Root.LastNode), "#6");
            Assert.IsTrue(c.Equals(doc.Root.LastNode.PreviousNode.PreviousNode, doc.Root.LastNode.PreviousNode), "#7");
        }
Esempio n. 7
0
        internal static XDocument FilterFromSubRootNodeDuplicates(string xmlString)
        {
            var document         = XDocument.Parse(xmlString);
            var comparer         = new XNodeEqualityComparer();
            var distinctElements = document.Root?.Elements().Distinct(comparer);

            if (distinctElements == null)
            {
                throw new ArgumentNullException();
            }

            foreach (var element in distinctElements)
            {
                document.Root?.Elements().Where(n => comparer.Equals(n, element)).Skip(1).Remove();
            }

            return(document);
        }
Esempio n. 8
0
        private static void DiffTest()
        {
            var doc1 = XDocument.Load(filename);
            var doc2 = XDocument.Load("test1.xml"); // generated in FixNS()

            var comparer = new XNodeEqualityComparer();

            bool same = comparer.Equals(doc1, doc2);

            Console.WriteLine("Docs equal: " + same);
            if (!same)
            {
                var diff2 = doc1.Document.DescendantNodes().Except(doc2.Document.DescendantNodes(), comparer).ToArray();
                int count = diff2.Count();
            }

            var diff   = doc2.Descendants().Cast <XNode>().Except(doc1.Descendants().Cast <XNode>(), comparer);// new XNodeEqualityComparer());
            int count2 = diff.Count();

            foreach (var item in diff.Cast <XElement>())
            {
                Console.WriteLine(PrintLocalName(item));
            }
        }
 public bool Equals(XDocument x, XDocument y)
 {
     return Comparer.Equals(x, y);
 }