Exemplo n.º 1
0
        private void RegisterVerde()
        {
            var settings = new Verde.Settings
            {
                TestsAssembly = System.Reflection.Assembly.GetExecutingAssembly(),
                AuthorizationCheck = (context) =>
                {
                    // Here we could do something that verifies that the current user is allowed to
                    // invoke integration tests.  Maybe something like:
                    // return context.User.IsInRole("admin");
                    return true;
                },
                TestFixtureFactory = new CommonServiceLocatorTestFixtureFactory(ServiceLocator.Current)
            };

            // Because we are using Autofac for IoC, we need this step to ensure that HttpContextWrapper gets
            // resolved to the Verde.Executor.HttpContextProxy rather than HttpContext.Current. This step is only
            // necessary if the AutofacDependencyResolver is in use.
            settings.BeginExecuteTestsRequest += (sender, e) =>
            {
                var resolver = DependencyResolver.Current as AutofacDependencyResolver;
                if (resolver != null)
                    new AutofacHttpContextModule().Configure(resolver.ApplicationContainer.ComponentRegistry);
            };

            // Conditionally invoke this line only if integration tests should be enabled in the current environment.
            Verde.Setup.Initialize(settings);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the integration tester.
        /// </summary>
        /// <remarks>
        /// This should be invoked from the Application_Start method in Global.asax.
        /// </remarks>
        public static void Initialize(Settings settings)
        {
            if (_initialized)
                throw new InvalidOperationException("Initialize method should only be called once.");

            _settings = settings;
            _settings.Validate();

            IntegrationTestHandler.RegisterRoutes();

            _initialized = true;
        }
Exemplo n.º 3
0
        public NUnitTestRunner(Settings settings)
        {
            _settings = settings;

            _fixtures = new List<NUnitTestFixture>();
            foreach (var type in settings.TestsAssembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(IntegrationFixtureAttribute), false);
                if (attrs.Length == 0)
                    continue;

                var fixture = new NUnitTestFixture(type, ((IntegrationFixtureAttribute)attrs[0]).Sequence);
                _fixtures.Add(fixture);
            }

            _fixtures.Sort((f1, f2) => f1.Sequence.CompareTo(f2.Sequence));
        }
Exemplo n.º 4
0
        protected void Application_Start()
        {
            IContainer container= AutofacRegistration();

            ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container));

            var settings = new Verde.Settings
            {
                TestsAssembly = System.Reflection.Assembly.GetExecutingAssembly(),
                AuthorizationCheck = (context) =>
                {
                    // Here we could do something that verifies that the current user is allowed to
                    // invoke integration tests.  Maybe something like:
                    // return context.User.IsInRole("admin");
                    return true;
                },
                TestFixtureFactory = new CommonServiceLocatorTestFixtureFactory(ServiceLocator.Current)
            };

            // Because we are using Autofac for IoC, we need this step to ensure that HttpContextWrapper gets
            // resolved to the Verde.Executor.HttpContextProxy rather than HttpContext.Current. This step is only
            // necessary if the AutofacDependencyResolver is in use.
            settings.BeginExecuteTestsRequest += (sender, e) =>
            {
                var resolver = DependencyResolver.Current as AutofacDependencyResolver;
                if (resolver != null)
                    new AutofacHttpContextModule().Configure(resolver.ApplicationContainer.ComponentRegistry);
            };

            // Conditionally invoke this line only if integration tests should be enabled in the current environment.
            Verde.Setup.Initialize(settings);

            System.Data.Entity.Database.SetInitializer(new MvcMusicStore.Models.SampleData());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }