public static SlackServer MockDefaultSendEphemeralMessage(this SlackServer server) { server.HttpServer.Given(Request.Create().WithPath(FlurlChatClient.SEND_EPHEMERAL_PATH)) .RespondWith(Response.Create().WithCallback(request => { var response = new MessageResponse() { Ok = true, Timestamp = SlackServerHelpers.GenerateTimestamp(), Channel = request.GetChannel(), Message = new MessageEvent() { Timestamp = SlackServerHelpers.GenerateTimestamp(), Text = request.GetText(), ThreadTimestamp = request.GetParameterValuesFromPostOrGet("thread_ts")?.FirstOrDefault(), Channel = request.GetChannel(), User = request.GetParameterValuesFromPostOrGet("user")?.FirstOrDefault(), } }; return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = response } }); })); return(server); }
public static SlackServer MockTeamInfo(this SlackServer server, string token, SlackLibrary.Connections.Models.Team team) { var givenRequest = Request.Create().WithPath(FlurlTeamClient.TEAM_INFO) .WithParam("token", token); server.HttpServer.Given(givenRequest) .RespondWith(Response.Create().WithCallback(request => { return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = new TeamInfoResponse() { Ok = true, Team = team } } }); })); return(server); }
public static SlackServer MockDefaultConversationOpen(this SlackServer server) { string GetChannelId(RequestMessage request) { var users = string.Concat(request.GetParameterValuesFromPostOrGet("users")); return($"DM{users}"); } server.HttpServer.Given(Request.Create().WithPath(FlurlConversationClient.CONVERSATION_OPEN_PATH)) .RespondWith(Response.Create().WithCallback(request => { return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = new ConversationResponse() { Ok = true, Channel = new ConversationChannel() { Id = GetChannelId(request) } } } }); })); return(server); }
public static SlackServer MockDefaultOAuthAccess(this SlackServer server, OAuthAccessResponse response) { server.HttpServer.Given(Request.Create().WithPath(FlurlAuthClient.OAUTH_ACCESS) .UsingPost(WireMock.Matchers.MatchBehaviour.AcceptOnMatch)) .RespondWith(Response.Create().WithCallback(request => { return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = response } }); })); return(server); }
public static SlackServer MockConversationList(this SlackServer server, string cursor = null, bool?excludeArchived = null, int?limit = null, string types = null, params ConversationChannel[] conversations) { var givenRequest = Request.Create().WithPath(FlurlConversationClient.CONVERSATION_LIST_PATH); if (cursor != null) { givenRequest = givenRequest.WithParam("cursor", cursor); } if (excludeArchived != null) { givenRequest = givenRequest.WithParam("exclude_archived", excludeArchived.ToString().ToLowerInvariant()); } if (limit != null) { givenRequest = givenRequest.WithParam("limit", limit.Value.ToString()); } if (types != null) { givenRequest = givenRequest.WithParam("types", types); } server.HttpServer.Given(givenRequest) .RespondWith(Response.Create().WithCallback(request => { return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = new ConversationCollectionReponse() { Ok = true, Channels = conversations } } }); })); return(server); }
public static SlackServer MockDefaultUpdateMessage(this SlackServer server) { server.HttpServer.Given(Request.Create().WithPath(FlurlChatClient.UPDATE_MESSAGE_PATH)) .RespondWith(Response.Create().WithCallback(request => { return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = new DefaultStandardResponse() { Ok = true, } } }); })); return(server); }
public static SlackServer MockUserInfo(this SlackServer server, User respondWithUser) { server.HttpServer.Given(Request.Create().WithPath(FlurlUserClient.USERS_INFO_PATH) .WithParam("user", respondWithUser.Id)) .RespondWith(Response.Create().WithCallback(request => { var response = new UserResponse() { User = respondWithUser, Ok = true, }; return(new WireMock.ResponseMessage() { StatusCode = 200, BodyData = new WireMock.Util.BodyData() { DetectedBodyType = WireMock.Util.BodyType.Json, BodyAsJson = response } }); })); return(server); }