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>());
        }
        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_ReturnsInstanceOfIInputFormatterIfOneExists()
        {
            // Arrange
            var viewEngines = new MvcViewOptions().ViewEngines;

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

            viewEngines.Add(testEngine);

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

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

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

            // Assert
            Assert.NotNull(formatter);
            Assert.IsType<TestViewEngine>(formatter);
            Assert.Same(testEngine, formatter);
        }
        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>());
        }