public void DefaultViewComponentActivator_ActivatesViewComponentContext()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();

            var context = new ViewComponentContext();
            var instance = new TestViewComponent();

            // Act
            activator.Activate(instance, context);

            // Assert
            Assert.Same(context, instance.ViewComponentContext);
        }
Exemplo n.º 2
0
        public void DefaultViewComponentActivator_ActivatesViewComponentContext()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();

            var context  = new ViewComponentContext();
            var instance = new TestViewComponent();

            // Act
            activator.Activate(instance, context);

            // Assert
            Assert.Same(context, instance.ViewComponentContext);
        }
        public void DefaultViewComponentActivator_ActivatesViewComponentContext_IgnoresNonPublic()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();

            var context = new ViewComponentContext();
            var instance = new VisibilityViewComponent();

            // Act
            activator.Activate(instance, context);

            // Assert
            Assert.Same(context, instance.ViewComponentContext);
            Assert.Null(instance.C);
        }
Exemplo n.º 4
0
        public void DefaultViewComponentActivator_ActivatesViewComponentContext_IgnoresNonPublic()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();

            var context  = new ViewComponentContext();
            var instance = new VisibilityViewComponent();

            // Act
            activator.Activate(instance, context);

            // Assert
            Assert.Same(context, instance.ViewComponentContext);
            Assert.Null(instance.C);
        }
        public void DefaultViewComponentActivatorSetsModelAsNull()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();
            var helper = Mock.Of<IHtmlHelper<object>>();
            var serviceProvider = new Mock<IServiceProvider>();
            serviceProvider.Setup(p => p.GetService(typeof(IHtmlHelper<object>))).Returns(helper);
            serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))).Returns(Mock.Of<ICompositeViewEngine>());
            serviceProvider.Setup(p => p.GetService(typeof(IUrlHelper))).Returns(Mock.Of<IUrlHelper>());
            var viewContext = GetViewContext(serviceProvider.Object);

            // Act
            activator.Activate(new TestViewComponent(), viewContext);

            // Assert
            Assert.Null(viewContext.ViewData.Model);
        }
        public void DefaulViewComponentActivatorContextualizesService()
        {
            // Arrange
            var activator       = new DefaultViewComponentActivator();
            var instance        = new TestClassUsingMyService();
            var myTestService   = new MyService();
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(p => p.GetService(typeof(MyService))).Returns(myTestService);
            var viewContext = GetViewContext(serviceProvider.Object);

            // Act
            activator.Activate(instance, viewContext);

            // Assert
            Assert.Same(myTestService, instance.MyTestService);
            Assert.Same(viewContext, instance.MyTestService.ViewContext);
        }
        public void DefaultViewComponentActivatorSetsModelAsNull()
        {
            // Arrange
            var activator       = new DefaultViewComponentActivator();
            var helper          = Mock.Of <IHtmlHelper <object> >();
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(p => p.GetService(typeof(IHtmlHelper <object>))).Returns(helper);
            serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))).Returns(Mock.Of <ICompositeViewEngine>());
            serviceProvider.Setup(p => p.GetService(typeof(IUrlHelper))).Returns(Mock.Of <IUrlHelper>());
            var viewContext = GetViewContext(serviceProvider.Object);

            // Act
            activator.Activate(new TestViewComponent(), viewContext);

            // Assert
            Assert.Null(viewContext.ViewData.Model);
        }
        public void DefaultViewComponentActivatorSetsAllPropertiesMarkedAsActivate()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();
            var instance = new TestViewComponent();
            var helper = Mock.Of<IHtmlHelper<object>>();
            var serviceProvider = new Mock<IServiceProvider>();
            serviceProvider.Setup(p => p.GetService(typeof(IHtmlHelper<object>))).Returns(helper);
            serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))).Returns(Mock.Of<ICompositeViewEngine>());
            serviceProvider.Setup(p => p.GetService(typeof(IUrlHelper))).Returns(Mock.Of<IUrlHelper>());
            var viewContext = GetViewContext(serviceProvider.Object);

            // Act
            activator.Activate(instance, viewContext);

            // Assert
            Assert.Same(helper, instance.Html);
            Assert.Same(viewContext, instance.ViewContext);
            Assert.IsType<ViewDataDictionary>(instance.ViewData);
        }
        public void DefaultViewComponentActivatorActivatesNonBuiltInTypes()
        {
            // Arrange
            var activator       = new DefaultViewComponentActivator();
            var helper          = Mock.Of <IHtmlHelper <object> >();
            var myTestService   = new MyService();
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(p => p.GetService(typeof(IHtmlHelper <object>))).Returns(helper);
            serviceProvider.Setup(p => p.GetService(typeof(MyService))).Returns(myTestService);
            serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))).Returns(Mock.Of <ICompositeViewEngine>());
            serviceProvider.Setup(p => p.GetService(typeof(IUrlHelper))).Returns(Mock.Of <IUrlHelper>());
            var viewContext = GetViewContext(serviceProvider.Object);
            var instance    = new TestViewComponentWithCustomDataType();

            // Act
            activator.Activate(instance, viewContext);

            // Assert
            Assert.Equal(myTestService, instance.TestMyServiceObject);
        }
        public void DefaultViewComponentActivatorSetsAllPropertiesMarkedAsActivate()
        {
            // Arrange
            var activator       = new DefaultViewComponentActivator();
            var instance        = new TestViewComponent();
            var helper          = Mock.Of <IHtmlHelper <object> >();
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(p => p.GetService(typeof(IHtmlHelper <object>))).Returns(helper);
            serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))).Returns(Mock.Of <ICompositeViewEngine>());
            serviceProvider.Setup(p => p.GetService(typeof(IUrlHelper))).Returns(Mock.Of <IUrlHelper>());
            var viewContext = GetViewContext(serviceProvider.Object);

            // Act
            activator.Activate(instance, viewContext);

            // Assert
            Assert.Same(helper, instance.Html);
            Assert.Same(viewContext, instance.ViewContext);
            Assert.IsType <ViewDataDictionary>(instance.ViewData);
        }
        public void DefaultViewComponentActivatorActivatesNonBuiltInTypes()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();
            var helper = Mock.Of<IHtmlHelper<object>>();
            var myTestService = new MyService();
            var serviceProvider = new Mock<IServiceProvider>();
            serviceProvider.Setup(p => p.GetService(typeof(IHtmlHelper<object>))).Returns(helper);
            serviceProvider.Setup(p => p.GetService(typeof(MyService))).Returns(myTestService);
            serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine))).Returns(Mock.Of<ICompositeViewEngine>());
            serviceProvider.Setup(p => p.GetService(typeof(IUrlHelper))).Returns(Mock.Of<IUrlHelper>());
            var viewContext = GetViewContext(serviceProvider.Object);
            var instance = new TestViewComponentWithCustomDataType();

            // Act
            activator.Activate(instance, viewContext);

            // Assert
            Assert.Equal(myTestService, instance.TestMyServiceObject);

        }
        public void DefaulViewComponentActivatorContextualizesService()
        {
            // Arrange
            var activator = new DefaultViewComponentActivator();
            var instance = new TestClassUsingMyService();
            var myTestService = new MyService();
            var serviceProvider = new Mock<IServiceProvider>();
            serviceProvider.Setup(p => p.GetService(typeof(MyService))).Returns(myTestService);
            var viewContext = GetViewContext(serviceProvider.Object);

            // Act
            activator.Activate(instance, viewContext);

            // Assert
            Assert.Same(myTestService, instance.MyTestService);
            Assert.Same(viewContext, instance.MyTestService.ViewContext);
        }