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 requests      = new List <UpdateRequest>
            {
                new UpdateRequest(
                    UpdateType.Update,
                    new BsonDocument("x", 1),
                    new BsonDocument("$set", new BsonDocument("x", 2)))
                {
                    Hint = new BsonDocument("_id", 1)
                }
            };
            var batch   = new BatchableSource <UpdateRequest>(requests);
            var subject = new RetryableUpdateCommandOperation(_collectionNamespace, batch, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };

            var exception = Record.Exception(() => ExecuteOperation(subject, async, useImplicitSession: true));

            if (Feature.HintForUpdateAndReplaceOperations.IsSupported(serverVersion))
            {
                exception.Should().BeNull();
            }
            else if (!writeConcern.IsAcknowledged)
            {
                exception.Should().BeOfType <NotSupportedException>();
            }
            else if (Feature.HintForUpdateAndReplaceOperations.DriverMustThrowIfNotSupported(serverVersion))
            {
                exception.Should().BeOfType <NotSupportedException>();
            }
            else
            {
                exception.Should().BeOfType <MongoCommandException>();
            }
        }
Beispiel #2
0
        public void Let_get_and_set_should_work([Values(null, "{ name : 'name' }")] string let)
        {
            var requests = new List <UpdateRequest>
            {
                new UpdateRequest(
                    UpdateType.Update,
                    new BsonDocument("x", 1),
                    new BsonDocument("$set", new BsonDocument("x", 2)))
                {
                    Hint = new BsonDocument("_id", 1)
                }
            };
            var batch   = new BatchableSource <UpdateRequest>(requests);
            var subject = new RetryableUpdateCommandOperation(_collectionNamespace, batch, _messageEncoderSettings);
            var value   = let != null?BsonDocument.Parse(let) : null;

            subject.Let = value;
            var result = subject.Let;

            result.Should().Be(value);
        }