public void GetControllerTypes_FindsTypes()
        {
            // Arrange
            DefaultHttpControllerTypeResolver resolver = new DefaultHttpControllerTypeResolver();
            Mock<IAssembliesResolver> mockAssemblyResolver = new Mock<IAssembliesResolver>();
            mockAssemblyResolver.Setup(a => a.GetAssemblies()).Returns(new List<Assembly> 
            {
                null,
                new MockExportedTypesAssembly(ThrowException.ReflectionTypeLoadException,
                    typeof(InvalidControllerStruct),
                    typeof(ValidController), 
                    typeof(ControllerWrapper.InvalidNestedController),
                    typeof(InvalidControllerWithInconsistentName)),
                new MockExportedTypesAssembly(ThrowException.Exception,
                    typeof(InvalidControllerAbstract),
                    typeof(InvalidControllerWithNoBaseType)),
                new MockExportedTypesAssembly(ThrowException.None,
                    typeof(VALIDController), 
                    typeof(VALIDCONTROLLER), 
                    typeof(InvalidControllerStruct)),
            });

            // Act
            ICollection<Type> actualControllerTypes = resolver.GetControllerTypes(mockAssemblyResolver.Object);

            // Assert
            Assert.Equal(3, actualControllerTypes.Count);
            Assert.True(actualControllerTypes.Contains(typeof(ValidController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDCONTROLLER)));
        }
        public void GetControllerTypes_FindsTypes()
        {
            // Arrange
            DefaultHttpControllerTypeResolver resolver             = new DefaultHttpControllerTypeResolver();
            Mock <IAssembliesResolver>        mockAssemblyResolver = new Mock <IAssembliesResolver>();

            mockAssemblyResolver.Setup(a => a.GetAssemblies()).Returns(new List <Assembly>
            {
                null,
                new MockExportedTypesAssembly(ThrowException.ReflectionTypeLoadException,
                                              typeof(InvalidControllerStruct),
                                              typeof(ValidController),
                                              typeof(ControllerWrapper.InvalidNestedController),
                                              typeof(InvalidControllerWithInconsistentName)),
                new MockExportedTypesAssembly(ThrowException.Exception,
                                              typeof(InvalidControllerAbstract),
                                              typeof(InvalidControllerWithNoBaseType)),
                new MockExportedTypesAssembly(ThrowException.None,
                                              typeof(VALIDController),
                                              typeof(VALIDCONTROLLER),
                                              typeof(InvalidControllerStruct)),
            });

            // Act
            ICollection <Type> actualControllerTypes = resolver.GetControllerTypes(mockAssemblyResolver.Object);

            // Assert
            Assert.Equal(3, actualControllerTypes.Count);
            Assert.True(actualControllerTypes.Contains(typeof(ValidController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDCONTROLLER)));
        }
        public void GetControllerTypes_ThrowsOnNull()
        {
            DefaultHttpControllerTypeResolver resolver = new DefaultHttpControllerTypeResolver();

            Assert.ThrowsArgumentNull(
                () => resolver.GetControllerTypes(null),
                "assembliesResolver"
                );
        }
Beispiel #4
0
        public void GetControllerTypes_FindsTypes()
        {
            // Arrange
            DefaultHttpControllerTypeResolver resolver             = new DefaultHttpControllerTypeResolver();
            Mock <IAssembliesResolver>        mockAssemblyResolver = new Mock <IAssembliesResolver>();

            mockAssemblyResolver.Setup(a => a.GetAssemblies()).Returns(new List <Assembly>
            {
                null,
                new MockExportedTypesAssembly(ThrowException.ReflectionTypeLoadException,
                                              typeof(ControllerWrapper.ValidNestedController),
                                              typeof(ControllerWrapper.ValidInheritedNestedController),
                                              typeof(ControllerWrapper.ControllerNestedWrapper.ValidNestedNestedController),
                                              typeof(InheritedControllerHidingWrapper.ValidNestedController)),
                new MockExportedTypesAssembly(ThrowException.Exception,
                                              typeof(ControllerWrapper.InvalidAbstractNestedController),
                                              ControllerWrapper.TypeOfInvalidProtectedNestedController(), // NOTE: Unable to get through typeof(ControllerWrapper.InvalidProtectedNestedController),
                                              ControllerWrapper.TypeOfInvalidPrivateNestedController(),   // NOTE: Unable to get through typeof(ControllerWrapper.InvalidPrivateNestedController),
                                              typeof(ControllerWrapper.InvalidInternalNestedController)),
                new MockExportedTypesAssembly(ThrowException.None,
                                              typeof(ValidSealedController),
                                              typeof(ValidPartialController),
                                              typeof(ValidInheritedController),
                                              typeof(ValidController),
                                              typeof(VALIDController),
                                              typeof(VALIDCONTROLLER),
                                              typeof(InvalidAbstractController),
                                              typeof(InvalidControllerStruct),
                                              typeof(InvalidControllerWithInconsistentName),
                                              typeof(InvalidControllerWithNoBaseType))
            });

            // Act
            ICollection <Type> actualControllerTypes = resolver.GetControllerTypes(mockAssemblyResolver.Object);

            // Assert
            Assert.Equal(10, actualControllerTypes.Count);
            Assert.True(actualControllerTypes.Contains(typeof(ControllerWrapper.ValidNestedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ControllerWrapper.ValidInheritedNestedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ControllerWrapper.ControllerNestedWrapper.ValidNestedNestedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidSealedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidPartialController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidInheritedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDCONTROLLER)));
            Assert.True(actualControllerTypes.Contains(typeof(InheritedControllerHidingWrapper.ValidNestedController)));
        }
 public void GetControllerTypes_ThrowsOnNull()
 {
     DefaultHttpControllerTypeResolver resolver = new DefaultHttpControllerTypeResolver();
     Assert.ThrowsArgumentNull(() => resolver.GetControllerTypes(null), "assembliesResolver");
 }
        public void GetControllerTypes_FindsTypes()
        {
            // Arrange
            DefaultHttpControllerTypeResolver resolver = new DefaultHttpControllerTypeResolver();
            Mock<IAssembliesResolver> mockAssemblyResolver = new Mock<IAssembliesResolver>();

            mockAssemblyResolver.Setup(a => a.GetAssemblies()).Returns(new List<Assembly> 
            {
                null,
                new MockExportedTypesAssembly(ThrowException.ReflectionTypeLoadException,
                    typeof(ControllerWrapper.ValidNestedController),
                    typeof(ControllerWrapper.ValidInheritedNestedController),
                    typeof(ControllerWrapper.ControllerNestedWrapper.ValidNestedNestedController),
                    typeof(InheritedControllerHidingWrapper.ValidNestedController)),
                new MockExportedTypesAssembly(ThrowException.Exception,
                    typeof(ControllerWrapper.InvalidAbstractNestedController),
                    ControllerWrapper.TypeOfInvalidProtectedNestedController(), // NOTE: Unable to get through typeof(ControllerWrapper.InvalidProtectedNestedController),
                    ControllerWrapper.TypeOfInvalidPrivateNestedController(), // NOTE: Unable to get through typeof(ControllerWrapper.InvalidPrivateNestedController),
                    typeof(ControllerWrapper.InvalidInternalNestedController)),
                new MockExportedTypesAssembly(ThrowException.None,
                    typeof(ValidSealedController),
                    typeof(ValidPartialController),
                    typeof(ValidInheritedController),
                    typeof(ValidController),
                    typeof(VALIDController),
                    typeof(VALIDCONTROLLER),
                    typeof(InvalidAbstractController),
                    typeof(InvalidControllerStruct),
                    typeof(InvalidControllerWithInconsistentName),
                    typeof(InvalidControllerWithNoBaseType))
            });

            // Act
            ICollection<Type> actualControllerTypes = resolver.GetControllerTypes(mockAssemblyResolver.Object);

            // Assert
            Assert.Equal(10, actualControllerTypes.Count);
            Assert.True(actualControllerTypes.Contains(typeof(ControllerWrapper.ValidNestedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ControllerWrapper.ValidInheritedNestedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ControllerWrapper.ControllerNestedWrapper.ValidNestedNestedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidSealedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidPartialController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidInheritedController)));
            Assert.True(actualControllerTypes.Contains(typeof(ValidController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDController)));
            Assert.True(actualControllerTypes.Contains(typeof(VALIDCONTROLLER)));
            Assert.True(actualControllerTypes.Contains(typeof(InheritedControllerHidingWrapper.ValidNestedController)));
        }
Beispiel #7
0
 public void HasValidControllerName_RejectsInvalidControllerNames(Type invalidControllerType)
 {
     Assert.False(DefaultHttpControllerTypeResolver.HasValidControllerName(invalidControllerType));
 }
Beispiel #8
0
 public void HasValidControllerName_AcceptsValidControllerNames(Type validControllerType)
 {
     Assert.True(DefaultHttpControllerTypeResolver.HasValidControllerName(validControllerType));
 }
Beispiel #9
0
 public void IsControllerType_RejectsInvalidControllerTypes(Type invalidControllerType)
 {
     Assert.False(DefaultHttpControllerTypeResolver.IsControllerType(invalidControllerType));
 }
Beispiel #10
0
 public void IsControllerType_AcceptsValidControllerTypes(Type validControllerType)
 {
     Assert.True(DefaultHttpControllerTypeResolver.IsControllerType(validControllerType));
 }
        public void IsControllerTypePredicateProperty_RoundTrips()
        {
            // Arrange
            Predicate<Type> expectedPredicate = type => type != null;
            DefaultHttpControllerTypeResolver resolver = new DefaultHttpControllerTypeResolver(expectedPredicate);

            TestTraceWriter traceWriter = new TestTraceWriter();
            DefaultHttpControllerTypeResolverTracer tracer =
                new DefaultHttpControllerTypeResolverTracer(resolver, traceWriter);

            // Act
            Predicate<Type> predicate = tracer.IsControllerTypePredicate;

            // Assert
            Assert.NotNull(predicate);
            Assert.Same(expectedPredicate, predicate);
        }