chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

The method:

private void ConfigureMvcDependencyResolver(IUnityContainer container)

{

var controllerFactory = new UnityControllerFactory(container);

container.RegisterInstance<IControllerFactory>(controllerFactory);

// var currentControllerFactory = System.Web.Mvc.ControllerBuilder.Current.GetControllerFactory();

// container.RegisterInstance<IControllerFactory>(currentControllerFactory);

container.RegisterType<IControllerActivator, UnityControllerActivator>(new LifetimeManagers.UnityHttpContextPerRequestLifetimeManager(m_Context));

container.RegisterType<IViewPageActivator, UnityViewPageActivator>(new LifetimeManagers.UnityHttpContextPerRequestLifetimeManager(m_Context));

var filterProvider = new UnityFilterProvider(container);

container.RegisterInstance<IFilterProvider>(\"attributes\", filterProvider);

container.RegisterType<IActionInvoker, UnityActionInvoker>();

container.RegisterType<ITempDataProvider, System.Web.Mvc.SessionStateTempDataProvider>();

container.RegisterType<System.Web.Mvc.Async.IAsyncActionInvoker, System.Web.Mvc.Async.AsyncControllerActionInvoker>();

container.RegisterType<ModelMetadataProvider, DataAnnotationsModelMetadataProvider>(new LifetimeManagers.UnityHttpContextPerRequestLifetimeManager(m_Context));

var resolver = new UnityDependencyResolver(container);

System.Web.Mvc.DependencyResolver.SetResolver(resolver);

}

My test:

public void ConfigureMvcDependencyResolver_CalledWithNewContainer_ResolverWasSet ()

        {//new

            var fakeUnityContainer = Isolate.Fake.Instance<UnityContainerFactory>();

            var fakeContainer = Isolate.Fake.Instance<IUnityContainer>();

            Isolate.WhenCalled(() => System.Web.Mvc.DependencyResolver.SetResolver(null)).CallOriginal();

            // act

            var result = Isolate.Invoke.Method(fakeUnityContainer, \"ConfigureMvcDependencyResolver\", fakeContainer);

            // assert

            Isolate.Verify.WasNotCalled(() => System.Web.Mvc.DependencyResolver.SetResolver(null));

        }

The invoke is being used correctly and the test passes, but the method is not marked with green shield and seems like it not \"reached\"

asked by IlanG (4.8k points)

1 Answer

0 votes
What\'s the error?
answered by mcp111 (140 points)
...