コード例 #1
0
 public void TestByteArrayConstructor()
 {
     byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
     var objectId = new BsonObjectId(bytes);
     Assert.AreEqual(0x01020304, objectId.Timestamp);
     Assert.AreEqual(0x050607, objectId.Machine);
     Assert.AreEqual(0x0809, objectId.Pid);
     Assert.AreEqual(0x0a0b0c, objectId.Increment);
     Assert.AreEqual(0x05060708090a0b0c, objectId.MachinePidIncrement);
     Assert.AreEqual(Bson.UnixEpoch.AddSeconds(0x01020304), objectId.CreationTime);
     Assert.AreEqual("0102030405060708090a0b0c", objectId.ToString());
     Assert.IsTrue(bytes.SequenceEqual(objectId.ToByteArray()));
 }
コード例 #2
0
        public void TestStringConstructor()
        {
            byte[] bytes    = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var    objectId = new BsonObjectId("0102030405060708090a0b0c");

            Assert.AreEqual(0x01020304, objectId.Timestamp);
            Assert.AreEqual(0x050607, objectId.Machine);
            Assert.AreEqual(0x0809, objectId.Pid);
            Assert.AreEqual(0x0a0b0c, objectId.Increment);
            Assert.AreEqual(0x050607, objectId.Machine);
            Assert.AreEqual(0x0809, objectId.Pid);
            Assert.AreEqual(0x0a0b0c, objectId.Increment);
            Assert.AreEqual(BsonConstants.UnixEpoch.AddSeconds(0x01020304), objectId.CreationTime);
            Assert.AreEqual("0102030405060708090a0b0c", objectId.ToString());
            Assert.IsTrue(bytes.SequenceEqual(objectId.ToByteArray()));
        }
コード例 #3
0
        public void TestIntIntShortIntConstructor()
        {
#pragma warning disable 618
            byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var objectId = new BsonObjectId(0x01020304, 0x050607, 0x0809, 0x0a0b0c);
            Assert.AreEqual(0x01020304, objectId.Timestamp);
            Assert.AreEqual(0x050607, objectId.Machine);
            Assert.AreEqual(0x0809, objectId.Pid);
            Assert.AreEqual(0x0a0b0c, objectId.Increment);
            Assert.AreEqual(0x050607, objectId.Machine);
            Assert.AreEqual(0x0809, objectId.Pid);
            Assert.AreEqual(0x0a0b0c, objectId.Increment);
            Assert.AreEqual(BsonConstants.UnixEpoch.AddSeconds(0x01020304), objectId.CreationTime);
            Assert.AreEqual("0102030405060708090a0b0c", objectId.ToString());
            Assert.IsTrue(bytes.SequenceEqual(objectId.ToByteArray()));
#pragma warning restore
        }
コード例 #4
0
        public void TestIntIntShortIntConstructor()
        {
#pragma warning disable 618
            byte[] bytes    = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var    objectId = new BsonObjectId(0x01020304, 0x050607, 0x0809, 0x0a0b0c);
            Assert.Equal(0x01020304, objectId.Timestamp);
            Assert.Equal(0x050607, objectId.Machine);
            Assert.Equal(0x0809, objectId.Pid);
            Assert.Equal(0x0a0b0c, objectId.Increment);
            Assert.Equal(0x050607, objectId.Machine);
            Assert.Equal(0x0809, objectId.Pid);
            Assert.Equal(0x0a0b0c, objectId.Increment);
            Assert.Equal(BsonConstants.UnixEpoch.AddSeconds(0x01020304), objectId.CreationTime);
            Assert.Equal("0102030405060708090a0b0c", objectId.ToString());
            Assert.True(bytes.SequenceEqual(objectId.ToByteArray()));
#pragma warning restore
        }