/// <summary> /// Initializes a new instance of the <see cref="DtzIoHelper" /> class. /// </summary> private DtzIoHelper(IList<string> stringPool) { ioStream = new IoStream(); Reader = new DateTimeZoneReader(ioStream.GetReadStream(), stringPool); Writer = new DateTimeZoneWriter(ioStream.GetWriteStream(), stringPool); this.stringPool = stringPool; }
public void Serialization() { var location = new TzdbZoneLocation( 60 * 3600 + 15 * 60 + 5, 100 * 3600 + 30 * 60 + 10, "Country name", "CO", "Etc/MadeUpZone", "Comment"); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); location.Write(writer); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); var location2 = TzdbZoneLocation.Read(reader); Assert.AreEqual(60.25 + 5.0 / 3600, location2.Latitude, 0.000001); Assert.AreEqual(100.5 + 10.0 / 3600, location2.Longitude, 0.000001); Assert.AreEqual("Country name", location2.CountryName); Assert.AreEqual("CO", location2.CountryCode); Assert.AreEqual("Etc/MadeUpZone", location2.ZoneId); Assert.AreEqual("Comment", location2.Comment); }
/// <summary> /// Initializes a new instance of the <see cref="DtzIoHelper" /> class. /// </summary> private DtzIoHelper(IList <string> stringPool) { ioStream = new IoStream(); Reader = new DateTimeZoneReader(ioStream.GetReadStream(), stringPool); Writer = new DateTimeZoneWriter(ioStream.GetWriteStream(), stringPool); this.stringPool = stringPool; }
public void InsufficientData() { var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); writer.WriteByte(1); writer.WriteCount(10); stream.Position = 0; var iterator = TzdbStreamField.ReadFields(stream).GetEnumerator(); Assert.Throws <InvalidNodaDataException>(() => iterator.MoveNext()); }
public void ReadWrite() { var map1 = new StandardDaylightAlternatingMap(Offset.FromHours(1), Summer, Winter); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); map1.Write(writer); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); var map2 = StandardDaylightAlternatingMap.Read(reader); Assert.AreEqual(map1, map2); }
public void ReadWrite() { var zone = new MapZone("windowsId", "territory", new[] { "id1", "id2", "id3" }); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); zone.Write(writer); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); var zone2 = MapZone.Read(reader); Assert.AreEqual(zone, zone2); }
public void Serialization() { var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); TestZone.Write(writer); stream.Position = 0; var reloaded = PrecalculatedDateTimeZone.Read(new DateTimeZoneReader(stream, null), TestZone.Id); // Check equivalence by finding zone intervals var interval = new Interval(Instant.FromUtc(1990, 1, 1, 0, 0), Instant.FromUtc(2010, 1, 1, 0, 0)); var originalZoneIntervals = TestZone.GetZoneIntervals(interval, ZoneEqualityComparer.Options.StrictestMatch).ToList(); var reloadedZoneIntervals = TestZone.GetZoneIntervals(interval, ZoneEqualityComparer.Options.StrictestMatch).ToList(); CollectionAssert.AreEqual(originalZoneIntervals, reloadedZoneIntervals); }
public void ReadInvalid() { var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); // Valid latitude/longitude writer.WriteSignedCount(0); writer.WriteSignedCount(0); // But no countries writer.WriteCount(0); writer.WriteString("Europe/Somewhere"); writer.WriteString(""); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); Assert.Throws <InvalidNodaDataException>(() => TzdbZone1970Location.Read(reader)); }
public void ReadInvalid() { var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); // This is invalid writer.WriteSignedCount(90 * 3600 + 1); writer.WriteSignedCount(0); writer.WriteString("name"); writer.WriteString("co"); writer.WriteString("Europe/Somewhere"); writer.WriteString(""); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); Assert.Throws <InvalidNodaDataException>(() => TzdbZoneLocation.Read(reader)); }
public void Serialization() { var location = new TzdbZone1970Location( 60 * 3600 + 15 * 60 + 5, 100 * 3600 + 30 * 60 + 10, new[] { SampleCountry }, "Etc/MadeUpZone", "Comment"); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); location.Write(writer); stream.Position = 0; var reloaded = TzdbZone1970Location.Read(new DateTimeZoneReader(stream, null)); Assert.AreEqual(location.Latitude, reloaded.Latitude); Assert.AreEqual(location.Longitude, reloaded.Longitude); CollectionAssert.AreEqual(location.Countries, reloaded.Countries); Assert.AreEqual(location.ZoneId, reloaded.ZoneId); Assert.AreEqual(location.Comment, reloaded.Comment); }
public void ReadWrite() { var zones = new WindowsZones("version", "tzdbVersion", "windowsVersion", new[] { MapZone1, MapZone2, MapZone3 }); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); zones.Write(writer); stream.Position = 0; var reader = new DateTimeZoneReader(stream, null); var zones2 = WindowsZones.Read(reader); Assert.AreEqual("version", zones2.Version); Assert.AreEqual("tzdbVersion", zones2.TzdbVersion); Assert.AreEqual("windowsVersion", zones2.WindowsVersion); Assert.AreEqual("primaryId2", zones2.PrimaryMapping["windowsId2"]); Assert.AreEqual("primaryId3", zones2.PrimaryMapping["windowsId3"]); Assert.AreEqual(new[] { MapZone1, MapZone2, MapZone3 }, zones2.MapZones); }
public void Serialization() { var location = new TzdbZone1970Location( 60 * 3600 + 15 * 60 + 5, 100 * 3600 + 30 * 60 + 10, new[] { SampleCountry }, "Etc/MadeUpZone", "Comment"); var stream = new MemoryStream(); var writer = new DateTimeZoneWriter(stream, null); location.Write(writer); stream.Position = 0; var reloaded = TzdbZone1970Location.Read(new DateTimeZoneReader(stream, null)); Assert.AreEqual(location.Latitude, reloaded.Latitude); Assert.AreEqual(location.Longitude, reloaded.Longitude); CollectionAssert.AreEqual(location.Countries, reloaded.Countries); Assert.AreEqual(location.ZoneId, reloaded.ZoneId); Assert.AreEqual(location.Comment, reloaded.Comment); }