public async void SendRequestAsync_With_No_StreamingRequest_Should_Fail()
        {
            var requestHandler  = new Mock <RequestHandler>();
            var requestManager  = new Mock <RequestManager>();
            var payloadSender   = new Mock <PayloadSender>();
            var payloadReceiver = new Mock <PayloadReceiver>();
            var protocolAdapter = new ProtocolAdapter(requestHandler.Object, requestManager.Object, payloadSender.Object, payloadReceiver.Object);

            await Assert.ThrowsAsync <ArgumentNullException>(() => protocolAdapter.SendRequestAsync(null));
        }
Esempio n. 2
0
        /// <summary>
        /// Task used to send data over this server connection.
        /// Throws <see cref="InvalidOperationException"/> if called when server is not connected.
        /// Throws <see cref="ArgumentNullException"/> if request is null.
        /// </summary>
        /// <param name="request">The <see cref="StreamingRequest"/> to send.</param>
        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> used to signal this operation should be cancelled.</param>
        /// <returns>A <see cref="Task"/> of type <see cref="ReceiveResponse"/> handling the send operation.</returns>
        public async Task <ReceiveResponse> SendAsync(StreamingRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (!_sender.IsConnected || !_receiver.IsConnected)
            {
                throw new InvalidOperationException("The server is not connected.");
            }

            return(await _protocolAdapter.SendRequestAsync(request, cancellationToken).ConfigureAwait(false));
        }
        /// <summary>
        /// Task used to send data over this client connection.
        /// Throws <see cref="InvalidOperationException"/> if called when the client is disconnected.
        /// Throws <see cref="ArgumentNullException"/> if message is null.
        /// </summary>
        /// <param name="message">The <see cref="StreamingRequest"/> to send.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> used to signal this operation should be cancelled.</param>
        /// <returns>A <see cref="Task"/> that will produce an instance of <see cref="ReceiveResponse"/> on completion of the send operation.</returns>
        public Task <ReceiveResponse> SendAsync(StreamingRequest message, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (!_sender.IsConnected || !_receiver.IsConnected)
            {
                throw new InvalidOperationException("The client is not connected.");
            }

            LastMessageSendTime = DateTime.UtcNow;
            return(_protocolAdapter.SendRequestAsync(message, cancellationToken));
        }