/// <summary> /// Write property that is a date time. /// </summary> /// <param name="propertyName">Name of json property to write.</param> /// <param name="instant">value to write.</param> public void WriteInstant( String propertyName, DateTime instant) { this.writer.WritePropertyName(propertyName); this.writer.WriteValue(InstantUtil.Format(instant)); }
public void DetectWhole() { using (var context = new UnitTestContext(this)) { context.Log.Assert(InstantUtil.Utc(2003, 5, 1, 10, 15, 30).IsMillisecond(), "Whole milliseconds"); context.Log.Assert(!InstantUtil.Utc(2003, 5, 1, 10, 15, 30).PlusNanoseconds(100000).IsMillisecond(), "Fractional milliseconds"); context.Log.Assert(InstantUtil.Utc(2003, 5, 1, 10, 15, 30, 0).IsSecond(), "Whole seconds"); context.Log.Assert(!InstantUtil.Utc(2003, 5, 1, 10, 15, 30, 1).IsSecond(), "Fractional seconds"); context.Log.Assert(InstantUtil.Utc(2003, 5, 1, 10, 15, 0).IsMinute(), "Whole minutes"); context.Log.Assert(!InstantUtil.Utc(2003, 5, 1, 10, 15, 1, 0).IsMinute(), "Fractional minutes"); } }
/// <summary> /// Verify that the result of serializing and then deserializing /// an object is the same as the original. /// </summary> private void VerifyRoundtrip(Context context, Instant value) { // To be used in assert message string nameAsString = value.AsString(); // Verify string serialization roundtrip string stringValue = value.AsString(); Instant parsedStringValue = InstantUtil.Parse(stringValue); context.Log.Assert(value == parsedStringValue, $"String roundtrip for {nameAsString} assert."); // Verify long serialization roundtrip long longValue = value.ToIsoLong(); Instant parsedLongValue = InstantUtil.FromIsoLong(longValue); context.Log.Assert(value == parsedLongValue, $"Long roundtrip for {nameAsString} assert."); }
public void IdBasedKey() { using (var context = CreateMethodContext()) { context.KeepTestData = true; // Create from timestamp var createdTime = InstantUtil.Utc(2003, 5, 1, 10, 15, 0); var rec = new IdBasedKeySample(); rec.Id = new TemporalId(createdTime, 1, 2, 3); rec.StringElement = "abc"; // Verify key serialization string keyValue = rec.ToKey().ToString(); context.Log.Verify($"Serialized key: {keyValue}"); // Verify key deserialization var key = new IdBasedKeySampleKey(); key.PopulateFrom(keyValue); context.Log.Verify($"Deserialized key: {key}"); context.Log.Assert(key.Id == rec.Id, "TemporalId serialization roundtrip."); } }