public void CompareTo_ByNode()
        {
            var timestamp     = Timestamp.Now;
            var clockSequence = TimeGuidGenerator.GenerateRandomClockSequence();
            var timeGuid1     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            var timeGuid2     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 });
            var timeGuid3     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x78, 0xfe, 0xff });
            var timeGuid4     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x78, 0xff, 0x00 });
            var timeGuid5     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x78, 0xff, 0xff });
            var timeGuid6     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x12, 0x34, 0x56, 0x79, 0x00, 0x00 });
            var timeGuid7     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00 });
            var timeGuid8     = new TimeGuid(timestamp, clockSequence, new byte[] { 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00 });
            var timeGuid9     = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 });
            var timeGuid10    = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0x00, 0x12, 0x34, 0x00, 0x00 });
            var timeGuid11    = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0x00, 0x12, 0x35, 0x00, 0x00 });
            var timeGuid12    = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x01 });
            var timeGuid13    = new TimeGuid(timestamp, clockSequence, new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff });

            Assert.That(timeGuid1.CompareTo(timeGuid2), Is.Negative);
            Assert.That(timeGuid2.CompareTo(timeGuid3), Is.Negative);
            Assert.That(timeGuid3.CompareTo(timeGuid4), Is.Negative);
            Assert.That(timeGuid4.CompareTo(timeGuid5), Is.Negative);
            Assert.That(timeGuid5.CompareTo(timeGuid6), Is.Negative);
            Assert.That(timeGuid6.CompareTo(timeGuid7), Is.Negative);
            Assert.That(timeGuid7.CompareTo(timeGuid8), Is.Negative);
            Assert.That(timeGuid8.CompareTo(timeGuid9), Is.Negative);
            Assert.That(timeGuid9.CompareTo(timeGuid10), Is.Negative);
            Assert.That(timeGuid10.CompareTo(timeGuid11), Is.Negative);
            Assert.That(timeGuid11.CompareTo(timeGuid12), Is.Negative);
            Assert.That(timeGuid12.CompareTo(timeGuid13), Is.Negative);
        }
示例#2
0
        public void GenerateByTimestampAndClockSequence()
        {
            var guidGen       = new TimeGuidGenerator(PreciseTimestampGenerator.Instance);
            var ts            = Timestamp.Now;
            var clockSequence = TimeGuidGenerator.GenerateRandomClockSequence();
            var guid          = guidGen.NewGuid(ts, clockSequence);

            Assert.That(TimeGuidBitsLayout.GetTimestamp(guid), Is.EqualTo(ts));
            Assert.That(TimeGuidBitsLayout.GetClockSequence(guid), Is.EqualTo(clockSequence));
        }
        public void CompareTo_ByTimestamp()
        {
            var timestamp1    = Timestamp.Now;
            var timestamp2    = timestamp1.AddTicks(1);
            var clockSequence = TimeGuidGenerator.GenerateRandomClockSequence();
            var timeGuid1     = new TimeGuid(timestamp1, clockSequence, new byte[6]);
            var timeGuid2     = new TimeGuid(timestamp2, clockSequence, new byte[6]);

            Assert.That(timeGuid2.CompareTo(timeGuid1), Is.Positive);
            Assert.That(timeGuid1.CompareTo(timeGuid2), Is.Negative);
        }
 private static ushort RandomClockSequence()
 {
     return(TimeGuidGenerator.GenerateRandomClockSequence());
 }
        public void GetNode()
        {
            var node = TimeGuidGenerator.GenerateRandomNode();

            Assert.That(new TimeGuid(Timestamp.Now, TimeGuidGenerator.GenerateRandomClockSequence(), node).GetNode(), Is.EqualTo(node));
        }
        public void GetClockSequence()
        {
            var clockSequence = TimeGuidGenerator.GenerateRandomClockSequence();

            Assert.That(TimeGuid.NewGuid(Timestamp.Now, clockSequence).GetClockSequence(), Is.EqualTo(clockSequence));
        }