Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }