Esempio n. 1
0
        public void test_constructor_argument()
        {
            CharSetProperty foo = new CharSetProperty(new HashSet <string>()
            {
                "blah", "bloh"
            });

            Assert.AreEqual(foo.value.Count, 2);
            Assert.IsTrue(foo.value.Contains("blah"));
            Assert.IsTrue(foo.value.Contains("bloh"));
        }
Esempio n. 2
0
        public void test_add()
        {
            CharSetProperty foo = new CharSetProperty(), bar = new CharSetProperty();

            foo.value.Add("blah");
            bar.value.Add("bloh");

            foo.add(bar);
            Assert.AreEqual(foo.value.Count, 2);
            Assert.IsTrue(foo.value.Contains("blah"));
            Assert.IsTrue(foo.value.Contains("bloh"));
        }
Esempio n. 3
0
        public void test_equals()
        {
            CharSetProperty foo = new CharSetProperty(), bar, baz = new CharSetProperty();

            foo.value.Add("blah");
            foo.value.Add("bloh");
            bar = foo.copy();
            baz.value.Add("blah");
            baz.value.Add("bleh");
            Assert.IsTrue(foo.equals(bar));
            Assert.IsTrue(bar.equals(foo));
            Assert.IsFalse(foo.equals(baz));
            Assert.IsFalse(baz.equals(foo));
        }
Esempio n. 4
0
        public void test_subtract_extra_refs()
        {
            CharSetProperty foo = new CharSetProperty(), bar = new CharSetProperty();

            foo.value.Add("blah", 2);
            foo.value.Add("bloh");
            foo.value.Add("bleh");
            bar.value.Add("blah");
            bar.value.Add("bloh");

            foo.subtract(bar);
            Assert.AreEqual(foo.value.Count, 2);
            Assert.IsTrue(foo.value.Contains("blah"));
            Assert.IsTrue(foo.value.Contains("bleh"));
        }
Esempio n. 5
0
        public void test_copy()
        {
            CharSetProperty foo = new CharSetProperty(), bar;

            foo.value.Add("blah");
            foo.value.Add("bloh");

            bar = foo.copy();
            Assert.IsFalse(ReferenceEquals(foo, bar));
            Assert.IsFalse(ReferenceEquals(foo.value, bar.value));
            Assert.AreEqual(foo.value.Count, bar.value.Count);
            foreach (string s in foo.value)
            {
                Assert.IsTrue(bar.value.Contains(s));
            }
        }
Esempio n. 6
0
        private Character get_test_character()
        {
            Character c = new Character("Krakrox the Barbarian");

            c.properties.value["Player"] = new CharTextProperty("Philip");
            c.properties.value["XP"]     = new CharNumProperty(42);
            CharSetProperty feats = new CharSetProperty();

            feats.value.Add("Power Attack");
            feats.value.Add("Cleave");
            c.properties.value["Feats"] = feats;
            CharDictProperty skills = new CharDictProperty();

            skills.value["Diplomacy"]     = new CharNumProperty(0);
            skills.value["Seal Clubbing"] = new CharNumProperty(9001);
            c.properties.value["Skills"]  = skills;

            return(c);
        }
Esempio n. 7
0
        public void test_equals()
        {
            CharDictProperty foo = new CharDictProperty(), bar, baz = new CharDictProperty();
            CharTextProperty tprop = new CharTextProperty("blah");
            CharNumProperty  nprop = new CharNumProperty(1.23m);
            CharSetProperty  sprop = new CharSetProperty();

            sprop.value.Add("bloh");
            sprop.value.Add("bleh");
            foo.value["Some Text"]       = tprop;
            foo.value["Some Number"]     = nprop;
            foo.value["Some Collection"] = sprop;
            bar = foo.copy();
            baz.value["Some Text"] = tprop;
            Assert.IsTrue(foo.equals(bar));
            Assert.IsTrue(bar.equals(foo));
            Assert.IsFalse(foo.equals(baz));
            Assert.IsFalse(baz.equals(foo));
        }
Esempio n. 8
0
        public void test_serialization()
        {
            CharSetProperty foo = new CharSetProperty(), bar;

            foo.value.Add("blah");
            foo.value.Add("bloh");
            DataContractSerializer fmt = new DataContractSerializer(typeof(CharSetProperty));

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                fmt.WriteObject(ms, foo);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                System.Xml.XmlDictionaryReader xr = System.Xml.XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas());
                bar = (CharSetProperty)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.value.Count, bar.value.Count);
            foreach (string s in foo.value)
            {
                Assert.IsTrue(bar.value.Contains(s));
            }
        }
Esempio n. 9
0
        public void test_serialization()
        {
            Character        foo = new Character("Somebody"), bar;
            CharTextProperty tprop = new CharTextProperty("blah");
            CharNumProperty  nprop = new CharNumProperty(1.23m);
            CharSetProperty  sprop = new CharSetProperty();

            sprop.value.Add("bloh");
            sprop.value.Add("bleh");
            foo.properties.value["Some Text"]       = tprop;
            foo.properties.value["Some Number"]     = nprop;
            foo.properties.value["Some Collection"] = sprop;
            DataContractSerializer fmt = new DataContractSerializer(typeof(Character));

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                fmt.WriteObject(ms, foo);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                System.Xml.XmlDictionaryReader xr = System.Xml.XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas());
                bar = (Character)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.name, bar.name);
            Assert.AreEqual(foo.properties.value.Count, bar.properties.value.Count);
            foreach (string s in foo.properties.value.Keys)
            {
                Assert.IsTrue(bar.properties.value.ContainsKey(s));
            }
            CharTextProperty tp = bar.properties.value["Some Text"] as CharTextProperty;

            Assert.IsFalse(tp is null);
            Assert.AreEqual(tp.value, "blah");
            CharNumProperty np = bar.properties.value["Some Number"] as CharNumProperty;

            Assert.IsFalse(np is null);
            Assert.AreEqual(np.value, 1.23m);
            CharSetProperty sp = bar.properties.value["Some Collection"] as CharSetProperty;

            Assert.IsFalse(sp is null);
            Assert.AreEqual(sp.value.Count, 2);
            Assert.IsTrue(sp.value.Contains("bloh"));
            Assert.IsTrue(sp.value.Contains("bleh"));
        }
Esempio n. 10
0
        public void test_copy()
        {
            Character        foo = new Character("Somebody"), bar;
            CharTextProperty tprop = new CharTextProperty("blah");
            CharNumProperty  nprop = new CharNumProperty(1.23m);
            CharSetProperty  sprop = new CharSetProperty();

            sprop.value.Add("bloh");
            sprop.value.Add("bleh");
            foo.properties.value["Some Text"]       = tprop;
            foo.properties.value["Some Number"]     = nprop;
            foo.properties.value["Some Collection"] = sprop;

            bar = foo.copy();
            Assert.IsFalse(ReferenceEquals(foo, bar));
            Assert.IsFalse(ReferenceEquals(foo.properties, bar.properties));
            Assert.AreEqual(foo.name, bar.name);
            Assert.AreEqual(foo.properties.value.Count, bar.properties.value.Count);
            foreach (string s in foo.properties.value.Keys)
            {
                Assert.IsTrue(bar.properties.value.ContainsKey(s));
                Assert.IsFalse(ReferenceEquals(foo.properties.value[s], bar.properties.value[s]));
            }
            CharTextProperty tp = bar.properties.value["Some Text"] as CharTextProperty;

            Assert.IsFalse(tp is null);
            Assert.AreEqual(tp.value, "blah");
            CharNumProperty np = bar.properties.value["Some Number"] as CharNumProperty;

            Assert.IsFalse(np is null);
            Assert.AreEqual(np.value, 1.23m);
            CharSetProperty sp = bar.properties.value["Some Collection"] as CharSetProperty;

            Assert.IsFalse(sp is null);
            Assert.AreEqual(sp.value.Count, 2);
            Assert.IsTrue(sp.value.Contains("bloh"));
            Assert.IsTrue(sp.value.Contains("bleh"));
        }