示例#1
0
        private async Task <IHttpActionResult> ProcessWebHook(string webHookReceiver, string id)
        {
            IWebHookReceiverManager receiverManager = Configuration.DependencyResolver.GetReceiverManager();
            IWebHookReceiver        receiver        = receiverManager.GetReceiver(webHookReceiver);

            if (receiver == null)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, ReceiverResources.ReceiverController_Unknown, webHookReceiver);
                Configuration.DependencyResolver.GetLogger().Error(msg);
                return(NotFound());
            }

            try
            {
                string msg = string.Format(CultureInfo.CurrentCulture, ReceiverResources.ReceiverController_Processing, webHookReceiver);
                Configuration.DependencyResolver.GetLogger().Info(msg);
                HttpResponseMessage response = await receiver.ReceiveAsync(id, RequestContext, Request);

                return(ResponseMessage(response));
            }
            catch (HttpResponseException rex)
            {
                return(ResponseMessage(rex.Response));
            }
            catch (Exception ex)
            {
                ex = ex.GetBaseException();
                string msg = string.Format(CultureInfo.CurrentCulture, ReceiverResources.ReceiverController_Failure, webHookReceiver, ex.Message);
                Configuration.DependencyResolver.GetLogger().Error(msg, ex);
                HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
                return(ResponseMessage(response));
            }
        }
        private async Task <IHttpActionResult> ProcessWebHook(string webHookReceiver, string id)
        {
            IWebHookReceiverManager receiverManager = Configuration.DependencyResolver.GetReceiverManager();
            IWebHookReceiver        receiver        = receiverManager.GetReceiver(webHookReceiver);

            if (receiver == null)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, @"No WebHook receiver is registered with the name '{0}'.", webHookReceiver);
                Configuration.DependencyResolver.GetLogger().Error(msg);
                return(NotFound());
            }

            try
            {
                string msg = string.Format(CultureInfo.CurrentCulture, @"Processing incoming WebHook request with receiver '{0}' and id '{1}'.", webHookReceiver, id);
                Configuration.DependencyResolver.GetLogger().Info(msg);
                HttpResponseMessage response = await receiver.ReceiveAsync(id, RequestContext, Request);

                return(ResponseMessage(response));
            }
            catch (HttpResponseException rex)
            {
                return(ResponseMessage(rex.Response));
            }
            catch (Exception ex)
            {
                Exception inner = ex.GetBaseException();
                string    msg   = string.Format(CultureInfo.CurrentCulture, @"WebHook receiver '{0}' could not process WebHook due to error: {1}", webHookReceiver, inner.Message);
                Configuration.DependencyResolver.GetLogger().Error(msg, inner);
                throw;
            }
        }
        public void GetReceiverManager_ReturnsDefaultInstance_IfNoneRegistered()
        {
            // Act
            IWebHookReceiverManager actual = _resolverMock.Object.GetReceiverManager();

            // Assert
            Assert.IsType <WebHookReceiverManager>(actual);
        }
示例#4
0
 /// <summary>
 /// Resets all values for testing purposes.
 /// </summary>
 internal static void Reset()
 {
     _receiverManager = null;
     _receiverConfig  = null;
     _handlerSorter   = null;
     _receivers       = null;
     _handlers        = null;
 }
        public void GetReceiverManager_ReturnsSameInstance_IfNoneRegistered()
        {
            // Act
            IWebHookReceiverManager actual1 = _resolverMock.Object.GetReceiverManager();
            IWebHookReceiverManager actual2 = _resolverMock.Object.GetReceiverManager();

            // Assert
            Assert.Same(actual1, actual2);
        }
示例#6
0
        /// <summary>
        /// Gets an <see cref="IWebHookReceiverManager"/> implementation registered with the Dependency Injection engine
        /// or a default implementation if none is registered.
        /// </summary>
        /// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
        /// <returns>The registered <see cref="IWebHookReceiverManager"/> instance or a default implementation if none are registered.</returns>
        public static IWebHookReceiverManager GetReceiverManager(this IDependencyScope services)
        {
            IWebHookReceiverManager receiverManager = services.GetService <IWebHookReceiverManager>();

            if (receiverManager == null)
            {
                IEnumerable <IWebHookReceiver> receivers = services.GetReceivers();
                ILogger logger = services.GetLogger();
                receiverManager = ReceiverServices.GetReceiverManager(receivers, logger);
            }
            return(receiverManager);
        }
示例#7
0
        public void GetReceiverManager_ReturnsSingleInstance()
        {
            // Arrange
            ILogger logger = CommonServices.GetLogger();
            List <IWebHookReceiver> receivers = new List <IWebHookReceiver>();

            // Act
            IWebHookReceiverManager actual1 = ReceiverServices.GetReceiverManager(receivers, logger);
            IWebHookReceiverManager actual2 = ReceiverServices.GetReceiverManager(receivers, logger);

            // Assert
            Assert.Same(actual1, actual2);
        }
        public void GetReceiverManager_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock <IWebHookReceiverManager> instanceMock = new Mock <IWebHookReceiverManager>();

            _resolverMock.Setup(r => r.GetService(typeof(IWebHookReceiverManager)))
            .Returns(instanceMock.Object)
            .Verifiable();

            // Act
            IWebHookReceiverManager actual = _resolverMock.Object.GetReceiverManager();

            // Assert
            Assert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }
示例#9
0
 /// <summary>
 /// Resets all values for testing purposes.
 /// </summary>
 internal static void Reset()
 {
     _receiverManager = null;
     _receiverConfig = null;
     _handlerSorter = null;
     _receivers = null;
     _handlers = null;
 }