public void CreateFromeTimeSpan() { // Arrange var factory = new TimestampFactory(); // Act var zero = factory.Create(TimeSpan.Zero); // Assert Assert.Equal(0, zero); }
public void TimeShort() { // Arrange var factory = new TimestampFactory(); // Act var zero = factory.ToTimeSpan(0); // Assert Assert.Equal(TimeSpan.Zero, zero); }
public void Create(DateTimeKind kind) { // Arrange var factory = new TimestampFactory(); var z = new DateTime(2001, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); // Act if (kind != DateTimeKind.Utc) { z = z.ToLocalTime(); } if (kind == DateTimeKind.Unspecified) { z = DateTime.SpecifyKind(z, DateTimeKind.Unspecified); } var zero = factory.Create(z); // Assert Assert.Equal(0, zero); }
public void DateTimeShort(DateTimeKind kind) { // Arrange var factory = new TimestampFactory(); var z = new DateTime(2001, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); // Act if (z.Kind != kind) { z = z.ToLocalTime(); } if (kind == DateTimeKind.Unspecified) { z = DateTime.SpecifyKind(z, DateTimeKind.Unspecified); } var zero = factory.ToDateTime(0, kind); // Assert Assert.Equal(kind, zero.Kind); Assert.Equal(z, zero); }
public static bool TryBuildFeedAsync <T>(string url, string ns, ulong rs, IEnumerable <T> records, string mediaType, Encoding encoding, out byte[] stream, out DateTimeOffset?lastModified) where T : IRecord <T> { // FIXME: need to normalize this to produce stable IDs (i.e. when query strings are in a different order) var id = WyHash64.ComputeHash64(Encoding.UTF8.GetBytes(url), BitConverter.ToUInt64(Encoding.UTF8.GetBytes(nameof(SyndicationFeed)))); var items = new List <SyndicationItem>(); lastModified = default; foreach (var record in records) { var title = $"{typeof(T).Name}"; var description = $"Location of the {typeof(T).Name} record at the specified feed item URI"; var uri = $"/api/{ns}/v{rs}/{typeof(T).Name}/{record.Uuid}"; var timestamp = TimestampFactory.FromUInt64(record.TimestampV2); var item = new SyndicationItem(title, description, new Uri(uri, UriKind.Relative), title, timestamp); items.Add(item); lastModified = timestamp; } var feed = new SyndicationFeed($"{typeof(T).Name} Query Feed", $"A feed containing {typeof(T).Name} records for the query specified by the feed URI'", new Uri(url), $"{id}", lastModified.GetValueOrDefault(DateTimeOffset.Now)) { Items = items }; var settings = new XmlWriterSettings { Encoding = encoding, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = false, Indent = true }; SyndicationFeedFormatter formatter; switch (mediaType) { case Constants.MediaTypeNames.Application.RssXml: case Constants.MediaTypeNames.Text.Xml: { formatter = new Rss20FeedFormatter(feed, false); break; } case Constants.MediaTypeNames.Application.AtomXml: { formatter = new Atom10FeedFormatter(feed); break; } default: { stream = default; return(false); } } using var ms = new MemoryStream(); using var writer = XmlWriter.Create(ms, settings); formatter.WriteTo(writer); writer.Flush(); stream = ms.ToArray(); return(true); }