public void TestCompareToBsonValue() { var bsonDocument = new BsonDocument { { "a", 1 }, { "b", 2 } }; var bson = bsonDocument.ToBson(); using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson)) { Assert.AreEqual(0, lazyBsonDocument.CompareTo((BsonValue)bsonDocument)); } using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone["a"] = 0; Assert.AreEqual(1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone["a"] = 2; Assert.AreEqual(-1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone.SetElement(0, new BsonElement("c", 1)); // "a" < "c" when comparing names Assert.AreEqual(-1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone.Remove("b"); Assert.AreEqual(1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize <LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone["c"] = 3; Assert.AreEqual(-1, lazyBsonDocument.CompareTo((BsonValue)clone)); } }
/// <summary> /// Creates a clone of the cursor. /// </summary> /// <param name="documentType">The type of the documents returned.</param> /// <param name="serializer">The serializer to use.</param> /// <returns> /// A clone of the cursor. /// </returns> public virtual MongoCursor Clone(Type documentType, IBsonSerializer serializer) { var clone = Create(documentType, _collection, _query, _readPreference, serializer); clone._options = _options == null ? null : (BsonDocument)_options.Clone(); clone._flags = _flags; clone._skip = _skip; clone._limit = _limit; clone._batchSize = _batchSize; clone._fields = _fields; return(clone); }
internal static BsonDocument CreateClientDocument(string applicationName, BsonDocument driverDocument, BsonDocument osDocument, string platformString) { var clientDocument = new BsonDocument { { "application", () => new BsonDocument("name", applicationName), applicationName != null }, { "driver", driverDocument }, { "os", osDocument.Clone() }, // clone because we might be removing optional fields from this particular clientDocument { "platform", platformString } }; return RemoveOptionalFieldsUntilDocumentIsLessThan512Bytes(clientDocument); }
internal static BsonDocument CreateClientDocument(string applicationName, BsonDocument driverDocument, BsonDocument osDocument, string platformString) { var clientDocument = new BsonDocument { { "application", () => new BsonDocument("name", applicationName), applicationName != null }, { "driver", driverDocument }, { "os", osDocument.Clone() }, // clone because we might be removing optional fields from this particular clientDocument { "platform", platformString } }; return(RemoveOptionalFieldsUntilDocumentIsLessThan512Bytes(clientDocument)); }
/// <summary> /// Creates a clone of the cursor. /// </summary> /// <returns>A clone of the cursor.</returns> public virtual MongoCursor <TNewDocument> Clone <TNewDocument>() { var clone = new MongoCursor <TNewDocument>(collection, query); clone.options = options == null ? null : (BsonDocument)options.Clone(); clone.flags = flags; clone.slaveOk = slaveOk; clone.skip = skip; clone.limit = limit; clone.batchSize = batchSize; return(clone); }
/// <summary> /// Creates a clone of the cursor. /// </summary> /// <param name="documentType">The type of the documents returned.</param> /// <returns>A clone of the cursor.</returns> public virtual MongoCursor Clone(Type documentType) { var clone = Create(documentType, _collection, _query); clone._options = _options == null ? null : (BsonDocument)_options.Clone(); clone._flags = _flags; clone._slaveOk = _slaveOk; clone._skip = _skip; clone._limit = _limit; clone._batchSize = _batchSize; clone._fields = _fields; clone._serializationOptions = _serializationOptions; return(clone); }
/// <summary> /// Creates a clone of the cursor. /// </summary> /// <param name="documentType">The type of the documents returned.</param> /// <returns>A clone of the cursor.</returns> public virtual MongoCursor Clone(Type documentType) { var clone = Create(documentType, collection, query); clone.options = options == null ? null : (BsonDocument)options.Clone(); clone.flags = flags; clone.slaveOk = slaveOk; clone.skip = skip; clone.limit = limit; clone.batchSize = batchSize; clone.fields = fields; clone.serializationOptions = serializationOptions; return(clone); }
/// <summary> /// Creates a clone of the cursor. /// </summary> /// <param name="documentType">The type of the documents returned.</param> /// <param name="serializer">The serializer to use.</param> /// <returns> /// A clone of the cursor. /// </returns> public virtual MongoCursor Clone(Type documentType, IBsonSerializer serializer) { #pragma warning disable 618 var clone = Create(documentType, _collection, _query, _readConcern, _readPreference, serializer); #pragma warning restore clone._batchSize = _batchSize; clone._collation = _collation; clone._fields = _fields; clone._flags = _flags; clone._limit = _limit; clone._maxAwaitTime = _maxAwaitTime; clone._options = _options == null ? null : (BsonDocument)_options.Clone(); clone._skip = _skip; return(clone); }
public void TestClone() { var document = new BsonDocument("d", new BsonDocument("x", 1)); var clone = (BsonDocument)document.Clone(); Assert.AreEqual(clone, document); Assert.AreSame(clone["d"], document["d"]); }
public void TestCompareToBsonValue() { var bsonDocument = new BsonDocument { { "a", 1 }, { "b", 2 } }; var bson = bsonDocument.ToBson(); using (var lazyBsonDocument = BsonSerializer.Deserialize<LazyBsonDocument>(bson)) { Assert.AreEqual(0, lazyBsonDocument.CompareTo((BsonValue)bsonDocument)); } using (var lazyBsonDocument = BsonSerializer.Deserialize<LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone["a"] = 0; Assert.AreEqual(1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize<LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone["a"] = 2; Assert.AreEqual(-1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize<LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone.SetElement(0, new BsonElement("c", 1)); // "a" < "c" when comparing names Assert.AreEqual(-1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize<LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone.Remove("b"); Assert.AreEqual(1, lazyBsonDocument.CompareTo((BsonValue)clone)); } using (var lazyBsonDocument = BsonSerializer.Deserialize<LazyBsonDocument>(bson)) { var clone = (BsonDocument)bsonDocument.Clone(); clone["c"] = 3; Assert.AreEqual(-1, lazyBsonDocument.CompareTo((BsonValue)clone)); } }
// public methods /// <summary> /// Creates a shallow clone of the BsonJavaScriptWithScope (see also DeepClone). /// </summary> /// <returns>A shallow clone of the BsonJavaScriptWithScope.</returns> public override BsonValue Clone() { return(new BsonJavaScriptWithScope(Code, (BsonDocument)_scope.Clone())); }