public override void OnSuccess(MethodResult <RocketMessage> result, IMessageResponse response) { if (wasTaskListResponse && response is TasklistMessageResponse tlmr) { cache.LastTaskListMessageIds[tlmr.GetUser().ID] = (result.Result.Id, result.Result.RoomId, response); } }
public async Task Should_be_passed_through_in_the_response() { // Act IMessageResponse response = await Sut.GetDriveStateAsync(_vehicleId).ConfigureAwait(false); // Assert response.RawJsonAsString.Should().Be(_expected.ToString(Formatting.None)); }
public async Task Should_return_the_error_status_code() { // Act IMessageResponse actual = await Sut.GetDriveStateAsync(_vehicleId, AccessToken).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.BadGateway); }
public async Task It_should_return_just_the_HTTP_status_Code() { // Act IMessageResponse actual = await Sut.GetVehicleStateAsync(_vehicleId, AccessToken).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(_statusCode); }
public async Task Should_return_the_error_status_code() { // Act IMessageResponse actual = await Sut.RevokeAccessTokenAsync(_accessToken).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.Unauthorized); }
public async Task Should_return_the_expected_response() { // Act IMessageResponse actual = await Sut.RevokeAccessTokenAsync(_accessToken).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.OK); actual.RawJsonAsString.Should().Be("{}"); }
public async Task Should_return_the_error_status_code() { // Act IMessageResponse actual = await Sut.RequestAccessTokenAsync(_clientId, _clientSecret, _email, _password).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.Unauthorized); }
public async Task Should_be_passed_through_in_the_response() { // Act IMessageResponse response = await Sut.RefreshAccessTokenAsync(_clientId, _clientSecret, _refreshToken).ConfigureAwait(false); // Assert response.RawJsonAsString.Should().Be(_expected.ToString(Formatting.None)); }
public async Task Should_be_passed_through_in_the_response() { // Act IMessageResponse <IResponseDataWrapper <IVehicleState> > response = await Sut.GetVehicleStateAsync(_vehicleId).ConfigureAwait(false); response.Data.Response.SunRoofPercentOpen.Should().Be(null); // Assert response.RawJsonAsString.Should().Be(_expected.ToString(Formatting.None)); }
public async Task Should_return_the_expected_drive_state() { // Act IMessageResponse <IResponseDataWrapper <IDriveState> > actual = await Sut.GetDriveStateAsync(_vehicleId, AccessToken).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.OK); actual.Data.Should().BeEquivalentTo(_expected, WithStrictOrdering); }
public async Task Should_return_the_expected_access_token() { // Act IMessageResponse <IAccessTokenResponse> actual = await Sut.RequestAccessTokenAsync(_clientId, _clientSecret, _email, _password).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.OK); actual.Data.ShouldBeEquivalentTo(_expected, WithStrictOrdering); }
public async Task Should_return_the_expected_vehicles() { // Act IMessageResponse <IResponseDataWrapper <IReadOnlyList <IVehicle> > > actual = await Sut.GetVehiclesAsync(AccessToken).ConfigureAwait(false); // Assert actual.HttpStatusCode.Should().Be(HttpStatusCode.OK); actual.Data.ShouldBeEquivalentTo(_expected, WithStrictOrdering); }
private void MessageBroker_OnResponse(IRequestMessage message, IMessageResponse response) { var payload = message.GetPayload <Payload>(); Assert.IsNotNull(response); Assert.IsNotNull(response.Content); var content = (Payload)response.Content; Assert.AreEqual(payload.x * 10, content.x); Assert.AreEqual(payload.y * 100, content.y); }
public IMessageResponse UpdateMessage(IMessageResponse taskListResponse) { if (!(taskListResponse is TasklistMessageResponse response)) { throw new ArgumentException("Response has to be of type TasklistMessageResponse", nameof(taskListResponse)); } var newTaskList = response.GetTasks().Select(x => context.Tasks.FirstOrDefault(t => t.ID == x.ID)); return(new TasklistMessageResponse(response.GetTitle(), response.ResponseUrl, response.GetUser(), newTaskList)); }
/// <summary> /// Gets a value that indicates if the <paramref name="messageResponse"/> was successful. /// </summary> /// <param name="messageResponse">A <see cref="IMessageResponse"/>.</param> /// <returns> /// <see langword="true" /> if <see cref="IMessageResponse.HttpStatusCode" /> was in the range 200-299; /// otherwise <see langword="false" />. /// </returns> public static bool IsSuccessStatusCode(this IMessageResponse messageResponse) { if (messageResponse == null) { throw new ArgumentNullException(nameof(messageResponse)); } int statusCode = (int)messageResponse.HttpStatusCode; bool successStatusCode = statusCode >= 200 && statusCode <= 299; return(successStatusCode); }
private void _conn_OnTunnelResponse(IMessageResponse response) { if (responses.ContainsKey(response.SequenceNumber)) { responses[response.SequenceNumber] = response; } else { responses.Add(response.SequenceNumber, response); } lastReceivedNumber = response.SequenceNumber; }
protected async Task <MethodResult <RocketMessage> > SendMessageAsync(IMessageResponse response) { if (response is AttachmentResponse attachmentMessage) { return(await Driver.SendCustomMessageAsync(attachmentMessage.Attachment, attachmentMessage.RoomId).ConfigureAwait(false)); } else if (response is BasicResponse basic) { return(await Driver.SendMessageAsync(basic.Message, basic.RoomId).ConfigureAwait(false)); } else { throw new InvalidOperationException( $"The result of {nameof(IBotResponse.GetResponse)} is either null or not of a supported type."); } }
override protected async Task ProcessRequest(string subscriptionId, List <Newtonsoft.Json.Linq.JObject> fields) { using (IServiceScope scope = provider.CreateScope()) { try { var response = (IResponse)scope.ServiceProvider.GetService(subscriptions[subscriptionId].ResponseType); IMessageResponse message = response.RespondTo(fields); var result = await SendMessageAsync(message); response.OnSuccess(result, message); } catch (Exception ex) { logger.LogError(ex, "An error occurred when processing request {subid} with payload {args}", subscriptionId, fields); } } }
private IMessageResponse RespondToDirectMessage(NotifyUserMessageArgument input) { IMessageResponse response = null; if (input.Payload.Message.Msg.TrimStart().ToUpper().StartsWith("TASKLIST")) { response = RespondToTaskList(input); } else if (input.Payload.Message.Msg.TrimStart().ToUpper().StartsWith("SET TASK")) { response = RespondToSetTaskDone(input); } if (response != null) { response.RoomId = response.RoomId ?? input.Payload.RoomId; return(response); } return(new BasicResponse("Sorry, I did not understand your request. I understand the following actions:\n* **tasklist**: Display all tasks assigned to you\n* Set Task <taskId> to <open/done>: Set a specific task to open or done", input.Payload.RoomId)); }
private async Task SendMessageAsync(IMessageResponse response) { var attachmentMessage = response as AttachmentResponse; var basicMessage = response as BasicResponse; if (attachmentMessage != null) { await Driver.SendCustomMessageAsync(attachmentMessage.Attachment, attachmentMessage.RoomId).ConfigureAwait(false); } else if (basicMessage != null) { await Driver.SendMessageAsync(basicMessage.Message, basicMessage.RoomId).ConfigureAwait(false); } else { throw new InvalidOperationException( $"The result of {nameof(IBotResponse.GetResponse)} is either null or not of a supported type."); } }
/// <summary> /// Reads the JSON from the <paramref name="responseTask"/> and deserializes it to the type /// <typeparamref name="TResult"/>. /// </summary> /// <typeparam name="TResult">The <see cref="Type"/> of the result object.</typeparam> /// <typeparam name="TModel">The <see cref="Type"/> of the object to deserialize.</typeparam> /// <param name="responseTask"> /// The asynchronous <see cref="Task{T}"/> of a <see cref="HttpResponseMessage"/>. /// </param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for a task to /// complete.</param> /// <returns>The deserialized object of type <typeparamref name="TResult"/>.</returns> private static async Task <IMessageResponse <TResult> > ReadJsonAsAsync <TResult, TModel>( this Task <HttpResponseMessage> responseTask, CancellationToken cancellationToken) where TResult : class where TModel : class, TResult { HttpResponseMessage responseMessage = await responseTask.ConfigureAwait(false); using (responseMessage) { Task <IMessageResponse <TModel> > messageTask = responseMessage.IsSuccessStatusCode ? responseMessage.ReadSuccessResponseAsync <TModel>(cancellationToken) : responseMessage.ReadFailureResponseAsync <TModel>(cancellationToken); IMessageResponse <TModel> response = await messageTask.ConfigureAwait(false); return(response); } }
public async Task SendTextAsync(string socketId, IMessageResponse messageResponse) { await SendAsync(socketId, SerializeToText(messageResponse)); }
public VisitorService(ISignalRService signalRService, IHttpService Http, IMessageResponse ResponseManager) { this.signalRService = signalRService; this.Http = Http; this.ResponseManager = ResponseManager; }
public MessageResponseWrapper(IMessageResponse response) => _response = response;
public async Task ProcessResponseAsync(IMessageResponse messageResponse) => await ProcessResponse((TMessageResponse)messageResponse);
public Task SayHello(IMessageRequest req, IMessageResponse resp) { return(resp.SendAsync(new { msg = "hello , meow ~~!" })); }
[POST("meow")] //按照约定,GET和POST的一大区别是:使用POST方法时,客户端会在消息中携带参数。 public Task SayMeow(IMessageRequest req, IMessageResponse resp) { return(resp.SendTextAsync(" meow~! meow~! " + req.GetTextMessage())); }
public virtual void OnSuccess(MethodResult <RocketMessage> result, IMessageResponse response) { }
public async Task SendBinaryAsync(string socketId, IMessageResponse messageResponse) { await SendAsync(socketId, SerializeToBinary(messageResponse)); }
public DataStoreResponse(Header header, IMessageResponse body) { this.Header = header; this.Body = body; }