public void test_revert() { Entry ent = new Entry(42, DateTime.Now, "Some Entry"); CalendarEvent evt = new CalendarEvent(Guid.NewGuid(), 42, "Some event"); Guid event_guid = Guid.NewGuid(); ActionCalendarEventCreate action = new ActionCalendarEventCreate(event_guid, evt); CampaignState state = new CampaignState(); action.apply(state, ent); action.revert(state, ent); Assert.AreEqual(state.events.events.Count, 0); Assert.AreEqual(state.events.active_events.Count, 0); }
public void test_serialization() { CalendarEvent evt = new CalendarEvent(Guid.NewGuid(), 42, "Some event"); ActionCalendarEventCreate foo = new ActionCalendarEventCreate(Guid.NewGuid(), evt), bar; DataContractSerializer fmt = new DataContractSerializer(typeof(ActionCalendarEventCreate)); 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 = (ActionCalendarEventCreate)(fmt.ReadObject(xr, true)); } Assert.AreEqual(foo.guid, bar.guid); Assert.AreEqual(foo.evt.name, bar.evt.name); }
public void test_merge_to_remove_create() { Guid event_guid = Guid.NewGuid(); ActionCalendarEventRemove remove_action = new ActionCalendarEventRemove(event_guid); List <EntryAction> actions = new List <EntryAction>() { remove_action }; CalendarEvent evt = new CalendarEvent(Guid.NewGuid(), 42, "Some event"); ActionCalendarEventCreate create_action = new ActionCalendarEventCreate(event_guid, evt); create_action.merge_to(actions); Assert.AreEqual(actions.Count, 0); }
public void test_apply() { Entry ent = new Entry(42, DateTime.Now, "Some Entry"); CalendarEvent evt = new CalendarEvent(Guid.NewGuid(), 42, "Some event"); Guid event_guid = Guid.NewGuid(); ActionCalendarEventCreate action = new ActionCalendarEventCreate(event_guid, evt); CampaignState state = new CampaignState(); action.apply(state, ent); Assert.AreEqual(state.events.events.Count, 1); Assert.IsTrue(state.events.events.ContainsKey(event_guid)); Assert.AreEqual(state.events.events[event_guid].name, "Some event"); Assert.IsFalse(ReferenceEquals(state.events.events[event_guid], evt)); Assert.AreEqual(state.events.active_events.Count, 1); Assert.IsTrue(state.events.active_events.Contains(event_guid)); }
public void test_merge_to_create_update() { Guid event_guid = Guid.NewGuid(); CalendarEvent from = new CalendarEvent(Guid.NewGuid(), 42, "Some event"), to = new CalendarEvent(Guid.NewGuid(), 42, "Some updated event"); ActionCalendarEventCreate create_action = new ActionCalendarEventCreate(event_guid, from); List <EntryAction> actions = new List <EntryAction>() { create_action }; ActionCalendarEventUpdate update_action = new ActionCalendarEventUpdate(event_guid, from, to, false, true, false, false); update_action.merge_to(actions); Assert.AreEqual(actions.Count, 1); ActionCalendarEventCreate merged_action = actions[0] as ActionCalendarEventCreate; Assert.IsNotNull(merged_action); Assert.AreEqual(merged_action.guid, event_guid); Assert.AreEqual(merged_action.evt.entry_guid, from.entry_guid); Assert.AreEqual(merged_action.evt.timestamp, 42); Assert.AreEqual(merged_action.evt.name, "Some updated event"); }