Exemplo n.º 1
0
        public void test_merge_to_create_update()
        {
            Guid note_guid = Guid.NewGuid(), topic1_guid = Guid.NewGuid(), topic2_guid = Guid.NewGuid();
            Note note = new Note("Some note", Guid.NewGuid(), new HashSet <Guid>()
            {
                topic1_guid
            });
            ActionNoteCreate   create_action = new ActionNoteCreate(note_guid, note);
            List <EntryAction> actions       = new List <EntryAction>()
            {
                create_action
            };

            Dictionary <Guid, int> adjust_topics = new Dictionary <Guid, int>()
            {
                [topic1_guid] = -1, [topic2_guid] = 1
            };
            ActionNoteUpdate update_action = new ActionNoteUpdate(note_guid, "Some note", "Some updated note", adjust_topics);

            update_action.merge_to(actions);

            Assert.AreEqual(actions.Count, 1);
            ActionNoteCreate merged_action = actions[0] as ActionNoteCreate;

            Assert.IsNotNull(merged_action);
            Assert.AreEqual(merged_action.guid, note_guid);
            Assert.AreEqual(merged_action.note.entry_guid, note.entry_guid);
            Assert.AreEqual(merged_action.note.contents, "Some updated note");
            Assert.IsNotNull(merged_action.note.topics);
            Assert.AreEqual(merged_action.note.topics.Count, 1);
            Assert.IsTrue(merged_action.note.topics.Contains(topic2_guid));
        }
Exemplo n.º 2
0
        public void test_merge_to_update_update()
        {
            Guid note_guid = Guid.NewGuid(), topic1_guid = Guid.NewGuid(), topic2_guid = Guid.NewGuid();
            Dictionary <Guid, int> adjust_topics1 = new Dictionary <Guid, int>()
            {
                [topic1_guid] = 1
            },
                                   adjust_topics2 = new Dictionary <Guid, int>()
            {
                [topic1_guid] = -1, [topic2_guid] = 1
            };
            ActionNoteUpdate   existing_action    = new ActionNoteUpdate(note_guid, "Some note", "Some updated note", adjust_topics1);
            List <EntryAction> actions            = new List <EntryAction>()
            {
                existing_action
            };

            ActionNoteUpdate update_action = new ActionNoteUpdate(note_guid, null, null, adjust_topics2);

            update_action.merge_to(actions);

            Assert.AreEqual(actions.Count, 1);
            ActionNoteUpdate merged_action = actions[0] as ActionNoteUpdate;

            Assert.IsNotNull(merged_action);
            Assert.AreEqual(merged_action.guid, note_guid);
            Assert.AreEqual(merged_action.contents_from, "Some note");
            Assert.AreEqual(merged_action.contents_to, "Some updated note");
            Assert.IsNotNull(merged_action.adjust_topics);
            Assert.AreEqual(merged_action.adjust_topics.Count, 1);
            Assert.IsTrue(merged_action.adjust_topics.ContainsKey(topic2_guid));
            Assert.AreEqual(merged_action.adjust_topics[topic2_guid], 1);
        }
Exemplo n.º 3
0
        public void test_revert_topics_only()
        {
            Entry ent = new Entry(42, DateTime.Now, "Some Entry");
            Guid  topic1 = Guid.NewGuid(), topic2 = Guid.NewGuid(), topic3 = Guid.NewGuid();
            Dictionary <Guid, int> adjust_topics = new Dictionary <Guid, int>()
            {
                [topic2] = -2,
                [topic3] = 1,
            };
            Note note = new Note("Some note", ent.guid, new HashSet <Guid>()
            {
                topic1, topic2
            });
            CampaignState    state     = new CampaignState();
            Guid             note_guid = state.notes.add_note(note);
            ActionNoteUpdate action    = new ActionNoteUpdate(note_guid, null, null, adjust_topics);

            action.apply(state, ent);
            action.revert(state, ent);
            Assert.AreEqual(note.contents, "Some note");
            Assert.AreEqual(note.topics.Count, 2);
            Assert.IsTrue(note.topics.Contains(topic1));
            Assert.IsTrue(note.topics.Contains(topic2));
            Assert.AreEqual(note.topics.contents[topic2], 2);
        }
Exemplo n.º 4
0
        public void test_serialization()
        {
            Dictionary <Guid, int> adjust_topics = new Dictionary <Guid, int>()
            {
                [Guid.NewGuid()] = -2,
                [Guid.NewGuid()] = 1,
            };
            ActionNoteUpdate       foo = new ActionNoteUpdate(Guid.NewGuid(), "Old note", "New Note", adjust_topics), bar;
            DataContractSerializer fmt = new DataContractSerializer(typeof(ActionNoteUpdate));

            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 = (ActionNoteUpdate)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.guid, bar.guid);
            Assert.AreEqual(foo.contents_from, bar.contents_from);
            Assert.AreEqual(foo.contents_to, bar.contents_to);
            Assert.AreEqual(foo.adjust_topics.Count, bar.adjust_topics.Count);
            foreach (Guid topic in foo.adjust_topics.Keys)
            {
                Assert.IsTrue(bar.adjust_topics.ContainsKey(topic));
                Assert.AreEqual(foo.adjust_topics[topic], bar.adjust_topics[topic]);
            }
        }
Exemplo n.º 5
0
        public void test_merge_to_update_remove()
        {
            Guid               note_guid     = Guid.NewGuid();
            ActionNoteUpdate   update_action = new ActionNoteUpdate(note_guid, "Some note", "Some updated note", null);
            List <EntryAction> actions       = new List <EntryAction>()
            {
                update_action
            };

            ActionNoteRemove remove_action = new ActionNoteRemove(note_guid);

            remove_action.merge_to(actions);

            Assert.AreEqual(actions.Count, 1);
            Assert.IsTrue(ReferenceEquals(actions[0], remove_action));
        }
Exemplo n.º 6
0
        public void test_apply_contents_only()
        {
            Entry ent = new Entry(42, DateTime.Now, "Some Entry");
            Guid  topic1 = Guid.NewGuid(), topic2 = Guid.NewGuid();
            Note  note = new Note("Some note", ent.guid, new HashSet <Guid>()
            {
                topic1, topic2
            });
            CampaignState    state     = new CampaignState();
            Guid             note_guid = state.notes.add_note(note);
            ActionNoteUpdate action    = new ActionNoteUpdate(note_guid, "Some note", "New note", null);

            action.apply(state, ent);
            Assert.AreEqual(note.contents, "New note");
            Assert.AreEqual(note.topics.Count, 2);
            Assert.IsTrue(note.topics.Contains(topic1));
            Assert.IsTrue(note.topics.Contains(topic2));
        }
Exemplo n.º 7
0
        public void test_rebase()
        {
            Entry ent = new Entry(42, DateTime.Now, "Some Entry");
            Guid  topic1 = Guid.NewGuid(), topic2 = Guid.NewGuid(), topic3 = Guid.NewGuid();
            Dictionary <Guid, int> adjust_topics = new Dictionary <Guid, int>()
            {
                [topic2] = -1,
                [topic3] = 1,
            };
            Note note = new Note("Some note", ent.guid, new HashSet <Guid>()
            {
                topic1, topic2
            });
            CampaignState    state     = new CampaignState();
            Guid             note_guid = state.notes.add_note(note);
            ActionNoteUpdate action    = new ActionNoteUpdate(note_guid, "Some modified note", "New note", adjust_topics);

            note.topics.Add(topic2);

            action.rebase(state);
            Assert.AreEqual(action.contents_from, "Some note");
            Assert.AreEqual(action.adjust_topics[topic2], -2);
        }