Beispiel #1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Address != null)
         {
             hashCode = hashCode * 59 + Address.GetHashCode();
         }
         if (Geo != null)
         {
             hashCode = hashCode * 59 + Geo.GetHashCode();
         }
         if (HasMap != null)
         {
             hashCode = hashCode * 59 + HasMap.GetHashCode();
         }
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #2
0
        public void EmptyValue()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("emptyValue");

            Assert.AreEqual("", hasMap.Props.Get("foo"), "Expected empty string");
        }
Beispiel #3
0
        public void EmptyProps()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("emptyProps");

            Assert.IsTrue(hasMap.Props.Count == 0);
        }
Beispiel #4
0
        public void ClassArray()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("classArray");

            Assert.IsTrue(hasMap.ClassArray.Length == 2);
            Assert.IsTrue(hasMap.ClassArray[0].Equals(typeof(String)));
            Assert.IsTrue(hasMap.ClassArray[1].Equals(typeof(Exception)));
        }
Beispiel #5
0
        public void ObjectArray()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("objectArray");

            Assert.IsTrue(hasMap.ObjectArray.Length == 2);
            Assert.IsTrue(hasMap.ObjectArray[0].Equals("one"));
            Assert.IsTrue(hasMap.ObjectArray[1].Equals(xof.GetObject("jenny")));
        }
Beispiel #6
0
        public void PopulatedProps()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("props");

            Assert.AreEqual(2, hasMap.Props.Count);
            Assert.AreEqual("bar", hasMap.Props["foo"]);
            Assert.AreEqual("TWO", hasMap.Props["2"]);
        }
Beispiel #7
0
        public void DelimitedProps()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("delimitedProps");

            Assert.AreEqual(2, hasMap.Props.Count);
            Assert.AreEqual(3, hasMap.Props.GetValues("foo").Length);
            Assert.AreEqual(7, hasMap.Props.GetValues("days").Length);
            Assert.AreEqual("wednesday", hasMap.Props.GetValues("days")[2]);
        }
Beispiel #8
0
        public void MapWithLiteralsOnly()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("literalMap");

            Assert.IsTrue(hasMap.Map.Count == 3);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            Assert.IsTrue(hasMap.Map["fi"].Equals("fum"));
            Assert.IsTrue(hasMap.Map["fa"] == null);
        }
Beispiel #9
0
        public void PopulatedPropsWithSameKey()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("propsWithSameKey");

            Assert.AreEqual(2, hasMap.Props.Count);
            Assert.AreEqual("OnE,tWo", hasMap.Props["foo"]);
            Assert.AreEqual(2, hasMap.Props.GetValues("bar").Length);
            Assert.AreEqual("OnE", hasMap.Props.GetValues("bar")[0]);
            Assert.AreEqual("tWo", hasMap.Props.GetValues("bar")[1]);
        }
Beispiel #10
0
        public void PopulatedSet()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("set");

            Assert.IsTrue(hasMap.Set.Count == 3);
            Assert.IsTrue(hasMap.Set.Contains("bar"));
            TestObject jenny = (TestObject)xof.GetObject("jenny");

            Assert.IsTrue(hasMap.Set.Contains(jenny));
            Assert.IsTrue(hasMap.Set.Contains(null));
        }
Beispiel #11
0
        public void MapWithLiteralsAndReferences()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("mixedMap");

            Assert.IsTrue(hasMap.Map.Count == 3);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            TestObject jenny = (TestObject)xof.GetObject("jenny");

            Assert.IsTrue(hasMap.Map["jenny"] == jenny);
            Assert.IsTrue(hasMap.Map["david"].Equals("david"));
        }
Beispiel #12
0
        public void MapWithLiteralsReferencesAndList()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("mixedMapWithList");

            Assert.IsTrue(hasMap.Map.Count == 4);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            TestObject jenny = (TestObject)xof.GetObject("jenny");

            Assert.IsTrue(hasMap.Map["jenny"].Equals(jenny));

            // Check list
            IList l = (IList)hasMap.Map["list"];

            Assert.IsNotNull(l);
            Assert.IsTrue(l.Count == 4);
            Assert.IsTrue(l[0].Equals("zero"));
            Assert.IsTrue(l[3] == null);

            // Check nested map in list
            IDictionary m = (IDictionary)l[1];

            Assert.IsNotNull(m);
            Assert.IsTrue(m.Count == 2);
            Assert.IsTrue(m["fo"].Equals("bar"));
            Assert.IsTrue(m["jen"].Equals(jenny), "Map element 'jenny' should be equal to jenny object, not " + m["jen"]);

            // Check nested list in list
            l = (IList)l[2];
            Assert.IsNotNull(l);
            Assert.IsTrue(l.Count == 2);
            Assert.IsTrue(l[0].Equals(jenny));
            Assert.IsTrue(l[1].Equals("ba"));

            // Check nested map
            m = (IDictionary)hasMap.Map["map"];
            Assert.IsNotNull(m);
            Assert.IsTrue(m.Count == 2);
            Assert.IsTrue(m["foo"].Equals("bar"));
            Assert.IsTrue(m["jenny"].Equals(jenny),
                          "Map element 'jenny' should be equal to jenny object, not " + m["jenny"]);
        }
        IDepTreeNode IDepTreeNodeFinder.FindNode(string property)
        {
            TKey key = (TKey)(property as object);

            object observable = Data.ContainsKey(key) ?
                                Data[key] : null;

            if (observable is null)
            {
                observable = HasMap.ContainsKey(key) ? HasMap[key] : null;
            }

            if (observable is IDepTreeNodeClassifier atom)
            {
                return(atom.Node);
            }

            throw new Exception($"Not able to find Atom for property {property}");
        }
Beispiel #14
0
        public void MapWithLiteralsAndPrototypeReferences()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);

            TestObject jenny  = (TestObject)xof.GetObject("pJenny");
            HasMap     hasMap = (HasMap)xof.GetObject("pMixedMap");

            Assert.IsTrue(hasMap.Map.Count == 2);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            Assert.IsTrue(hasMap.Map["jenny"].ToString().Equals(jenny.ToString()));
            Assert.IsTrue(hasMap.Map["jenny"] != jenny, "Not same instance");

            HasMap hasMap2 = (HasMap)xof.GetObject("pMixedMap");

            Assert.IsTrue(hasMap2.Map.Count == 2);
            Assert.IsTrue(hasMap2.Map["foo"].Equals("bar"));
            Assert.IsTrue(hasMap2.Map["jenny"].ToString().Equals(jenny.ToString()));
            Assert.IsTrue(hasMap2.Map["jenny"] != hasMap.Map["jenny"], "Not same instance");
        }
Beispiel #15
0
        /// <summary>
        /// Returns true if Place instances are equal
        /// </summary>
        /// <param name="other">Instance of Place to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Place other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Address == other.Address ||
                     Address != null &&
                     Address.Equals(other.Address)
                     ) &&
                 (
                     Geo == other.Geo ||
                     Geo != null &&
                     Geo.Equals(other.Geo)
                 ) &&
                 (
                     HasMap == other.HasMap ||
                     HasMap != null &&
                     HasMap.Equals(other.HasMap)
                 ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ));
        }