コード例 #1
0
        public void test_remove_character_inactive()
        {
            CharacterDomain domain   = new CharacterDomain();
            Character       chr      = new Character("Somebody");
            Guid            chr_guid = domain.add_character(chr);

            domain.remove_character(chr_guid);
            domain.remove_character(chr_guid);
        }
コード例 #2
0
        public void test_copy()
        {
            Character       c1 = new Character("Somebody"), c2 = new Character("Mr. Boddy");
            CharacterDomain foo = new CharacterDomain(), bar;

            foo.add_character(c1);
            Guid mr_boddy = foo.add_character(c2);

            foo.remove_character(mr_boddy);

            bar = foo.copy();
            Assert.IsFalse(ReferenceEquals(foo, bar));
            Assert.IsFalse(ReferenceEquals(foo.characters, bar.characters));
            Assert.AreEqual(foo.characters.Count, bar.characters.Count);
            foreach (Guid chr in foo.characters.Keys)
            {
                Assert.IsTrue(bar.characters.ContainsKey(chr));
                Assert.IsFalse(ReferenceEquals(foo.characters[chr], bar.characters[chr]));
                Assert.AreEqual(foo.characters[chr].name, bar.characters[chr].name);
            }
            Assert.IsFalse(ReferenceEquals(foo.active_characters, bar.active_characters));
            Assert.AreEqual(foo.active_characters.Count, bar.active_characters.Count);
            foreach (Guid chr in foo.active_characters)
            {
                Assert.IsTrue(bar.active_characters.Contains(chr));
            }
        }
コード例 #3
0
        public void test_serialization()
        {
            Character       c1 = new Character("Somebody"), c2 = new Character("Mr. Boddy");
            CharacterDomain foo = new CharacterDomain(), bar;

            foo.add_character(c1);
            Guid mr_boddy = foo.add_character(c2);

            foo.remove_character(mr_boddy);

            DataContractSerializer fmt = new DataContractSerializer(typeof(CharacterDomain));

            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 = (CharacterDomain)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.characters.Count, bar.characters.Count);
            foreach (Guid chr in foo.characters.Keys)
            {
                Assert.IsTrue(bar.characters.ContainsKey(chr));
                Assert.AreEqual(foo.characters[chr].name, bar.characters[chr].name);
            }
            Assert.AreEqual(foo.active_characters.Count, bar.active_characters.Count);
            foreach (Guid chr in foo.active_characters)
            {
                Assert.IsTrue(bar.active_characters.Contains(chr));
            }
        }
コード例 #4
0
        public void test_remove_character()
        {
            CharacterDomain domain   = new CharacterDomain();
            Character       chr      = new Character("Somebody");
            Guid            chr_guid = domain.add_character(chr);

            domain.remove_character(chr_guid);
            Assert.AreEqual(domain.characters.Count, 1);
            Assert.IsTrue(domain.characters.ContainsKey(chr_guid));
            Assert.AreEqual(domain.characters[chr_guid], chr);
            Assert.AreEqual(domain.active_characters.Count, 0);
        }
コード例 #5
0
        public void test_remove_character_no_such_guid()
        {
            CharacterDomain domain = new CharacterDomain();

            domain.remove_character(Guid.NewGuid());
        }