public async Task VerifyWebHookAsync_Succeeds_EchoResponse() { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => { NameValueCollection query = req.RequestUri.ParseQueryString(); _response.Content = new StringContent(query["echo"]); return(Task.FromResult(_response)); }; WebHook webHook = CreateWebHook(); // Act await _manager.VerifyWebHookAsync(webHook); }
public async Task VerifyWebHookAsync_Stops_IfNoEchoParameter(string query) { // Arrange bool error = false; _response.Content = new StringContent("Hello World"); _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => { error = true; return(Task.FromResult(_response)); }; WebHook webHook = CreateWebHook(); webHook.WebHookUri = new Uri("http://localhost/hook?" + query); // Act await _manager.VerifyWebHookAsync(webHook); // Assert Assert.False(error); }
public async Task VerifyWebHookAsync_Throws_IfNotHttpOrHttpsUri(string webHookUri) { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); WebHook webHook = CreateWebHook(); webHook.WebHookUri = new Uri(webHookUri); // Act InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal(string.Format(CultureInfo.InvariantCulture, "The WebHook URI must be absolute with a scheme of either 'http' or 'https' but received '{0}'.", webHook.WebHookUri), ex.Message); }
public async Task VerifyWebHookAsync_Succeeds_EchoResponse() { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => { NameValueCollection query = req.RequestUri.ParseQueryString(); _response.Content = new StringContent(query["echo"]); return Task.FromResult(_response); }; WebHook webHook = CreateWebHook(); // Act await _manager.VerifyWebHookAsync(webHook); }
public async Task VerifyWebHookAsync_Throws_IfEchoDoesNotMatch() { // Arrange _response.Content = new StringContent("Hello World"); _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => Task.FromResult(_response); WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("The HTTP request echo query parameter was not returned as plain text in the response. Please return the echo parameter to verify that the WebHook is working as expected.", ex.Message); }
public async Task VerifyWebHookAsync_Throws_INotSuccessResponse() { // Arrange _response.StatusCode = HttpStatusCode.NotFound; _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => Task.FromResult(_response); WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("WebHook verification failed. Please ensure that the WebHook URI is valid and that the endpoint is accessible. Error encountered: NotFound", ex.Message); }
public async Task VerifyWebHookAsync_Throws_IEmptySuccessResponse() { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => Task.FromResult(_response); WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("The WebHook URI did not return the expected echo query parameter value in a plain text response body. This is necessary to ensure that the WebHook is connected correctly.", ex.Message); }
public async Task VerifyWebHookAsync_Throws_IfHttpClientThrows() { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => { throw new Exception("Catch this!"); }; WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("WebHook verification failed. Please ensure that the WebHook URI is valid and that the endpoint is accessible. Error encountered: Catch this!", ex.Message); }
public async Task VerifyWebHookAsync_Throws_IfEchoDoesNotMatch() { // Arrange _response.Content = new StringContent("Hello World"); _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => Task.FromResult(_response); WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("The HTTP request echo query parameter was not returned as plain text in the response. Please return the echo parameter to verify that the WebHook is working as expected.", ex.Message); }
public async Task VerifyWebHookAsync_Throws_IEmptySuccessResponse() { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => Task.FromResult(_response); WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("The WebHook URI did not return the expected echo query parameter value in a plain text response body. This is necessary to ensure that the WebHook is connected correctly.", ex.Message); }
public async Task VerifyWebHookAsync_Throws_INotSuccessResponse() { // Arrange _response.StatusCode = HttpStatusCode.NotFound; _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => Task.FromResult(_response); WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("WebHook verification failed. Please ensure that the WebHook URI is valid and that the endpoint is accessible. Error encountered: NotFound", ex.Message); }
public async Task VerifyWebHookAsync_Throws_IfHttpClientThrows() { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => { throw new Exception("Catch this!"); }; WebHook webHook = CreateWebHook(); // Act InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("WebHook verification failed. Please ensure that the WebHook URI is valid and that the endpoint is accessible. Error encountered: Catch this!", ex.Message); }
public async Task VerifyWebHookAsync_Throws_IfNotHttpOrHttpsUri(string webHookUri) { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); WebHook webHook = CreateWebHook(); webHook.WebHookUri = webHookUri != null ? new Uri(webHookUri) : null; // Act InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal(string.Format(CultureInfo.InvariantCulture, "The WebHook URI must be absolute with a scheme of either 'http' or 'https' but received '{0}'.", webHook.WebHookUri), ex.Message); }
public async Task VerifyWebHookAsync_Throws_IfInvalidWebHookSecret(string secret) { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); WebHook webHook = CreateWebHook(); webHook.Secret = secret; // Act InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("The WebHook secret key parameter must be between 32 and 64 characters long.", ex.Message); }
public async Task VerifyWebHookAsync_Stops_IfNoEchoParameter(string query) { // Arrange bool error = false; _response.Content = new StringContent("Hello World"); _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); _handlerMock.Handler = (req, counter) => { error = true; return Task.FromResult(_response); }; WebHook webHook = CreateWebHook(); webHook.WebHookUri = new Uri("http://localhost/hook?" + query); // Act await _manager.VerifyWebHookAsync(webHook); // Assert Assert.False(error); }
public async Task VerifyWebHookAsync_Throws_IfInvalidWebHookSecret(string secret) { // Arrange _manager = new WebHookManager(_storeMock.Object, _senderMock.Object, _loggerMock.Object, _httpClient); WebHook webHook = CreateWebHook(); webHook.Secret = secret; // Act InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => _manager.VerifyWebHookAsync(webHook)); // Assert Assert.Equal("The WebHook secret key parameter must be between 32 and 64 characters long.", ex.Message); }