public static EntryElement ToEntry(EventRecord evnt, string userHostName) { if (evnt == null || userHostName == null) return null; var entry = new EntryElement(); entry.SetTitle(String.Format("{0} #{1}", evnt.EventStreamId, evnt.EventNumber)); entry.SetId(HostName.Combine(userHostName, "/streams/{0}/{1}", evnt.EventStreamId, evnt.EventNumber)); entry.SetUpdated(evnt.TimeStamp); entry.SetAuthor(AtomSpecs.Author); entry.SetSummary(String.Format("Entry #{0}", evnt.EventNumber)); entry.AddLink(HostName.Combine(userHostName, "/streams/{0}/{1}", evnt.EventStreamId, evnt.EventNumber), "edit", null); entry.AddLink( HostName.Combine(userHostName, "/streams/{0}/event/{1}?format=text", evnt.EventStreamId, evnt.EventNumber), null, ContentType.PlainText); entry.AddLink( HostName.Combine(userHostName, "/streams/{0}/event/{1}?format=json", evnt.EventStreamId, evnt.EventNumber), "alternate", ContentType.Json); entry.AddLink( HostName.Combine(userHostName, "/streams/{0}/event/{1}?format=xml", evnt.EventStreamId, evnt.EventNumber), "alternate", ContentType.Xml); return entry; }
private static void SetEntryProperties(string stream, int eventNumber, DateTime timestamp, Uri requestedUrl, EntryElement entry) { var escapedStreamId = Uri.EscapeDataString(stream); entry.SetTitle(eventNumber + "@" + stream); entry.SetId(HostName.Combine(requestedUrl, "/streams/{0}/{1}", escapedStreamId, eventNumber)); entry.SetUpdated(timestamp); entry.SetAuthor(AtomSpecs.Author); entry.AddLink("edit", HostName.Combine(requestedUrl, "/streams/{0}/{1}", escapedStreamId, eventNumber)); entry.AddLink("alternate", HostName.Combine(requestedUrl, "/streams/{0}/{1}", escapedStreamId, eventNumber)); }
public void have_all_fields_filled() { var writer = XmlWriter.Create(new MemoryStream()); var entry = new EntryElement(); Assert.Throws<AtomSpecificationViolationException>(() => entry.WriteXml(writer)); entry.SetTitle("test #0"); Assert.Throws<AtomSpecificationViolationException>(() => entry.WriteXml(writer)); entry.SetId("guid"); Assert.Throws<AtomSpecificationViolationException>(() => entry.WriteXml(writer)); entry.SetUpdated(DateTime.UtcNow); Assert.Throws<AtomSpecificationViolationException>(() => entry.WriteXml(writer)); entry.SetAuthor(AtomSpecs.Author); Assert.Throws<AtomSpecificationViolationException>(() => entry.WriteXml(writer)); entry.SetSummary("Entry #0"); Assert.DoesNotThrow(() => entry.WriteXml(writer)); writer.Close(); }