Exemplo n.º 1
0
        public void InputviewEngines_InstancesOf_ReturnsNonEmptyCollectionIfSomeExist()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;

            viewEngines.Add(typeof(TestViewEngine));
            var viewEngine1 = new TestViewEngine();
            var viewEngine2 = Mock.Of <IViewEngine>();
            var viewEngine3 = new TestViewEngine();
            var viewEngine4 = Mock.Of <IViewEngine>();

            viewEngines.Add(viewEngine1);
            viewEngines.Add(viewEngine2);
            viewEngines.Add(viewEngine3);
            viewEngines.Add(viewEngine4);

            var expectedviewEngines = new List <TestViewEngine> {
                viewEngine1, viewEngine3
            };

            // Act
            var result = viewEngines.InstancesOf <TestViewEngine>().ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Equal(result, expectedviewEngines);
        }
        public void InputviewEngines_InstanceOf_ThrowsInvalidOperationExceptionIfNoInstance()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;
            viewEngines.Add(Mock.Of<IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => viewEngines.InstanceOf<TestViewEngine>());
        }
Exemplo n.º 3
0
        public void InputviewEngines_InstanceOf_ThrowsInvalidOperationExceptionIfNoInstance()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;

            viewEngines.Add(Mock.Of <IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => viewEngines.InstanceOf <TestViewEngine>());
        }
Exemplo n.º 4
0
        public void InputviewEngines_InstanceOfOrDefault_ThrowsInvalidOperationExceptionIfMoreThanOnceInstance()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;

            viewEngines.Add(new TestViewEngine());
            viewEngines.Add(Mock.Of <IViewEngine>());
            viewEngines.Add(new TestViewEngine());

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => viewEngines.InstanceOfOrDefault <TestViewEngine>());
        }
Exemplo n.º 5
0
        public void InputviewEngines_InstancesOf_ReturnsEmptyCollectionIfNoneExist()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;

            viewEngines.Add(Mock.Of <IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act
            var result = viewEngines.InstancesOf <TestViewEngine>();

            // Assert
            Assert.Empty(result);
        }
Exemplo n.º 6
0
        public void InputviewEngines_InstanceOfOrDefault_ReturnsNullIfNoInstance()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;

            viewEngines.Add(Mock.Of <IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act
            var formatter = viewEngines.InstanceOfOrDefault <TestViewEngine>();

            // Assert
            Assert.Null(formatter);
        }
        public void ModelBinders_RemoveTypesOf_RemovesDescriptorsOfIModelBinder()
        {
            // Arrange
            var modelBinders = new MvcOptions().ModelBinders;
            modelBinders.Add(new ByteArrayModelBinder());
            modelBinders.Add(Mock.Of<IModelBinder>());
            modelBinders.Add(typeof(ByteArrayModelBinder));
            modelBinders.Add(Mock.Of<IModelBinder>());

            // Act
            modelBinders.RemoveTypesOf<ByteArrayModelBinder>();

            // Assert
            Assert.DoesNotContain(modelBinders, descriptor => descriptor.OptionType == typeof(ByteArrayModelBinder));
        }
        public void ValueProviderFactories_RemoveTypesOf_RemovesDescriptorsOfIValueProviderFactory()
        {
            // Arrange
            var factories = new MvcOptions().ValueProviderFactories;
            factories.Add(new FormValueProviderFactory());
            factories.Add(Mock.Of<IValueProviderFactory>());
            factories.Add(typeof(FormValueProviderFactory));
            factories.Add(Mock.Of<IValueProviderFactory>());

            // Act
            factories.RemoveTypesOf<FormValueProviderFactory>();

            // Assert
            Assert.DoesNotContain(factories, descriptor => descriptor.OptionType == typeof(FormValueProviderFactory));
        }
Exemplo n.º 9
0
        public void ModelBinders_RemoveTypesOf_RemovesDescriptorsOfIModelBinder()
        {
            // Arrange
            var modelBinders = new MvcOptions().ModelBinders;

            modelBinders.Add(new ByteArrayModelBinder());
            modelBinders.Add(Mock.Of <IModelBinder>());
            modelBinders.Add(typeof(ByteArrayModelBinder));
            modelBinders.Add(Mock.Of <IModelBinder>());

            // Act
            modelBinders.RemoveTypesOf <ByteArrayModelBinder>();

            // Assert
            Assert.DoesNotContain(modelBinders, descriptor => descriptor.OptionType == typeof(ByteArrayModelBinder));
        }
        public void ValueProviderFactories_RemoveTypesOf_RemovesDescriptorsOfIValueProviderFactory()
        {
            // Arrange
            var factories = new MvcOptions().ValueProviderFactories;

            factories.Add(new FormValueProviderFactory());
            factories.Add(Mock.Of <IValueProviderFactory>());
            factories.Add(typeof(FormValueProviderFactory));
            factories.Add(Mock.Of <IValueProviderFactory>());

            // Act
            factories.RemoveTypesOf <FormValueProviderFactory>();

            // Assert
            Assert.DoesNotContain(factories, descriptor => descriptor.OptionType == typeof(FormValueProviderFactory));
        }
Exemplo n.º 11
0
        public void InputviewEngines_InstanceOf_ReturnsInstanceOfIInputFormatterIfOneExists()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;

            viewEngines.Add(Mock.Of <IViewEngine>());
            var testEngine = new TestViewEngine();

            viewEngines.Add(testEngine);
            viewEngines.Add(typeof(TestViewEngine));

            // Act
            var formatter = viewEngines.InstanceOf <TestViewEngine>();

            // Assert
            Assert.NotNull(formatter);
            Assert.IsType <TestViewEngine>(formatter);
            Assert.Same(testEngine, formatter);
        }
        public void InputviewEngines_InstanceOf_ReturnsInstanceOfIInputFormatterIfOneExists()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;
            viewEngines.Add(Mock.Of<IViewEngine>());
            var testEngine = new TestViewEngine();
            viewEngines.Add(testEngine);
            viewEngines.Add(typeof(TestViewEngine));

            // Act
            var formatter = viewEngines.InstanceOf<TestViewEngine>();

            // Assert
            Assert.NotNull(formatter);
            Assert.IsType<TestViewEngine>(formatter);
            Assert.Same(testEngine, formatter);
        }
        public void InputviewEngines_InstancesOf_ReturnsNonEmptyCollectionIfSomeExist()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;
            viewEngines.Add(typeof(TestViewEngine));
            var viewEngine1 = new TestViewEngine();
            var viewEngine2 = Mock.Of<IViewEngine>();
            var viewEngine3 = new TestViewEngine();
            var viewEngine4 = Mock.Of<IViewEngine>();
            viewEngines.Add(viewEngine1);
            viewEngines.Add(viewEngine2);
            viewEngines.Add(viewEngine3);
            viewEngines.Add(viewEngine4);

            var expectedviewEngines = new List<TestViewEngine> { viewEngine1, viewEngine3 };

            // Act
            var result = viewEngines.InstancesOf<TestViewEngine>().ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Equal(result, expectedviewEngines);
        }
        public void InputviewEngines_InstancesOf_ReturnsEmptyCollectionIfNoneExist()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;
            viewEngines.Add(Mock.Of<IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act
            var result = viewEngines.InstancesOf<TestViewEngine>();

            // Assert
            Assert.Empty(result);
        }
        public void InputviewEngines_InstanceOfOrDefault_ReturnsNullIfNoInstance()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;
            viewEngines.Add(Mock.Of<IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act
            var formatter = viewEngines.InstanceOfOrDefault<TestViewEngine>();

            // Assert
            Assert.Null(formatter);
        }
        public void InputviewEngines_InstanceOfOrDefault_ThrowsInvalidOperationExceptionIfMoreThanOnceInstance()
        {
            // Arrange
            var viewEngines = new MvcOptions().ViewEngines;
            viewEngines.Add(new TestViewEngine());
            viewEngines.Add(Mock.Of<IViewEngine>());
            viewEngines.Add(new TestViewEngine());

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => viewEngines.InstanceOfOrDefault<TestViewEngine>());
        }