public void Constructor_should_initialize_instance()
 {
     var subject = new DeleteMessage(_requestId, _collectionNamespace, _query, _isMulti);
     subject.CollectionNamespace.Should().Be(_collectionNamespace);
     subject.IsMulti.Should().Be(_isMulti);
     subject.Query.Should().Be(_query);
     subject.RequestId.Should().Be(_requestId);
 }
Beispiel #2
0
        public void Constructor_should_initialize_instance()
        {
            var subject = new DeleteMessage(_requestId, _collectionNamespace, _query, _isMulti);

            subject.CollectionNamespace.Should().Be(_collectionNamespace);
            subject.IsMulti.Should().Be(_isMulti);
            subject.Query.Should().Be(_query);
            subject.RequestId.Should().Be(_requestId);
        }
        public void GetEncoder_should_return_encoder()
        {
            var mockEncoder = Substitute.For<IMessageEncoder<DeleteMessage>>();
            var mockEncoderFactory = Substitute.For<IMessageEncoderFactory>();
            mockEncoderFactory.GetDeleteMessageEncoder().Returns(mockEncoder);

            var subject = new DeleteMessage(1, _collectionNamespace, new BsonDocument("x", 1), true);
            var encoder = subject.GetEncoder(mockEncoderFactory);
            encoder.Should().BeSameAs(mockEncoder);
        }
        public void GetEncoder_should_return_encoder()
        {
            var subject = new DeleteMessage(1, _collectionNamespace, new BsonDocument("x", 1), true);
            var stubEncoderFactory = Substitute.For<IMessageEncoderFactory>();
            var stubEncoder = Substitute.For<IMessageEncoder>();
            stubEncoderFactory.GetDeleteMessageEncoder().Returns(stubEncoder);

            var result = subject.GetEncoder(stubEncoderFactory);

            result.Should().BeSameAs(stubEncoder);
        }
        public void GetEncoder_should_return_encoder()
        {
            var subject = new DeleteMessage(1, _collectionNamespace, new BsonDocument("x", 1), true);
            var mockEncoderFactory = new Mock<IMessageEncoderFactory>();
            var encoder = new Mock<IMessageEncoder>().Object;
            mockEncoderFactory.Setup(f => f.GetDeleteMessageEncoder()).Returns(encoder);

            var result = subject.GetEncoder(mockEncoderFactory.Object);

            result.Should().BeSameAs(encoder);
        }
Beispiel #6
0
        public void GetEncoder_should_return_encoder()
        {
            var subject            = new DeleteMessage(1, _collectionNamespace, new BsonDocument("x", 1), true);
            var stubEncoderFactory = Substitute.For <IMessageEncoderFactory>();
            var stubEncoder        = Substitute.For <IMessageEncoder>();

            stubEncoderFactory.GetDeleteMessageEncoder().Returns(stubEncoder);

            var result = subject.GetEncoder(stubEncoderFactory);

            result.Should().BeSameAs(stubEncoder);
        }
        public void GetEncoder_should_return_encoder()
        {
            var subject            = new DeleteMessage(1, _collectionNamespace, new BsonDocument("x", 1), true);
            var mockEncoderFactory = new Mock <IMessageEncoderFactory>();
            var encoder            = new Mock <IMessageEncoder>().Object;

            mockEncoderFactory.Setup(f => f.GetDeleteMessageEncoder()).Returns(encoder);

            var result = subject.GetEncoder(mockEncoderFactory.Object);

            result.Should().BeSameAs(encoder);
        }
Beispiel #8
0
        public void GetEncoder_should_return_encoder()
        {
            var mockEncoder        = Substitute.For <IMessageEncoder <DeleteMessage> >();
            var mockEncoderFactory = Substitute.For <IMessageEncoderFactory>();

            mockEncoderFactory.GetDeleteMessageEncoder().Returns(mockEncoder);

            var subject = new DeleteMessage(1, "database", "collection", new BsonDocument("x", 1), true);
            var encoder = subject.GetEncoder(mockEncoderFactory);

            encoder.Should().BeSameAs(mockEncoder);
        }
        // static constructor
        static DeleteMessageJsonEncoderTests()
        {
            __testMessage = new DeleteMessage(__requestId, __collectionNamespace, __query, __isMulti);

            __testMessageJson =
                "{ " +
                    "\"opcode\" : \"delete\", " +
                    "\"requestId\" : 1, " +
                    "\"database\" : \"d\", " +
                    "\"collection\" : \"c\", "+
                    "\"query\" : { \"x\" : 1 }, " +
                    "\"isMulti\" : false" +
                " }";
        }
        // static constructor
        static DeleteMessageBinaryEncoderTests()
        {
            __testMessage = new DeleteMessage(__requestId, __databaseName, __collectionName, __query, __isMulti);

            __testMessageBytes = new byte[]
            {
                0, 0, 0, 0, // messageLength
                1, 0, 0, 0, // requestId
                0, 0, 0, 0, // responseTo
                214, 7, 0, 0, // opcode = 2006
                0, 0, 0, 0, // reserved
                (byte)'d', (byte)'.', (byte)'c', 0, // fullCollectionName
                1, 0, 0, 0, // flags
                12, 0, 0, 0, 0x10, (byte)'x', 0, 1, 0, 0, 0, 0 // query
            };
            __testMessageBytes[0] = (byte)__testMessageBytes.Length;
            __flagsOffset = 20 + (__databaseName.Length + 1 + __collectionName.Length + 1);
        }
        public void WriteMessage_should_encode_flags_correctly(int flags, bool isMulti)
        {
            var message = new DeleteMessage(__requestId, __databaseName, __collectionName, __query, isMulti);

            using (var stream = new MemoryStream())
            using (var binaryWriter = new BsonBinaryWriter(stream))
            {
                var subject = new DeleteMessageBinaryEncoder(null, binaryWriter);
                subject.WriteMessage(message);
                var bytes = stream.ToArray();
                bytes[__flagsOffset].Should().Be((byte)flags);
            }
        }
        private void ProcessDeleteMessage(DeleteMessage originalMessage, Queue<RequestMessage> messageQueue, ConnectionId connectionId, DeleteMessageBinaryEncoder encoder, Stopwatch stopwatch)
        {
            var commandName = "delete";
            var operationId = EventContext.OperationId;
            int requestId = originalMessage.RequestId;
            var expectedResponseType = ExpectedResponseType.None;
            int gleRequestId;
            WriteConcern writeConcern;
            if (TryGetWriteConcernFromGLE(messageQueue, out gleRequestId, out writeConcern))
            {
                requestId = gleRequestId;
                expectedResponseType = ExpectedResponseType.GLE;
            }

            if (_startedEvent != null)
            {
                var decodedMessage = encoder.ReadMessage(RawBsonDocumentSerializer.Instance);
                try
                {
                    var entry = new BsonDocument
                    {
                        { "q", decodedMessage.Query },
                        { "limit", decodedMessage.IsMulti ? 0 : 1 }
                    };
                    var command = new BsonDocument
                    {
                        { commandName, decodedMessage.CollectionNamespace.CollectionName },
                        { "deletes", new BsonArray(new [] { entry }) }
                    };

                    if (writeConcern == null)
                    {
                        command["writeConcern"] = WriteConcern.Unacknowledged.ToBsonDocument();
                    }
                    else if (!writeConcern.IsServerDefault)
                    {
                        command["writeConcern"] = writeConcern.ToBsonDocument();
                    }

                    var @event = new CommandStartedEvent(
                        commandName,
                        command,
                        decodedMessage.CollectionNamespace.DatabaseNamespace,
                        operationId,
                        requestId,
                        connectionId);

                    _startedEvent(@event);
                }
                finally
                {
                    var disposable = decodedMessage.Query as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }

            if (_shouldTrackState)
            {
                _state.TryAdd(requestId, new CommandState
                {
                    CommandName = commandName,
                    OperationId = operationId,
                    Stopwatch = stopwatch,
                    ExpectedResponseType = expectedResponseType
                });
            }
        }