Пример #1
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);
        }
Пример #2
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));
        }