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>()); }
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>()); }
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>()); }
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 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)); }
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)); }
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>()); }