public void InputviewEngines_InstancesOf_ReturnsNonEmptyCollectionIfSomeExist()
        {
            // Arrange
            var viewEngines = new MvcViewOptions().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 MvcViewOptions().ViewEngines;
            viewEngines.Add(Mock.Of<IViewEngine>());
            viewEngines.Add(typeof(TestViewEngine));

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => viewEngines.InstanceOf<TestViewEngine>());
        }
        public void InputviewEngines_InstanceOf_ThrowsInvalidOperationExceptionIfNoInstance()
        {
            // Arrange
            var viewEngines = new MvcViewOptions().ViewEngines;

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

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => viewEngines.InstanceOf <TestViewEngine>());
        }
        public void InputviewEngines_InstanceOfOrDefault_ThrowsInvalidOperationExceptionIfMoreThanOnceInstance()
        {
            // Arrange
            var viewEngines = new MvcViewOptions().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 Setup_SetsUpViewEngines()
        {
            // Arrange
            var mvcOptions = new MvcViewOptions();
            var setup = new MvcViewOptionsSetup();

            // Act
            setup.Configure(mvcOptions);

            // Assert
            Assert.Equal(1, mvcOptions.ViewEngines.Count);
            Assert.Equal(typeof(RazorViewEngine), mvcOptions.ViewEngines[0].ViewEngineType);
        }
Exemplo n.º 6
0
        public void Setup_SetsUpViewEngines()
        {
            // Arrange
            var mvcOptions = new MvcViewOptions();
            var setup      = new MvcViewOptionsSetup();

            // Act
            setup.Configure(mvcOptions);

            // Assert
            Assert.Equal(1, mvcOptions.ViewEngines.Count);
            Assert.Equal(typeof(RazorViewEngine), mvcOptions.ViewEngines[0].ViewEngineType);
        }
        public void InputviewEngines_InstancesOf_ReturnsEmptyCollectionIfNoneExist()
        {
            // Arrange
            var viewEngines = new MvcViewOptions().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 MvcViewOptions().ViewEngines;

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

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

            // Assert
            Assert.Null(formatter);
        }
Exemplo n.º 9
0
        public void Setup_SetsUpClientModelValidatorProviders()
        {
            // Arrange
            var mvcOptions = new MvcViewOptions();
            var setup      = new MvcViewOptionsSetup();

            // Act
            setup.Configure(mvcOptions);

            // Assert
            Assert.Equal(2, mvcOptions.ClientModelValidatorProviders.Count);
            Assert.IsType <DefaultClientModelValidatorProvider>(mvcOptions.ClientModelValidatorProviders[0]);
            Assert.IsType <DataAnnotationsClientModelValidatorProvider>(mvcOptions.ClientModelValidatorProviders[1]);
        }
        public void InputviewEngines_InstanceOf_ReturnsInstanceOfIInputFormatterIfOneExists()
        {
            // Arrange
            var viewEngines = new MvcViewOptions().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 MvcViewOptions().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 MvcViewOptions().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 MvcViewOptions().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 MvcViewOptions().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 MvcViewOptions().ViewEngines;
            viewEngines.Add(new TestViewEngine());
            viewEngines.Add(Mock.Of<IViewEngine>());
            viewEngines.Add(new TestViewEngine());

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => viewEngines.InstanceOfOrDefault<TestViewEngine>());
        }
Exemplo n.º 16
0
        public void Setup_SetsUpClientModelValidatorProviders()
        {
            // Arrange
            var mvcOptions = new MvcViewOptions();
            var setup = new MvcViewOptionsSetup();

            // Act
            setup.Configure(mvcOptions);

            // Assert
            Assert.Equal(2, mvcOptions.ClientModelValidatorProviders.Count);
            Assert.IsType<DefaultClientModelValidatorProvider>(mvcOptions.ClientModelValidatorProviders[0]);
            Assert.IsType<DataAnnotationsClientModelValidatorProvider>(mvcOptions.ClientModelValidatorProviders[1]);
        }