internal void HandleZone1970LocationsField(TzdbStreamField field) { CheckSingleField(field, zone1970Locations); CheckStringPoolPresence(field); using (var stream = field.CreateStream()) { var reader = new DateTimeZoneReader(stream, stringPool); var count = reader.ReadCount(); var array = new TzdbZone1970Location[count]; for (int i = 0; i < count; i++) { array[i] = TzdbZone1970Location.Read(reader); } zone1970Locations = array; } }
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 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); }