예제 #1
0
            public void NewImplementation(IAlternateMethodContext context)
            {
                if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
                {
                    context.Proceed();
                    return;
                }

                context.Proceed();
                var state       = (IActionInvokerStateMixin)context.Proxy;
                var timer       = context.TimerStrategy();
                var timerResult = timer.Stop(state.Offset);

                var args                 = state.Arguments;
                var actionDescriptor     = args.ActionDescriptor;
                var controllerDescriptor = args.ActionDescriptor.ControllerDescriptor;
                var actionName           = actionDescriptor.ActionName;
                var actionParams         = actionDescriptor.GetParameters().Select(p => p.ParameterType).ToArray();

                var message = new ActionInvoker.InvokeActionMethod.Message(context.ReturnValue.GetType())
                              .AsTimedMessage(timerResult)
                              .AsSourceMessage(controllerDescriptor.ControllerType, controllerDescriptor.ControllerType.GetMethod(actionName, actionParams) ?? controllerDescriptor.ControllerType.GetMethod(actionName + "Async", actionParams))
                              .AsChildActionMessage(state.Arguments.ControllerContext)
                              .AsActionMessage(state.Arguments.ControllerContext)
                              .AsMvcTimelineMessage(MvcTimelineCategory.Controller);

                context.MessageBroker.Publish(message);
            }
예제 #2
0
        public void PublishMessageWithRuntimePolicyOn(DependencyResolver.GetService sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { typeof(IController) });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny <DependencyResolver.GetService.Message>()));
        }
예제 #3
0
        public void ProceedAndPublishMessageWithRuntimePolicyOn(ModelBinder.BindProperty sut, IAlternateMethodContext context, ControllerContext controllerContext, ModelBindingContext modelBindingContext, PropertyDescriptor propertyDescriptor)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { controllerContext, modelBindingContext, propertyDescriptor });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <ModelBinder.BindProperty.Message>()));
        }
        public void ProceedPublishMessageWithRuntimePolicyOn(ModelBinder.BindModel sut, IAlternateMethodContext context, ControllerContext arg1, ModelBindingContext arg2)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1, arg2 });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny<ModelBinder.BindModel.Message>()));
        }
        public void ProceedAndPublishMessageWithRuntimePolicyOn(ModelBinder.BindProperty sut, IAlternateMethodContext context, ControllerContext controllerContext, ModelBindingContext modelBindingContext, PropertyDescriptor propertyDescriptor)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { controllerContext, modelBindingContext, propertyDescriptor });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny<ModelBinder.BindProperty.Message>()));
        }
예제 #6
0
        public void ProceedWithOffPolicy(View.Render sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.RuntimePolicyStrategy).Returns(() => RuntimePolicy.Off);

            sut.NewImplementation(context);

            context.Verify(c => c.Proceed());
            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()), Times.Never());
        } 
예제 #7
0
        public void ProceedPublishMessageWithRuntimePolicyOn(ModelBinder.BindModel sut, IAlternateMethodContext context, ControllerContext arg1, ModelBindingContext arg2)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1, arg2 });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <ModelBinder.BindModel.Message>()));
        }
        public void ProceedWithOffPolicy(View.Render sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.RuntimePolicyStrategy).Returns(() => RuntimePolicy.Off);

            sut.NewImplementation(context);

            context.Verify(c => c.Proceed());
            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()), Times.Never());
        }
        public void PublishMessageWithRuntimePolicyOn(DependencyResolver.GetService sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { typeof(IController) });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny<DependencyResolver.GetService.Message>()));
        }
        public void ProceedAndPublishMessagesWithRuntimePolicyOn(ResultExecutedContext argument, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { argument });

            var sut = new ResultFilter.OnResultExecuted();
            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny<ResultFilter.OnResultExecuted.Message>()));
        }
        public void ProceedWithTimerWithNullReturnValue(ValueProviderFactory.GetValueProvider sut, IAlternateMethodContext context, ControllerContext arg1)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(null);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny<Action>()));
            context.Verify(c => c.ReturnValue);            
        }
예제 #12
0
        public void PublishMessagesWithOnPolicy(View.Render sut, IAlternateMethodContext context, IViewCorrelationMixin mixin, ViewContext viewContext)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { viewContext, new StringWriter() });
            context.Setup(c => c.Proxy).Returns(mixin);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny<View.Render.Message>())); 
        } 
        public void PublishMessageOnGetServices(DependencyResolver.GetServices sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { typeof(string) });
            context.Setup(c => c.ReturnValue).Returns(Enumerable.Empty<object>());

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny<DependencyResolver.GetServices.Message>()));
        }
        public void PublishMessageOnGetServices(DependencyResolver.GetServices sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { typeof(string) });
            context.Setup(c => c.ReturnValue).Returns(Enumerable.Empty <object>());

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny <DependencyResolver.GetServices.Message>()));
        }
        public void ProceedWithTimerWithNullReturnValue(ValueProviderFactory.GetValueProvider sut, IAlternateMethodContext context, ControllerContext arg1)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(null);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny <Action>()));
            context.Verify(c => c.ReturnValue);
        }
        public void ProceedAndPublishMessageWithRuntimePolicyOn(ValueProvider <T> .ContainsPrefix sut, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { "any sting" });
            context.Setup(c => c.ReturnValue).Returns(true);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <ValueProvider <T> .ContainsPrefix.Message>()));
        }
예제 #17
0
        public void PublishMessagesWithOnPolicy(View.Render sut, IAlternateMethodContext context, IViewCorrelationMixin mixin, ViewContext viewContext)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { viewContext, new StringWriter() });
            context.Setup(c => c.Proxy).Returns(mixin);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny <View.Render.Message>()));
        }
        public void ProceedAndPublishMessagesWithRuntimePolicyOn(IAlternateMethodContext context, AuthorizationContext argument)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { argument });

            var sut = new AuthorizationFilter.OnAuthorization();
            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny<AuthorizationFilter.OnAuthorization.Message>()));
        }
        public void ProceedAndPublishMessagesWithRuntimePolicyOn(IAlternateMethodContext context, ExceptionContext argument)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { argument });

            var sut = new ExceptionFilter.OnException();

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <ExceptionFilter.OnException.Message>()));
        }
        public void ProceedAndPublishMessageWithRuntimePolicyOn(ValueProvider <T> .GetValue sut, IAlternateMethodContext context, string arg1, bool arg2, ValueProviderResult returnValue, Type targetType)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1, arg2 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);
            context.Setup(c => c.TargetType).Returns(targetType);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <ValueProvider <T> .GetValue.Message>()));
        }
        public void ProceedAndWarnWithRuntimePolicyOnAndIModelBinder(AlternateType<IModelBinder> alternateModelBinder, IAlternateMethodContext context, Type arg1, IModelBinder returnValue)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);

            var sut = new ModelBinderProvider.GetBinder(alternateModelBinder);
            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.Verify(mb => mb.ReturnValue);
        }
예제 #22
0
        public void ProceedAndPublishMessageWithRuntimePolicyOn(ResultExecutingContext argument, IAlternateMethodContext context)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { argument });

            var sut = new ResultFilter.OnResultExecuting();

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <ResultFilter.OnResultExecuting.Message>()));
        }
예제 #23
0
        public void ProceedAndWarnWithRuntimePolicyOnAndIModelBinder(AlternateType <IModelBinder> alternateModelBinder, IAlternateMethodContext context, Type arg1, IModelBinder returnValue)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);

            var sut = new ModelBinderProvider.GetBinder(alternateModelBinder);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.Verify(mb => mb.ReturnValue);
        }
        public void ProceedWithTimerWithIValueProviderReturnValue([Frozen] IProxyFactory proxyFactory, ValueProviderFactory.GetValueProvider sut, IAlternateMethodContext context, ControllerContext arg1, IValueProvider returnValue)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);
            proxyFactory.Setup(pf => pf.IsWrapInterfaceEligible <IValueProvider>(typeof(IValueProvider))).Returns(true);
            proxyFactory.Setup(pf => pf.WrapInterface(It.IsAny <IValueProvider>(), It.IsAny <IEnumerable <IAlternateMethod> >())).Returns(returnValue);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny <Action>()));
            context.Verify(c => c.ReturnValue);
            context.VerifySet(c => c.ReturnValue = It.IsAny <IValueProvider>());
        }
        public void ProceedWithTimerWithIValueProviderReturnValue([Frozen] IProxyFactory proxyFactory, ValueProviderFactory.GetValueProvider sut, IAlternateMethodContext context, ControllerContext arg1, IValueProvider returnValue)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);
            proxyFactory.Setup(pf => pf.IsWrapInterfaceEligible<IValueProvider>(typeof(IValueProvider))).Returns(true);
            proxyFactory.Setup(pf => pf.WrapInterface(It.IsAny<IValueProvider>(), It.IsAny<IEnumerable<IAlternateMethod>>())).Returns(returnValue);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(c => c.Time(It.IsAny<Action>()));
            context.Verify(c => c.ReturnValue);
            context.VerifySet(c => c.ReturnValue = It.IsAny<IValueProvider>());
        }
예제 #26
0
        /// <summary>
        /// Calls <c>Proceed</c> on the original implementation, if the current <c>RuntimePolicy</c> is not <c>Off</c>, and provides a corresponding <see cref="TimerResult"/>.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="timerResult">The timer result.</param>
        /// <returns>
        /// Returns <c>true</c> if <c>Proceed</c> was called on the original object, and sets <paramref name="timerResult" />. Returns <c>false</c> and sets <paramref name="timerResult" /> to <c>null</c> if <c>RuntimePolicy</c> is <c>Off</c>.
        /// </returns>
        public static bool TryProceedWithTimer(this IAlternateMethodContext context, out TimerResult timerResult)
        {
            if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
            {
                context.Proceed();
                timerResult = null;
                return(false);
            }

            var timer = context.TimerStrategy();

            timerResult = timer.Time(context.Proceed);
            return(true);
        }
        public void ProceedAndWrapResultWithRuntimePolicyOnAndDefaultModelBinder(AlternateType<IModelBinder> alternateModelBinder, IAlternateMethodContext context, Type arg1, DefaultModelBinder returnValue, IModelBinder newModelBinder)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);
            alternateModelBinder.Setup(amb => amb.TryCreate(It.IsAny<IModelBinder>(), out newModelBinder, null, null)).Returns(true);

            var sut = new ModelBinderProvider.GetBinder(alternateModelBinder);
            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.Verify(mb => mb.ReturnValue);
            context.Logger.Verify(l => l.Warn(It.IsAny<string>(), context.ReturnValue.GetType()), Times.Never());
            context.VerifySet(c => c.ReturnValue = newModelBinder);
            alternateModelBinder.Verify(amb => amb.TryCreate(It.IsAny<IModelBinder>(), out newModelBinder, null, null));
        }
예제 #28
0
            public void NewImplementation(IAlternateMethodContext context)
            {
                // BeginInvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<string, object> parameters, AsyncCallback callback, object state)
                if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
                {
                    context.Proceed();
                    return;
                }

                var state = (IActionInvokerStateMixin)context.Proxy;
                var timer = context.TimerStrategy();

                state.Arguments = new ActionInvoker.InvokeActionMethod.Arguments(context.Arguments);
                state.Offset    = timer.Start();
                context.Proceed();
            }
예제 #29
0
        public void ProceedAndWrapResultWithRuntimePolicyOnAndDefaultModelBinder(AlternateType <IModelBinder> alternateModelBinder, IAlternateMethodContext context, Type arg1, DefaultModelBinder returnValue, IModelBinder newModelBinder)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { arg1 });
            context.Setup(c => c.ReturnValue).Returns(returnValue);
            alternateModelBinder.Setup(amb => amb.TryCreate(It.IsAny <IModelBinder>(), out newModelBinder, null, null)).Returns(true);

            var sut = new ModelBinderProvider.GetBinder(alternateModelBinder);

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.Verify(mb => mb.ReturnValue);
            context.Logger.Verify(l => l.Warn(It.IsAny <string>(), context.ReturnValue.GetType()), Times.Never());
            context.VerifySet(c => c.ReturnValue = newModelBinder);
            alternateModelBinder.Verify(amb => amb.TryCreate(It.IsAny <IModelBinder>(), out newModelBinder, null, null));
        }
        public void PublishMessageWithRuntimePolicyOn(ActionInvoker.InvokeActionMethod sut, IAlternateMethodContext context)
        {
            var actionDescriptorMock = new Mock<ActionDescriptor>();
            actionDescriptorMock.Setup(a => a.ControllerDescriptor).Returns(new ReflectedControllerDescriptor(typeof(DummyController)));
            actionDescriptorMock.Setup(a => a.ActionName).Returns("Index");

            context.Setup(c => c.ReturnValue).Returns(new ContentResult());
            context.Setup(c => c.Arguments).Returns(new object[]
                                                            {
                                                                new ControllerContext(),
                                                                actionDescriptorMock.Object,
                                                                new Dictionary<string, object>()
                                                            });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny<Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny<ActionInvoker.InvokeActionMethod.Message>()));
        } 
예제 #31
0
        public void PublishMessageWithRuntimePolicyOn(ActionInvoker.InvokeActionMethod sut, IAlternateMethodContext context)
        {
            var actionDescriptorMock = new Mock <ActionDescriptor>();

            actionDescriptorMock.Setup(a => a.ControllerDescriptor).Returns(new ReflectedControllerDescriptor(typeof(DummyController)));
            actionDescriptorMock.Setup(a => a.ActionName).Returns("Index");

            context.Setup(c => c.ReturnValue).Returns(new ContentResult());
            context.Setup(c => c.Arguments).Returns(new object[]
            {
                new ControllerContext(),
                actionDescriptorMock.Object,
                new Dictionary <string, object>()
            });

            sut.NewImplementation(context);

            context.TimerStrategy().Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(b => b.Publish(It.IsAny <ActionInvoker.InvokeActionMethod.Message>()));
        }