public async Task should_call_expected_url_with_given_slack_key() { // given const string slackKey = "something-that-looks-like-a-slack-key"; const string channel = "channel-name"; const string text = "some-text-for-you"; var expectedResponse = new DefaultStandardResponse(); _httpTest.RespondWithJson(expectedResponse); // when await _chatClient.PostMessage(slackKey, channel, text, null); // then _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse))); _httpTest .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH)) .WithRequestUrlEncoded(new { token = slackKey, channel = channel, text = text, as_user = "******", link_names = "true" }) .Times(1); }
public void VerifyResponse(DefaultStandardResponse response) { if (!response.Ok) { throw new ResponseCommunicationException(response, $"Error occured while posting message '{response.Error}'") { SlackError = response.Error }; } }
public void should_not_throw_exception() { // given var response = new DefaultStandardResponse { Ok = true }; var verifier = new ResponseVerifier(); // when && then verifier.VerifyResponse(response); }
public void should_throw_exception_with_given_error_message_when_request_failed() { // given var response = new DefaultStandardResponse { Ok = false, Error = "I AM A ERROR-message" }; var verifier = new ResponseVerifier(); // when && then var exception = Assert.Throws <ResponseCommunicationException>(() => verifier.VerifyResponse(response)); exception.Message.ShouldBe($"Error occured while posting message '{response.Error}'"); }
public void VerifyDialogResponse(DefaultStandardResponse response) { if (!response.Ok) { if (response.Error == "validation_errors") { var validationException = new DialogValidationException(response); throw new ResponseCommunicationException(response, $"Error occured while posting dialog '{response.Error}'", validationException) { SlackError = response.Error }; } else { throw new ResponseCommunicationException(response, $"Error occured while posting dialog '{response.Error}'") { SlackError = response.Error }; } } }
public async Task should_archive_channel() { // given const string slackKey = "I-is-another-key"; const string channelName = "my-channel"; var expectedResponse = new DefaultStandardResponse() { Ok = true }; _httpTest.RespondWithJson(expectedResponse); // when await _channelClient.ArchiveChannel(slackKey, channelName); // then _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once); _httpTest .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.CHANNEL_ARCHIVE_PATH)) .WithQueryParamValue("token", slackKey) .WithQueryParamValue("channel", channelName) .Times(1); }
public async Task should_call_expected_url_with_given_slack_key() { // given const string slackKey = "something-that-looks-like-a-slack-key"; const string channel = "channel-name"; const string filePath = @"C:\test-file-name.exe"; var expectedResponse = new DefaultStandardResponse(); _httpTest.RespondWithJson(expectedResponse); // when await _fileClient.PostFile(slackKey, channel, filePath); // then _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse))); _httpTest .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlFileClient.FILE_UPLOAD_PATH)) .WithQueryParamValue("token", slackKey) .WithQueryParamValue("channels", channel) .WithVerb(HttpMethod.Post) .WithContentType("multipart/form-data") .Times(1); }
public DialogValidationException(DefaultStandardResponse dialogResponse) { DialogResponse = dialogResponse; }
public ResponseCommunicationException(DefaultStandardResponse response, string message) : base(message) { Response = response; }