public void GetControllersMetaData_LocalControllers_GetWithoutIgnoredAndSortedCorrectly()
        {
            // Assign

            AcspTypesFinder.ExcludedAssembliesPrefixes.Remove("AcspNet");
            AcspTypesFinder.ExcludedAssembliesPrefixes.Add("DynamicProxyGenAssembly2");
            AcspTypesFinder.CleanLoadedTypesAndAssenbliesInfo();

            var factory = new Mock <IControllerMetaDataFactory>();
            var store   = new ControllersMetaStore(factory.Object);

            factory.SetupSequence(x => x.CreateControllerMetaData(It.IsAny <Type>()))
            .Returns(new ControllerMetaData(typeof(TestController1), new ControllerExecParameters(null, 2)))
            .Returns(new ControllerMetaData(typeof(TestController2), new ControllerExecParameters(null, 1)))
            .Returns(new ControllerMetaData(typeof(TestController4)))
            .Returns(new ControllerMetaData(typeof(TestController5)));

            // Act
            var metaData = store.ControllersMetaData;

            Assert.AreEqual(4, metaData.Count);
            Assert.AreEqual("TestController4", metaData[0].ControllerType.Name);
            Assert.AreEqual("TestController5", metaData[1].ControllerType.Name);
            Assert.AreEqual("TestController2", metaData[2].ControllerType.Name);
            Assert.AreEqual("TestController1", metaData[3].ControllerType.Name);

            factory.Verify(x => x.CreateControllerMetaData(It.Is <Type>(t => t == typeof(TestController1))));
            factory.Verify(x => x.CreateControllerMetaData(It.Is <Type>(t => t == typeof(TestController2))));
            factory.Verify(x => x.CreateControllerMetaData(It.Is <Type>(t => t == typeof(TestController4))));
            factory.Verify(x => x.CreateControllerMetaData(It.Is <Type>(t => t == typeof(TestController5))));
        }
        public void FindTypesDerivedFrom_NoDerivedTypes_NullReturned()
        {
            // Act
            var types = AcspTypesFinder.FindTypesDerivedFrom <TestBootstrapper>();

            // Assert
            Assert.AreEqual(0, types.Count);
        }
        public void FindTypeDerivedFrom_NoDerivedTypes_NullReturned()
        {
            // Act
            var type = AcspTypesFinder.FindTypeDerivedFrom <TestBootstrapper>();

            // Assert
            Assert.IsNull(type);
        }
        public void FindTypeDerivedFrom_BaseAcspNetBootstrapper_TestBootstrapperReturned()
        {
            // Assign

            AcspTypesFinder.ExcludedAssembliesPrefixes.Remove("AcspNet");
            AcspTypesFinder.CleanLoadedTypesAndAssenbliesInfo();

            // Act
            var type = AcspTypesFinder.FindTypeDerivedFrom <BaseAcspNetBootstrapper>();

            // Assert
            Assert.AreEqual("AcspNet.Tests.TestEntities.TestBootstrapper", type.FullName);
        }
Exemple #5
0
		public void CreateBootstrapper_HaveUserType_TestBootstrapperReturned()
		{
			// Assign

			AcspTypesFinder.ExcludedAssembliesPrefixes.Remove("AcspNet");
			AcspTypesFinder.CleanLoadedTypesAndAssenbliesInfo();

			// Act
			var bootstrapper = BootstrapperFactory.CreateBootstrapper();

			// Assert

			Assert.AreEqual("AcspNet.Tests.TestEntities.TestBootstrapper", bootstrapper.GetType().FullName);
		}
        private static IEnumerable <Type> GetIgnoredTypes()
        {
            var typesToIgnore = new List <Type>();

            var ignoreContainingClass = AcspTypesFinder.GetAllTypes().FirstOrDefault(t => t.IsDefined(typeof(IgnoreTypesRegistrationAttribute), true));

            if (ignoreContainingClass != null)
            {
                var attributes = ignoreContainingClass.GetCustomAttributes(typeof(IgnoreTypesRegistrationAttribute), false);

                typesToIgnore.AddRange(((IgnoreTypesRegistrationAttribute)attributes[0]).Types);
            }

            return(typesToIgnore);
        }
Exemple #7
0
		public void CreateBootstrapper_NoUserType_BaseAcspNetBootstrapperReturned()
		{
			// Assign

			if(!AcspTypesFinder.ExcludedAssembliesPrefixes.Contains("AcspNet"))
				AcspTypesFinder.ExcludedAssembliesPrefixes.Add("AcspNet");

			AcspTypesFinder.CleanLoadedTypesAndAssenbliesInfo();

			// Act
			var bootstrapper = BootstrapperFactory.CreateBootstrapper();

			// Assert

			Assert.AreEqual("AcspNet.Bootstrapper.BaseAcspNetBootstrapper", bootstrapper.GetType().FullName);
		}
        public void FindTypesDerivedFrom_TypeHave3TypesDerived_3TestControllersReturned()
        {
            // Assign

            AcspTypesFinder.ExcludedAssembliesPrefixes.Remove("AcspNet");
            AcspTypesFinder.ExcludedAssembliesPrefixes.Add("DynamicProxyGenAssembly2");
            AcspTypesFinder.CleanLoadedTypesAndAssenbliesInfo();

            // Act
            var types  = AcspTypesFinder.FindTypesDerivedFrom <Controller>();
            var types2 = AcspTypesFinder.FindTypesDerivedFrom <AsyncController>();

            // Assert

            Assert.AreEqual(2, types.Count);
            Assert.AreEqual(1, types2.Count);
            Assert.AreEqual("AcspNet.Tests.TestEntities.TestController1", types[1].FullName);
            Assert.AreEqual("AcspNet.Tests.TestEntities.TestController3", types[0].FullName);
            Assert.AreEqual("AcspNet.Tests.TestEntities.TestController2", types2[0].FullName);
        }
        /// <summary>
        /// Creates the bootstrapper.
        /// </summary>
        /// <returns></returns>
        public static BaseAcspNetBootstrapper CreateBootstrapper()
        {
            var userBootstrapperType = AcspTypesFinder.FindTypeDerivedFrom <BaseAcspNetBootstrapper>();

            return(userBootstrapperType != null ? (BaseAcspNetBootstrapper)Activator.CreateInstance(userBootstrapperType) : new BaseAcspNetBootstrapper());
        }