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");
     }
 }
Esempio n. 2
0
        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.");
            }
        }