// constructors public UpdateOpcodeOperationEmulator( CollectionNamespace collectionNamespace, UpdateRequest request, MessageEncoderSettings messageEncoderSettings) { _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace)); _request = Ensure.IsNotNull(request, nameof(request)); _messageEncoderSettings = Ensure.IsNotNull(messageEncoderSettings, nameof(messageEncoderSettings)); }
// constructors public UpdateOpcodeOperationEmulator( CollectionNamespace collectionNamespace, UpdateRequest request, MessageEncoderSettings messageEncoderSettings) { _collectionNamespace = Ensure.IsNotNull(collectionNamespace, "collectionNamespace"); _request = Ensure.IsNotNull(request, "request"); _messageEncoderSettings = Ensure.IsNotNull(messageEncoderSettings, "messageEncoderSettings"); }
public void Should_convert_from_UpdateRequest_to_ReplaceOne_with_BsonDocument(bool isUpsert) { var filter = new BsonDocument("a", 1); var replacement = BsonDocument.Parse("{a:2}"); var request = new UpdateRequest(UpdateType.Update, new BsonDocumentWrapper(filter), new BsonDocumentWrapper(replacement)) { IsMulti = false, IsUpsert = isUpsert }; var result = WriteModel<BsonDocument>.FromCore(request); result.Should().BeOfType<ReplaceOneModel<BsonDocument>>(); var model = (ReplaceOneModel<BsonDocument>)result; ((BsonDocumentFilterDefinition<BsonDocument>)model.Filter).Document.Should().Be(filter); model.Replacement.Should().BeSameAs(replacement); model.IsUpsert.Should().Be(isUpsert); }
public void Should_convert_from_UpdateRequest_to_ReplaceOne_with_BsonDocument(bool isUpsert) { var criteria = Query.EQ("a", 1); var replacement = BsonDocument.Parse("{a:2}"); var request = new UpdateRequest(UpdateType.Update, new BsonDocumentWrapper(criteria), new BsonDocumentWrapper(replacement)) { IsMulti = false, IsUpsert = isUpsert }; var result = WriteModel<BsonDocument>.FromCore(request); result.Should().BeOfType<ReplaceOneModel<BsonDocument>>(); var model = (ReplaceOneModel<BsonDocument>)result; model.Criteria.Should().BeSameAs(criteria); model.Replacement.Should().BeSameAs(replacement); model.IsUpsert.Should().Be(isUpsert); }
public void Execute_with_hint_should_throw_when_hint_is_not_supported( [Values(0, 1)] int w, [Values(false, true)] bool async) { var writeConcern = new WriteConcern(w); var serverVersion = CoreTestConfiguration.ServerVersion; var request = new UpdateRequest( UpdateType.Update, new BsonDocument("x", 1), new BsonDocument("$set", new BsonDocument("x", 2))) { Hint = new BsonDocument("_id", 1) }; var subject = new UpdateOpcodeOperation(_collectionNamespace, request, _messageEncoderSettings) { WriteConcern = writeConcern }; var exception = Record.Exception(() => ExecuteOperation(subject, async)); if (!writeConcern.IsAcknowledged) { exception.Should().BeOfType <NotSupportedException>(); } else if (Feature.HintForUpdateAndReplaceOperations.IsSupported(serverVersion)) { exception.Should().BeNull(); } else if (Feature.HintForUpdateAndReplaceOperations.DriverMustThrowIfNotSupported(serverVersion)) { exception.Should().BeOfType <NotSupportedException>(); } else { exception.Should().BeOfType <MongoCommandException>(); } }
public void Should_convert_from_UpdateRequest_to_UpdateMany(bool isUpsert) { var filter = BsonDocument.Parse("{a:1}"); var update = BsonDocument.Parse("{$set: {a:2}}"); var request = new UpdateRequest(UpdateType.Update, new BsonDocumentWrapper(filter), new BsonDocumentWrapper(update)) { IsMulti = true, IsUpsert = isUpsert }; var result = WriteModel<BsonDocument>.FromCore(request); result.Should().BeOfType<UpdateManyModel<BsonDocument>>(); var model = (UpdateManyModel<BsonDocument>)result; ((BsonDocumentFilterDefinition<BsonDocument>)model.Filter).Document.Should().BeSameAs(filter); ((BsonDocumentUpdateDefinition<BsonDocument>)model.Update).Document.Should().BeSameAs(update); model.IsUpsert.Should().Be(isUpsert); }
public void Should_convert_from_UpdateRequest_to_UpdateOne_with_wrappers(bool isUpsert) { var criteria = Query.EQ("a", 1); var update = Update.Set("a", 2); var request = new UpdateRequest(UpdateType.Update, new BsonDocumentWrapper(criteria), new BsonDocumentWrapper(update)) { IsMulti = false, IsUpsert = isUpsert }; var result = WriteModel<BsonDocument>.FromCore(request); result.Should().BeOfType<UpdateOneModel<BsonDocument>>(); var model = (UpdateOneModel<BsonDocument>)result; model.Criteria.Should().BeSameAs(criteria); model.Update.Should().BeSameAs(update); model.IsUpsert.Should().Be(isUpsert); }
public void Should_convert_from_UpdateRequest_to_UpdateMany(bool isUpsert) { var criteria = BsonDocument.Parse("{a:1}"); var update = BsonDocument.Parse("{$set: {a:2}}"); var request = new UpdateRequest(UpdateType.Update, new BsonDocumentWrapper(criteria), new BsonDocumentWrapper(update)) { IsMulti = true, IsUpsert = isUpsert }; var result = WriteModel<BsonDocument>.FromCore(request); result.Should().BeOfType<UpdateManyModel<BsonDocument>>(); var model = (UpdateManyModel<BsonDocument>)result; model.Criteria.Should().BeSameAs(criteria); model.Update.Should().BeSameAs(update); model.IsUpsert.Should().Be(isUpsert); }