Exemple #1
0
        public void test_copy()
        {
            Note       n1 = new Note("Some current note", Guid.NewGuid()), n2 = new Note("Some former note", Guid.NewGuid());
            NoteDomain foo = new NoteDomain(), bar;

            foo.add_note(n1);
            Guid rem_guid = foo.add_note(n2);

            foo.remove_note(rem_guid);

            bar = foo.copy();
            Assert.IsFalse(ReferenceEquals(foo, bar));
            Assert.IsFalse(ReferenceEquals(foo.notes, bar.notes));
            Assert.AreEqual(foo.notes.Count, bar.notes.Count);
            foreach (Guid note in foo.notes.Keys)
            {
                Assert.IsTrue(bar.notes.ContainsKey(note));
                Assert.IsFalse(ReferenceEquals(foo.notes[note], bar.notes[note]));
                Assert.AreEqual(foo.notes[note].contents, bar.notes[note].contents);
            }
            Assert.IsFalse(ReferenceEquals(foo.active_notes, bar.active_notes));
            Assert.AreEqual(foo.active_notes.Count, bar.active_notes.Count);
            foreach (Guid note in foo.active_notes)
            {
                Assert.IsTrue(bar.active_notes.Contains(note));
            }
        }
Exemple #2
0
        public void test_serialization()
        {
            Note       n1 = new Note("Some current note", Guid.NewGuid()), n2 = new Note("Some former note", Guid.NewGuid());
            NoteDomain foo = new NoteDomain(), bar;

            foo.add_note(n1);
            Guid rem_guid = foo.add_note(n2);

            foo.remove_note(rem_guid);

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

            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 = (NoteDomain)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.notes.Count, bar.notes.Count);
            foreach (Guid note in foo.notes.Keys)
            {
                Assert.IsTrue(bar.notes.ContainsKey(note));
                Assert.AreEqual(foo.notes[note].contents, bar.notes[note].contents);
            }
            Assert.AreEqual(foo.active_notes.Count, bar.active_notes.Count);
            foreach (Guid note in foo.active_notes)
            {
                Assert.IsTrue(bar.active_notes.Contains(note));
            }
        }
Exemple #3
0
        public void test_restore_note_active()
        {
            NoteDomain domain    = new NoteDomain();
            Note       note      = new Note("Some note", Guid.NewGuid());
            Guid       note_guid = domain.add_note(note);

            domain.restore_note(note_guid);
        }
Exemple #4
0
        public void test_add_note_duplicate_note()
        {
            NoteDomain domain = new NoteDomain();
            Note       note   = new Note("Some note", Guid.NewGuid());

            domain.add_note(note);
            domain.add_note(note);
        }
Exemple #5
0
        public void test_add_note_duplicate_guid()
        {
            NoteDomain domain = new NoteDomain();
            Note       note1 = new Note("Some note", Guid.NewGuid()), note2 = new Note("Some other note", Guid.NewGuid());

            Guid note_guid = domain.add_note(note1);

            domain.add_note(note2, note_guid);
        }
Exemple #6
0
        public void test_remove_note()
        {
            NoteDomain domain    = new NoteDomain();
            Note       note      = new Note("Some note", Guid.NewGuid());
            Guid       note_guid = domain.add_note(note);

            domain.remove_note(note_guid);
            Assert.AreEqual(domain.notes.Count, 1);
            Assert.IsTrue(domain.notes.ContainsKey(note_guid));
            Assert.AreEqual(domain.notes[note_guid], note);
            Assert.AreEqual(domain.active_notes.Count, 0);
        }
Exemple #7
0
        public void test_restore_note_no_such_guid()
        {
            NoteDomain domain = new NoteDomain();

            domain.restore_note(Guid.NewGuid());
        }
Exemple #8
0
        public void test_add_note_null()
        {
            NoteDomain domain = new NoteDomain();

            domain.add_note(null);
        }