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)); }
public void test_revert() { Entry ent = new Entry(42, DateTime.Now, "Some Entry"); Note note = new Note("Some note", ent.guid); Guid note_guid = Guid.NewGuid(); ActionNoteCreate action = new ActionNoteCreate(note_guid, note); CampaignState state = new CampaignState(); action.apply(state, ent); action.revert(state, ent); Assert.AreEqual(state.notes.notes.Count, 0); Assert.AreEqual(state.notes.active_notes.Count, 0); }
public void test_serialization() { Note note = new Note("Some note", Guid.NewGuid()); ActionNoteCreate foo = new ActionNoteCreate(Guid.NewGuid(), note), bar; DataContractSerializer fmt = new DataContractSerializer(typeof(ActionNoteCreate)); 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 = (ActionNoteCreate)(fmt.ReadObject(xr, true)); } Assert.AreEqual(foo.guid, bar.guid); Assert.AreEqual(foo.note.contents, bar.note.contents); }
public void test_apply() { Entry ent = new Entry(42, DateTime.Now, "Some Entry"); Note note = new Note("Some note", ent.guid); Guid note_guid = Guid.NewGuid(); ActionNoteCreate action = new ActionNoteCreate(note_guid, note); CampaignState state = new CampaignState(); action.apply(state, ent); Assert.AreEqual(state.notes.notes.Count, 1); Assert.IsTrue(state.notes.notes.ContainsKey(note_guid)); Assert.AreEqual(state.notes.notes[note_guid].contents, "Some note"); Assert.IsFalse(ReferenceEquals(state.notes.notes[note_guid], note)); Assert.AreEqual(state.notes.active_notes.Count, 1); Assert.IsTrue(state.notes.active_notes.Contains(note_guid)); }
public void test_merge_to_create_remove() { Guid note_guid = Guid.NewGuid(); Note note = new Note("Some note", Guid.NewGuid()); ActionNoteCreate create_action = new ActionNoteCreate(note_guid, note); List <EntryAction> actions = new List <EntryAction>() { create_action }; ActionNoteRemove remove_action = new ActionNoteRemove(note_guid); remove_action.merge_to(actions); Assert.AreEqual(actions.Count, 0); }