public void test_copy() { CharNumProperty foo = new CharNumProperty(1.3m), bar = foo.copy(); Assert.IsFalse(ReferenceEquals(foo, bar)); Assert.AreEqual(foo.value, bar.value); }
public void test_subtract() { CharNumProperty foo = new CharNumProperty(3.5m), bar = new CharNumProperty(1.3m); foo.subtract(bar); Assert.AreEqual(foo.value, 2.2m); }
public void test_add() { CharNumProperty foo = new CharNumProperty(3.5m), bar = new CharNumProperty(1.3m); foo.add(bar); Assert.AreEqual(foo.value, 4.8m); }
public void test_equals() { CharNumProperty foo = new CharNumProperty(1.3m), bar = foo.copy(), baz = new CharNumProperty(42); Assert.IsTrue(foo.equals(bar)); Assert.IsTrue(bar.equals(foo)); Assert.IsFalse(foo.equals(baz)); Assert.IsFalse(baz.equals(foo)); }
public void test_set_property_non_dict_parent() { Character c = this.get_test_character(); CharNumProperty new_prop = new CharNumProperty(1000); c.set_property(new List <string>() { "XP", "Next Level" }, new_prop); }
public void test_set_property_no_such_parent() { Character c = this.get_test_character(); CharNumProperty new_prop = new CharNumProperty(2); c.set_property(new List <string>() { "Spells per Day", "Level 1" }, new_prop); }
public void test_get_property_nested() { Character c = this.get_test_character(); CharNumProperty prop = c.get_property(new List <string>() { "Skills", "Seal Clubbing" }) as CharNumProperty; Assert.IsFalse(prop is null); Assert.AreEqual(prop.value, 9001); }
public void test_serialization() { CharNumProperty foo = new CharNumProperty(1.3m), bar; DataContractSerializer fmt = new DataContractSerializer(typeof(CharNumProperty)); 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 = (CharNumProperty)(fmt.ReadObject(xr, true)); } Assert.AreEqual(foo.value, bar.value); }
public void test_subtract() { CharDictProperty foo = new CharDictProperty(), bar = new CharDictProperty(); CharTextProperty tprop = new CharTextProperty("blah"); CharNumProperty nprop = new CharNumProperty(1.23m); foo.value["Some Text"] = tprop; foo.value["Some Number"] = nprop; bar.value["Some Number"] = nprop; foo.subtract(bar); Assert.AreEqual(foo.value.Count, 1); Assert.IsTrue(foo.value.ContainsKey("Some Text")); }
public void test_remove_property() { Character c = this.get_test_character(); Assert.IsTrue(c.properties.value.ContainsKey("XP")); CharNumProperty old_prop = c.remove_property(new List <string>() { "XP" }) as CharNumProperty; Assert.IsFalse(old_prop is null); Assert.AreEqual(old_prop.value, 42); Assert.IsFalse(c.properties.value.ContainsKey("XP")); }
public void test_add() { CharDictProperty foo = new CharDictProperty(), bar = new CharDictProperty(); CharTextProperty tprop = new CharTextProperty("blah"); CharNumProperty nprop = new CharNumProperty(1.23m); foo.value["Some Text"] = tprop; bar.value["Some Number"] = nprop; foo.add(bar); Assert.AreEqual(foo.value.Count, 2); Assert.IsTrue(foo.value.ContainsKey("Some Text")); Assert.IsTrue(foo.value.ContainsKey("Some Number")); Assert.IsFalse(ReferenceEquals(foo.value["Some Number"], bar.value["Some Number"])); Assert.AreEqual((foo.value["Some Number"] as CharNumProperty).value, (bar.value["Some Number"] as CharNumProperty).value); }
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)); }
public void test_set_property_new() { Character c = this.get_test_character(); CharNumProperty new_prop = new CharNumProperty(42); CharProperty old_prop = c.set_property(new List <string>() { "Skills", "Fury" }, new_prop); Assert.IsTrue(old_prop is null); CharNumProperty prop = c.get_property(new List <string>() { "Skills", "Fury" }) as CharNumProperty; Assert.IsFalse(prop is null); Assert.AreEqual(prop.value, new_prop.value); }
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")); }
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")); }