private void SetupModelBinders(IInspectorContext context) { var alternateModelBinder = new ModelBinder(context.ProxyFactory); var binders = ModelBinders.Binders; var keys = binders.Keys.ToArray(); for (int i = 0; i < keys.Length; i++) { var type = keys[i]; var originalBinder = binders[type]; IModelBinder newBinder; if (alternateModelBinder.TryCreate(originalBinder, out newBinder)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinder, originalBinder.GetType()); binders[type] = newBinder; } } // handle default binder var originalDefaultBinder = ModelBinders.Binders.DefaultBinder as DefaultModelBinder; IModelBinder newDefaultBinder; if (originalDefaultBinder != null && alternateModelBinder.TryCreate(originalDefaultBinder, out newDefaultBinder)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinder, originalDefaultBinder.GetType()); ModelBinders.Binders.DefaultBinder = newDefaultBinder; } }
internal ConnectionLifetimeTimeline(IInspectorContext context, DbConnection connection, Guid connectionId) : base(context) { _connection = connection; ConnectionId = connectionId; }
public void Setup(IInspectorContext context) { if (context.RuntimePolicyStrategy() == RuntimePolicy.Off) return; _profiler.Start(); }
public void Setup(IInspectorContext context) { _target = new GlimpseTarget(context.MessageBroker, context.TimerStrategy) {Name = "glimpse"}; LogManager.ConfigurationReloaded += LogManagerOnConfigurationReloaded; AttachLogTarget(); }
internal CommandTimeline(IInspectorContext context, DbCommand command, Guid connectionId, Guid?transactionId) : base(context) { _command = command; _connetionId = connectionId; _transactionId = transactionId; }
internal ConnectionEventTimeline(IInspectorContext context, DbConnection connection, Guid connectionId, ConnectionEvent connectionEvent) : base(context) { _connection = connection; _connectionId = connectionId; _connectionEvent = connectionEvent; }
internal CommandTimeline(IInspectorContext context, DbCommand command, Guid connectionId, Guid? transactionId) : base(context) { _command = command; _connetionId = connectionId; _transactionId = transactionId; }
public void Setup(IInspectorContext context) { StateRouteHandler alternateBaseImplementation = new StateRouteHandler(context.ProxyFactory); RouteCollection currentRoutes = RouteTable.Routes; Navigation.StateRouteHandler originalHandler = null; Route stateRoute; using (currentRoutes.GetWriteLock()) { foreach (RouteBase route in currentRoutes) { stateRoute = route as Route; if (stateRoute != null) { originalHandler = stateRoute.RouteHandler as Navigation.StateRouteHandler; if (originalHandler != null) { Navigation.StateRouteHandler newHandler = null; alternateBaseImplementation.TryCreate(originalHandler, out newHandler, null, new object[] { originalHandler.State }); stateRoute.RouteHandler = newHandler; context.Logger.Info(Resources.RouteSetupReplacedRouteHandler, stateRoute.Url); } } } } }
public void IntergrationTestRouteProxing(RoutesInspector sut, System.Web.Routing.IRouteHandler routeHandler, IInspectorContext context) { RouteTable.Routes.Clear(); RouteTable.Routes.Add("Test", new System.Web.Routing.Route("Test", routeHandler)); RouteTable.Routes.Add("BaseTyped", new NewRouteBase()); RouteTable.Routes.Add("BaseTestTyped", new NewConstructorRouteBase("Name")); RouteTable.Routes.Add("SubTyped", new NewRoute("test", routeHandler)); RouteTable.Routes.Add("SubTestTyped", new NewConstructorRoute("test", routeHandler, "Name")); RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}", new { resource = "Test", pathInfo = "[0-9]" }); context.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(context.Logger, context.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy())); sut.Setup(context); // This test needs to be like this because IProxyTargetAccessor is in Moq and Glimpse foreach (var route in RouteTable.Routes) { var found = false; foreach (var routeInterface in route.GetType().GetInterfaces()) { if (routeInterface.Name == "IProxyTargetAccessor") { found = true; } } Assert.True(found); } }
internal TransactionEventTimeline(IInspectorContext context, DbConnection connection, Guid connectionId, Guid transactionId, TransactionEvent transactionEvent) : base(context) { _connection = connection; _connectionId = connectionId; _transactionId = transactionId; _transactionEvent = transactionEvent; }
/// <summary> /// Setups the specified context. /// </summary> /// <param name="context">The context.</param> /// <remarks> /// Executed during the <see cref="Glimpse.Core.Framework.IGlimpseRuntime.Initialize" /> phase of /// system startup. Specifically, with the ASP.NET provider, this is wired to/implemented by the /// <c>System.Web.IHttpModule.Init</c> method. /// </remarks> public void Setup(IInspectorContext context) { var traceListeners = System.Diagnostics.Trace.Listeners; if (!traceListeners.OfType<TraceListener>().Any()) { traceListeners.Add(new TraceListener(context.MessageBroker, context.TimerStrategy)); } }
internal TransactionLifetimeTimeline(IInspectorContext context, DbConnection connection, Guid connectionId) : base(context) { _connection = connection; _connetionId = connectionId; TransactionId = Guid.NewGuid(); }
public void ContinueIfUnableToProxyControllerFactory(ExecutionInspector sut, IInspectorContext context) { context.ProxyFactory.Setup(f => f.IsWrapClassEligible(It.IsAny<Type>())).Returns(false); sut.Setup(context); Assert.IsType<DefaultControllerFactory>(ControllerBuilder.Current.GetControllerFactory()); }
public void ContinueIfUnableToProxyControllerFactory(ExecutionInspector sut, IInspectorContext context) { context.ProxyFactory.Setup(f => f.IsWrapClassEligible(It.IsAny <Type>())).Returns(false); sut.Setup(context); Assert.IsType <DefaultControllerFactory>(ControllerBuilder.Current.GetControllerFactory()); }
public void Setup(ViewEngineInspector sut, IInspectorContext context, IViewEngine viewEngine) { context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible<IViewEngine>(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny<IViewEngine>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>())).Returns(viewEngine); sut.Setup(context); context.ProxyFactory.Verify(pf => pf.WrapInterface(It.IsAny<IViewEngine>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>()), Times.AtLeastOnce()); }
public void Setup(IInspectorContext context) { if (context == null) { return; } _runtime = context.RuntimePolicyStrategy; _messageBroker = context.MessageBroker; }
/// <summary> /// Setups the specified context. /// </summary> /// <param name="context">The context.</param> /// <remarks> /// Executed during the <see cref="Glimpse.Core.Framework.IGlimpseRuntime.Initialize" /> phase of /// system startup. Specifically, with the ASP.NET provider, this is wired to/implemented by the /// <c>System.Web.IHttpModule.Init</c> method. /// </remarks> public void Setup(IInspectorContext context) { var traceListeners = System.Diagnostics.Trace.Listeners; if (!traceListeners.OfType <TraceListener>().Any()) { traceListeners.Add(new TraceListener(context.MessageBroker, context.TimerStrategy)); } }
public void Setup(IInspectorContext context) { if (context.RuntimePolicyStrategy() == RuntimePolicy.Off) { return; } _profiler.Start(); }
public void Setup(ViewEngineInspector sut, IInspectorContext context, IViewEngine viewEngine) { context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible <IViewEngine>(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny <IViewEngine>(), It.IsAny <IEnumerable <IAlternateMethod> >(), Enumerable.Empty <object>())).Returns(viewEngine); sut.Setup(context); context.ProxyFactory.Verify(pf => pf.WrapInterface(It.IsAny <IViewEngine>(), It.IsAny <IEnumerable <IAlternateMethod> >(), Enumerable.Empty <object>()), Times.AtLeastOnce()); }
public void IgnoreEmptyModelBindingProvidersCollection(ModelBinderInspector sut, IInspectorContext context, IModelBinderProvider proxy) { ModelBinderProviders.BinderProviders.Clear(); context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible<IModelBinderProvider>(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny<IModelBinderProvider>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>())).Returns(proxy); sut.Setup(context); Assert.Empty(ModelBinderProviders.BinderProviders); }
public void IgnoreEmptyValueProviderFactoriesCollection(ModelBinderInspector sut, IInspectorContext context, ValueProviderFactory proxy) { ValueProviderFactories.Factories.Clear(); context.ProxyFactory.Setup(pf => pf.IsWrapClassEligible(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapClass(It.IsAny<ValueProviderFactory>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>(), null)).Returns(proxy); sut.Setup(context); Assert.Empty(ValueProviderFactories.Factories); }
public void ProxyControllerFactory(ExecutionInspector sut, IInspectorContext context, IControllerFactory controllerFactory) { context.ProxyFactory.Setup(f => f.IsWrapInterfaceEligible<IControllerFactory>(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(f => f.WrapInterface(It.IsAny<IControllerFactory>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>())).Returns(controllerFactory); sut.Setup(context); Assert.Equal(ControllerBuilder.Current.GetControllerFactory(), controllerFactory); context.Logger.Verify(l => l.Debug(It.Is<string>(s => s.Contains("IControllerFactory")), It.IsAny<object[]>())); }
public void UpdateDefaultModelBinder(ModelBinderInspector sut, IInspectorContext context, DefaultModelBinder proxy) { context.ProxyFactory.Setup(pf => pf.IsExtendClassEligible(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.ExtendClass <DefaultModelBinder>(It.IsAny <IEnumerable <IAlternateMethod> >())).Returns(proxy); sut.Setup(context); Assert.Equal(proxy, ModelBinders.Binders.DefaultBinder); context.Logger.Verify(l => l.Info(It.IsAny <string>(), It.IsAny <object[]>())); }
public void ProxyControllerFactory(ExecutionInspector sut, IInspectorContext context, IControllerFactory controllerFactory) { context.ProxyFactory.Setup(f => f.IsWrapInterfaceEligible <IControllerFactory>(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(f => f.WrapInterface(It.IsAny <IControllerFactory>(), It.IsAny <IEnumerable <IAlternateMethod> >(), Enumerable.Empty <object>())).Returns(controllerFactory); sut.Setup(context); Assert.Equal(ControllerBuilder.Current.GetControllerFactory(), controllerFactory); context.Logger.Verify(l => l.Debug(It.Is <string>(s => s.Contains("IControllerFactory")), It.IsAny <object[]>())); }
public void ContinueIfUnableToProxyDependencyResolver(DependencyInjectionInspector sut, IInspectorContext context, IDependencyResolver dependencyResolver) { DependencyResolver.SetResolver(dependencyResolver); context.ProxyFactory.Setup(f => f.IsWrapInterfaceEligible<IDependencyResolver>(It.IsAny<Type>())).Returns(false); sut.Setup(context); Assert.Equal(dependencyResolver, DependencyResolver.Current); }
public void UpdateModelBindingProviders(ModelBinderInspector sut, IInspectorContext context, IModelBinderProvider proxy) { ModelBinderProviders.BinderProviders.Add(new DummyModelBinderProvider()); context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible <IModelBinderProvider>(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny <IModelBinderProvider>(), It.IsAny <IEnumerable <IAlternateMethod> >(), Enumerable.Empty <object>())).Returns(proxy); sut.Setup(context); Assert.Contains(proxy, ModelBinderProviders.BinderProviders); context.Logger.Verify(l => l.Info(It.IsAny <string>(), It.IsAny <object[]>())); }
public void UpdateValueProviderFactories(ModelBinderInspector sut, IInspectorContext context, ValueProviderFactory proxy) { ValueProviderFactories.Factories.Add(new DummyValueProviderFactory()); context.ProxyFactory.Setup(pf => pf.IsWrapClassEligible(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapClass(It.IsAny <ValueProviderFactory>(), It.IsAny <IEnumerable <IAlternateMethod> >(), Enumerable.Empty <object>(), null)).Returns(proxy); sut.Setup(context); Assert.Contains(proxy, ValueProviderFactories.Factories); context.Logger.Verify(l => l.Info(It.IsAny <string>(), It.IsAny <object[]>())); }
public void Setup(IInspectorContext context) { var originalDefaultBinder = ModelBinders.Binders.DefaultBinder; IModelBinder newDefaultBinder; var alternateModelBinder = new ModelBinder(context.ProxyFactory); if (originalDefaultBinder != null && alternateModelBinder.TryCreate(originalDefaultBinder, out newDefaultBinder)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinder, originalDefaultBinder.GetType()); ModelBinders.Binders.DefaultBinder = newDefaultBinder; } }
public void Setup(IInspectorContext context) { Func<RuntimePolicy> runtimePolicyStrategy = context.RuntimePolicyStrategy; Func<IExecutionTimer> timerStrategy = context.TimerStrategy; IMessageBroker messageBroker = context.MessageBroker; // because there is no static way to access runtime policy strategy GlimpseJson.RuntimePolicyStrategy = runtimePolicyStrategy; GlimpseJson.Initialize(runtimePolicyStrategy, timerStrategy, messageBroker); }
public void UpdateModelBindingProviders(ModelBinderInspector sut, IInspectorContext context, IModelBinderProvider proxy) { ModelBinderProviders.BinderProviders.Add(new DummyModelBinderProvider()); context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible<IModelBinderProvider>(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny<IModelBinderProvider>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>())).Returns(proxy); sut.Setup(context); Assert.Contains(proxy, ModelBinderProviders.BinderProviders); context.Logger.Verify(l => l.Info(It.IsAny<string>(), It.IsAny<object[]>())); }
public void Setup(IInspectorContext context) { _messageBroker = context.MessageBroker; _timerStrategy = context.TimerStrategy; var kernal = Kernal(); kernal.ComponentCreated += ComponentCreated; kernal.ComponentDestroyed += ComponentDestroyed; kernal.DependencyResolving += DependencyResolving; }
public void Setup(IInspectorContext context) { _target = new GlimpseTarget(context.MessageBroker, context.TimerStrategy) { Name = "glimpse" }; LogManager.ConfigurationReloaded += LogManagerOnConfigurationReloaded; AttachLogTarget(); }
public void UpdateValueProviderFactories(ModelBinderInspector sut, IInspectorContext context, ValueProviderFactory proxy) { ValueProviderFactories.Factories.Add(new DummyValueProviderFactory()); context.ProxyFactory.Setup(pf => pf.IsWrapClassEligible(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapClass(It.IsAny<ValueProviderFactory>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>(), null)).Returns(proxy); sut.Setup(context); Assert.Contains(proxy, ValueProviderFactories.Factories); context.Logger.Verify(l => l.Info(It.IsAny<string>(), It.IsAny<object[]>())); }
public void Setup(IInspectorContext context) { Func <RuntimePolicy> runtimePolicyStrategy = context.RuntimePolicyStrategy; Func <IExecutionTimer> timerStrategy = context.TimerStrategy; IMessageBroker messageBroker = context.MessageBroker; // because there is no static way to access runtime policy strategy GlimpseJson.RuntimePolicyStrategy = runtimePolicyStrategy; GlimpseJson.Initialize(runtimePolicyStrategy, timerStrategy, messageBroker); }
public void ProxyDependencyResolver(DependencyInjectionInspector sut, IInspectorContext context, IDependencyResolver dependencyResolver) { DependencyResolver.SetResolver(dependencyResolver); context.ProxyFactory.Setup(f => f.IsWrapInterfaceEligible<IDependencyResolver>(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(f => f.WrapInterface(It.IsAny<IDependencyResolver>(), It.IsAny<IEnumerable<IAlternateMethod>>(), Enumerable.Empty<object>())).Returns(dependencyResolver); sut.Setup(context); Assert.Equal(dependencyResolver, DependencyResolver.Current); context.Logger.Verify(l => l.Debug(It.Is<string>(s => s.Contains("IDependencyResolver")), It.IsAny<object[]>())); }
public void ExtendsMvcRoutes(System.Web.Routing.IRouteHandler routeHandler, RoutesInspector sut, IInspectorContext context, System.Web.Routing.Route newRoute) { RouteTable.Routes.Clear(); RouteTable.Routes.Add("Test", new System.Web.Routing.Route("Test", routeHandler)); context.ProxyFactory.Setup(x => x.ExtendClass<System.Web.Routing.Route>(It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable(); sut.Setup(context); context.ProxyFactory.VerifyAll(); Assert.Same(newRoute, RouteTable.Routes[0]); }
public void ReturnRouteInstancesEvenWhenRoutesTableEmpty(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext) { System.Web.Routing.RouteTable.Routes.Clear(); routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy())); routeInspector.Setup(routeInspectorContext); var data = tab.GetData(context) as IList<RouteModel>; Assert.NotNull(data); Assert.Empty(data); }
public void UpdateModelBinders(ModelBinderInspector sut, IInspectorContext context, DummyDefaultModelBinder seedBinder, IModelBinder proxy) { ModelBinders.Binders.Add(typeof(object), seedBinder); context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible<IModelBinder>(It.IsAny<Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny<IModelBinder>(), It.IsAny<IEnumerable<IAlternateMethod>>())).Returns(proxy); sut.Setup(context); Assert.Contains(proxy, ModelBinders.Binders.Values); Assert.DoesNotContain(seedBinder, ModelBinders.Binders.Values); context.Logger.Verify(l => l.Info(It.IsAny<string>(), It.IsAny<object[]>())); }
public void ProxyDependencyResolver(DependencyInjectionInspector sut, IInspectorContext context, IDependencyResolver dependencyResolver) { DependencyResolver.SetResolver(dependencyResolver); context.ProxyFactory.Setup(f => f.IsWrapInterfaceEligible <IDependencyResolver>(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(f => f.WrapInterface(It.IsAny <IDependencyResolver>(), It.IsAny <IEnumerable <IAlternateMethod> >(), Enumerable.Empty <object>())).Returns(dependencyResolver); sut.Setup(context); Assert.Equal(dependencyResolver, DependencyResolver.Current); context.Logger.Verify(l => l.Debug(It.Is <string>(s => s.Contains("IDependencyResolver")), It.IsAny <object[]>())); }
public void UpdateModelBinders(ModelBinderInspector sut, IInspectorContext context, DummyDefaultModelBinder seedBinder, IModelBinder proxy) { ModelBinders.Binders.Add(typeof(object), seedBinder); context.ProxyFactory.Setup(pf => pf.IsWrapInterfaceEligible <IModelBinder>(It.IsAny <Type>())).Returns(true); context.ProxyFactory.Setup(pf => pf.WrapInterface(It.IsAny <IModelBinder>(), It.IsAny <IEnumerable <IAlternateMethod> >())).Returns(proxy); sut.Setup(context); Assert.Contains(proxy, ModelBinders.Binders.Values); Assert.DoesNotContain(seedBinder, ModelBinders.Binders.Values); context.Logger.Verify(l => l.Info(It.IsAny <string>(), It.IsAny <object[]>())); }
public void Setup(IInspectorContext context) { GlimpseConfig.Publish = m => { if (m != null && context.MessageBroker != null) { context.MessageBroker.Publish(m); } }; /* context.MessageBroker.Subscribe<GlimpseMail>(a => { int q = 0; }); */ }
public void WrapsMvcRouteDerivedTypes(RoutesInspector sut, System.Web.Routing.IRouteHandler routeHandler, IInspectorContext context, NewRoute route, System.Web.Routing.Route newRoute) { RouteTable.Routes.Clear(); RouteTable.Routes.Add("Test", route); context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(System.Web.Routing.Route))).Returns(true).Verifiable(); context.ProxyFactory.Setup(x => x.WrapClass((System.Web.Routing.Route)route, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable(); sut.Setup(context); context.ProxyFactory.VerifyAll(); Assert.Same(newRoute, RouteTable.Routes[0]); }
public void ReturnProperNumberOfInstances(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext) { System.Web.Routing.RouteTable.Routes.Clear(); System.Web.Routing.RouteTable.Routes.Ignore("Something"); routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy())); routeInspector.Setup(routeInspectorContext); var data = tab.GetData(context) as IList<RouteModel>; Assert.NotNull(data); Assert.Equal(System.Web.Routing.RouteTable.Routes.Count, data.Count); }
/// <summary> /// Setups the specified context. /// </summary> /// <param name="context">The context.</param> /// <remarks> /// Executed during the <see cref="Glimpse.Core.Framework.IGlimpseRuntime.Initialize" /> phase of /// system startup. Specifically, with the ASP.NET provider, this is wired to/implemented by the /// <c>System.Web.IHttpModule.Init</c> method. /// </remarks> public void Setup(IInspectorContext context) { var registeredAppenders = LogManager.GetAllRepositories() .SelectMany(repo => repo.GetAppenders()) .OfType<GlimpseAppender>(); if (registeredAppenders.Count() > 0) return; var repository = (Hierarchy)LogManager.GetRepository(); repository.Root.AddAppender(new GlimpseAppender(context.MessageBroker, context.TimerStrategy)); }
public void Setup(IInspectorContext context) { var logger = context.Logger; var originalControllerFactory = ControllerBuilder.Current.GetControllerFactory(); var alternateImplementation = new ControllerFactory(context.ProxyFactory); IControllerFactory newControllerFactory; if (alternateImplementation.TryCreate(originalControllerFactory, out newControllerFactory)) { ControllerBuilder.Current.SetControllerFactory(newControllerFactory); logger.Debug(Resources.ControllerFactorySetup, originalControllerFactory.GetType()); } }
public void Setup(IInspectorContext context) { Profiler.MessageBroker = context.MessageBroker; Profiler.ExecutionTimerFactory = () => { try { return(context.TimerStrategy()); } catch { // Avoid exception being thrown from threads without access to request store return(null); } };; }
public void Setup(IInspectorContext context) { var logger = context.Logger; var alternateBaseImplementation = new AlternateType.RouteBase(context.ProxyFactory, context.Logger); var currentRoutes = System.Web.Routing.RouteTable.Routes; using (currentRoutes.GetWriteLock()) { var mappedRoutes = (Dictionary <string, System.Web.Routing.RouteBase>)MappedRoutesField.GetValue(currentRoutes); for (var i = 0; i < currentRoutes.Count; i++) { var originalObj = currentRoutes[i]; if (IgnoredRouteTypes.Contains(originalObj.GetType().ToString())) { continue; } var newObj = (System.Web.Routing.RouteBase)null; var mixins = new[] { RouteNameMixin.None() }; var routeName = string.Empty; if (mappedRoutes.ContainsValue(originalObj)) { var pair = mappedRoutes.First(r => r.Value == originalObj); routeName = pair.Key; mixins = new[] { new RouteNameMixin(pair.Key) }; } if (alternateBaseImplementation.TryCreate(originalObj, out newObj, mixins)) { currentRoutes[i] = newObj; if (!string.IsNullOrEmpty(routeName)) { mappedRoutes[routeName] = newObj; } logger.Info(Resources.RouteSetupReplacedRoute, originalObj.GetType()); } else { logger.Info(Resources.RouteSetupNotReplacedRoute, originalObj.GetType()); } } } }
public void ExtendsStringConstraints(RoutesInspector sut, IInspectorContext context, NewRoute route, Route newRoute, string routeConstraint) { route.Constraints = new RouteValueDictionary { { "controller", routeConstraint } }; RouteTable.Routes.Clear(); RouteTable.Routes.Add("Test", route); context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(Route))).Returns(true).Verifiable(); context.ProxyFactory.Setup(x => x.WrapClass((Route)route, It.IsAny <IEnumerable <IAlternateMethod> >(), It.IsAny <IEnumerable <object> >(), It.IsAny <object[]>())).Returns(newRoute).Verifiable(); sut.Setup(context); context.ProxyFactory.VerifyAll(); Assert.Same(typeof(RouteConstraintRegex), route.Constraints["controller"].GetType()); }
public void ExtendsRouteConstraintConstraints(RoutesInspector sut, IInspectorContext context, NewRoute route, System.Web.Routing.Route newRoute, IRouteConstraint routeConstraint, IRouteConstraint newRouteConstraint) { route.Constraints = new RouteValueDictionary { { "controller", routeConstraint } }; RouteTable.Routes.Clear(); RouteTable.Routes.Add("Test", route); context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(System.Web.Routing.Route))).Returns(true).Verifiable(); context.ProxyFactory.Setup(x => x.WrapClass((System.Web.Routing.Route)route, It.IsAny <IEnumerable <IAlternateMethod> >(), It.IsAny <IEnumerable <object> >(), It.IsAny <object[]>())).Returns(newRoute).Verifiable(); context.ProxyFactory.Setup(x => x.IsWrapInterfaceEligible <IRouteConstraint>(typeof(IRouteConstraint))).Returns(true).Verifiable(); context.ProxyFactory.Setup(x => x.WrapInterface(routeConstraint, It.IsAny <IEnumerable <IAlternateMethod> >(), It.IsAny <IEnumerable <object> >())).Returns(newRouteConstraint).Verifiable(); sut.Setup(context); context.ProxyFactory.VerifyAll(); Assert.Same(newRouteConstraint, route.Constraints["controller"]); }
public void Setup(IInspectorContext context) { var logger = context.Logger; var alternateImplementation = new AlternateType.DependencyResolver(context.ProxyFactory); var dependencyResolver = DependencyResolver.Current; IDependencyResolver newResolver; if (alternateImplementation.TryCreate(dependencyResolver, out newResolver)) { DependencyResolver.SetResolver(newResolver); logger.Debug("Replaced IDependencyResolver of type '{0}' with proxy implementation.", dependencyResolver.GetType()); } else { logger.Warn("Couldn't replace IDependencyResolver of type '{0}' with proxy implementation.", dependencyResolver.GetType()); } }
public void Setup(IInspectorContext context) { var logger = context.Logger; var alternateImplementation = new AlternateType.DependencyResolver(context.ProxyFactory); var dependencyResolver = DependencyResolver.Current; IDependencyResolver newResolver; if (alternateImplementation.TryCreate(dependencyResolver, out newResolver)) { DependencyResolver.SetResolver(newResolver); logger.Debug(Resources.DependencyResolverSetupReplacedDependencyResolver, dependencyResolver.GetType()); } else { logger.Warn(Resources.DependencyResolverSetupNotReplacedDependencyResolver, dependencyResolver.GetType()); } }
private void SetupValueProviderFactories(IInspectorContext context) { var factories = ValueProviderFactories.Factories; if (factories.Count == 0) { return; } var alternateValueProviderFactory = new ValueProviderFactory(context.ProxyFactory); for (int i = 0; i < factories.Count; i++) { var originalFactory = factories[i]; System.Web.Mvc.ValueProviderFactory newFactory; if (alternateValueProviderFactory.TryCreate(originalFactory, out newFactory)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedValueProviderFactory, originalFactory.GetType()); factories[i] = newFactory; } } }
private void SetupModelBinderProviders(IInspectorContext context) { #if !MVC2 var binderProviders = ModelBinderProviders.BinderProviders; if (binderProviders.Count == 0) { return; } var alternateModelBinderProvider = new ModelBinderProvider(context.ProxyFactory); for (int i = 0; i < binderProviders.Count; i++) { var originalBinder = binderProviders[i]; IModelBinderProvider newProvider; if (alternateModelBinderProvider.TryCreate(originalBinder, out newProvider)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinderProvider, originalBinder.GetType()); binderProviders[i] = newProvider; } } #endif }