public void Initialize(string name, string id, string config, params KeyValuePair <Type, object>[] dependencies)
        {
            _httpConfig = new HttpConfiguration();

            _logger   = new Mock <ILogger>().Object;
            _settings = new SettingsDictionary();
            _settings[SecretPrefix + name] = GetConfigValue(id, config);

            _config = new WebHookReceiverConfig(_settings, _logger);

            List <KeyValuePair <Type, object> > deps = new List <KeyValuePair <Type, object> >()
            {
                new KeyValuePair <Type, object>(typeof(IWebHookReceiverConfig), _config),
                new KeyValuePair <Type, object>(typeof(SettingsDictionary), _settings)
            };

            deps.AddRange(dependencies);

            _httpConfig = HttpConfigurationMock.Create(deps);

            _request      = new HttpRequestMessage();
            _receiverMock = new WebHookReceiverMock();

            _context = new HttpRequestContext {
                Configuration = _httpConfig
            };
            _request.SetRequestContext(_context);
        }
Exemple #2
0
        private async Task Action_Handles_ReceiverException(Func <string, Task <IHttpActionResult> > action)
        {
            // Arrange
            Exception           exception = new Exception("Catch this!");
            WebHookReceiverMock receiver  = new WebHookReceiverMock(exception);

            _managerMock.Setup(m => m.GetReceiver(TestReceiver))
            .Returns(receiver)
            .Verifiable();

            // Act
            Exception actual = await Assert.ThrowsAsync <Exception>(() => action(TestReceiver));

            // Assert
            _managerMock.Verify();
            Assert.Equal("Catch this!", actual.Message);
        }
Exemple #3
0
        public async Task Get_Handles_ReceiverException()
        {
            // Arrange
            Exception           exception = new Exception("Catch this!");
            WebHookReceiverMock receiver  = new WebHookReceiverMock(exception);

            _managerMock.Setup(m => m.GetReceiver(TestReceiver))
            .Returns(receiver)
            .Verifiable();

            // Act
            IHttpActionResult result = await _controller.Get(TestReceiver);

            HttpResponseMessage response = ((ResponseMessageResult)result).Response;
            HttpError           error    = await response.Content.ReadAsAsync <HttpError>();

            // Assert
            _managerMock.Verify();
            Assert.Equal("WebHook receiver 'TestReceiver' could not process WebHook due to error: Catch this!", error.Message);
        }
Exemple #4
0
        public async Task Post_Handles_ReceiverHttpResponseException()
        {
            // Arrange
            HttpResponseMessage   response  = new HttpResponseMessage();
            HttpResponseException exception = new HttpResponseException(response);
            WebHookReceiverMock   receiver  = new WebHookReceiverMock(exception);

            _managerMock.Setup(m => m.GetReceiver(TestReceiver))
            .Returns(receiver)
            .Verifiable();

            // Act
            IHttpActionResult result = await _controller.Post(TestReceiver);

            HttpResponseMessage actual = ((ResponseMessageResult)result).Response;

            // Assert
            _managerMock.Verify();
            Assert.Same(response, actual);
        }
Exemple #5
0
        private async Task Action_Handles_ReceiverHttpResponseException(Func <string, Task <IHttpActionResult> > action)
        {
            // Arrange
            HttpResponseMessage   expected  = new HttpResponseMessage();
            HttpResponseException exception = new HttpResponseException(expected);
            WebHookReceiverMock   receiver  = new WebHookReceiverMock(exception);

            _managerMock.Setup(m => m.GetReceiver(TestReceiver))
            .Returns(receiver)
            .Verifiable();

            // Act
            IHttpActionResult result = await action(TestReceiver);

            HttpResponseMessage actual = ((ResponseMessageResult)result).Response;

            // Assert
            _managerMock.Verify();
            Assert.Same(expected, actual);
        }
Exemple #6
0
        public async Task Get_Returns_ReceiverResponse()
        {
            // Arrange
            HttpResponseMessage response = new HttpResponseMessage()
            {
                ReasonPhrase = "From Receiver!"
            };
            WebHookReceiverMock receiver = new WebHookReceiverMock(response);

            _managerMock.Setup(m => m.GetReceiver(TestReceiver))
            .Returns(receiver)
            .Verifiable();

            // Act
            IHttpActionResult result = await _controller.Get(TestReceiver);

            HttpResponseMessage actual = ((ResponseMessageResult)result).Response;

            // Assert
            _managerMock.Verify();
            Assert.Equal("From Receiver!", actual.ReasonPhrase);
        }
Exemple #7
0
        private async Task Action_Returns_ReceiverResponse(Func <string, Task <IHttpActionResult> > action)
        {
            // Arrange
            HttpResponseMessage response = new HttpResponseMessage()
            {
                ReasonPhrase = "From Receiver!"
            };
            WebHookReceiverMock receiver = new WebHookReceiverMock(response);

            _managerMock.Setup(m => m.GetReceiver(TestReceiver))
            .Returns(receiver)
            .Verifiable();

            // Act
            IHttpActionResult result = await action(TestReceiver);

            HttpResponseMessage actual = ((ResponseMessageResult)result).Response;

            // Assert
            _managerMock.Verify();
            Assert.Equal("From Receiver!", actual.ReasonPhrase);
        }