コード例 #1
0
        public void Document_Copies_Properties_To_KeyValue_Array()
        {
            // ARRANGE
            // create a Bson document with all possible value types

            var document = new BsonDocument();

            document.Add("string", new BsonValue("string"));
            document.Add("bool", new BsonValue(true));
            document.Add("objectId", new BsonValue(ObjectId.NewObjectId()));
            document.Add("DateTime", new BsonValue(DateTime.Now));
            document.Add("decimal", new BsonValue((decimal)1));
            document.Add("double", new BsonValue((double)1.0));
            document.Add("guid", new BsonValue(Guid.NewGuid()));
            document.Add("int", new BsonValue((int)1));
            document.Add("long", new BsonValue((long)1));
            document.Add("bytes", new BsonValue(new byte[] { (byte)1 }));
            document.Add("bsonDocument", new BsonDocument());

            // ACT
            // copy all properties to destination array

            var result = new KeyValuePair <string, BsonValue> [document.Count()];

            document.CopyTo(result, 0);
        }
コード例 #2
0
        public void Document_copies_properties_to_KeyValue_array()
        {
            // ARRANGE
            // create a Bson document with all possible value types

            var document = new BsonDocument();

            document.Add("string", new BsonValue("string"));
            document.Add("bool", new BsonValue(true));
            document.Add("objectId", new BsonValue(ObjectId.NewObjectId()));
            document.Add("DateTime", new BsonValue(DateTime.Now));
            document.Add("decimal", new BsonValue((decimal)1));
            document.Add("double", new BsonValue((double)1.0));
            document.Add("guid", new BsonValue(Guid.NewGuid()));
            document.Add("int", new BsonValue((int)1));
            document.Add("long", new BsonValue((long)1));
            document.Add("bytes", new BsonValue(new byte[] { (byte)1 }));
            document.Add("bsonDocument", new BsonDocument());

            // ACT
            // copy all properties to destination array

            var result = new KeyValuePair <string, BsonValue> [document.Count()];

            document.CopyTo(result, 0);

            // ASSERT
            // all BsonValue instances have been added to the array by reference

            //TODO: implement get from another way
            // Assert.IsTrue(result.All(kv => object.ReferenceEquals(document.Get(kv.Key), kv.Value)));
        }