示例#1
0
 /// <summary>
 /// This helps the dependency injection mechanism find assemblies to look for implementations
 /// </summary>
 protected virtual void ConfigureDependencyImplentationSelector(ImplementationSelector defaultImplementationSelector)
 {
     foreach (Assembly assembly in DependencyImplementationAssemblies.GetAssemblies())
     {
         defaultImplementationSelector.AddAssembly(assembly);
     }
 }
示例#2
0
 /// <summary>
 /// This injects the current assembly into the DependencyImplementationSelector
 /// </summary>
 protected override void ConfigureDependencyImplentationSelector(ImplementationSelector defaultImplementationSelector)
 {
     base.ConfigureDependencyImplentationSelector(defaultImplementationSelector);
     defaultImplementationSelector.AddAssembly(typeof(ODataUnitTestModule).Assembly);
     defaultImplementationSelector.AddAssembly(typeof(ODataReaderTestCase).Assembly);
     // TODO: Consider adding this to the base if we find adding spatial to other test projects.
     defaultImplementationSelector.AddAssembly(typeof(SpatialClrTypeResolver).Assembly);
 }
 public ChallengeBootstrapperService(
     IServiceProvider services,
     IOptions <ConfigurationRoot> config,
     ImplementationSelector dsiSelector)
 {
     this.Services               = services;
     this.Configuration          = config.Value;
     this.ImplementationSelector = dsiSelector;
 }
示例#4
0
        /// <summary>
        /// Gets the available parameters for this test module.
        /// </summary>
        /// <returns>Array of <see cref="TestParameterInfo"/> that describes allowed test parameters for the test module.</returns>
        /// <remarks>The parameters are determined by scanning all Taupo and test assemblies
        /// and examining <see cref="InjectTestParameterAttribute"/>, <see cref="ImplementationSelectorAttribute"/>.
        /// </remarks>
        public TestParameterInfo[] GetAvailableParameters()
        {
            ImplementationSelector dis = new ImplementationSelector();

            this.ConfigureImplementationSelector(dis);

            HelpGenerator hg = new HelpGenerator(this.loggerResolver);

            return(hg.GetAvailableParameters(dis.Types));
        }
示例#5
0
        private void ShowHelp()
        {
            ImplementationSelector dis = new ImplementationSelector();

            this.ConfigureImplementationSelector(dis);

            HelpGenerator hg       = new HelpGenerator(this.loggerResolver);
            string        helpText = hg.GetHelpText(dis.Types);

            this.rootLogger.WriteLine(LogLevel.Info, helpText);
        }
示例#6
0
        private void ConfigureDependencyInjectionContainer()
        {
            this.dependencyInjector = this.moduleDependencyInjectionContainer = new LightweightDependencyInjectionContainer();
            var implementationSelector = new ImplementationSelector();

            this.ConfigureImplementationSelector(implementationSelector);
            var configurator = new DependencyInjectionConfigurator(implementationSelector, this.TestParameters);

            configurator.RootLogger = this.rootLogger;
            configurator.ConfigureDefaultDependencies(this.moduleDependencyInjectionContainer);
            this.ConfigureDependencies(this.moduleDependencyInjectionContainer);
            this.dependencyInjector.InjectDependenciesInto(this);
            configurator.InitializeGlobalObjects(this.moduleDependencyInjectionContainer);
        }
示例#7
0
        /// <summary>
        /// Injects default dependencies when Taupo runner is not being used
        /// </summary>
        protected void InjectDependencies()
        {
            var container = new LightweightDependencyInjectionContainer();

            ImplementationSelector defaultImplSelector = new ImplementationSelector();

            this.ConfigureDependencyImplentationSelector(defaultImplSelector);

            DependencyInjectionConfigurator dependInjecConfigurator = new DependencyInjectionConfigurator(defaultImplSelector, new Dictionary <string, string>());

            dependInjecConfigurator.ConfigureDefaultDependencies(container);

            this.ConfigureDependencies(container);

            // Configure MSTest only dependencies
            container.Register <Logger, TraceLogger>();

            container.RegisterInstance(container);
            container.InjectDependenciesInto(this);
        }
示例#8
0
        protected virtual void ConfigureMSTestDependencies(DependencyInjectionContainer container)
        {
            ImplementationSelector defaultImplSelector = new ImplementationSelector();

            this.ConfigureDependencyImplentationSelector(defaultImplSelector);

            DependencyInjectionConfigurator dependInjecConfigurator = new DependencyInjectionConfigurator(defaultImplSelector, new Dictionary <string, string>());

            dependInjecConfigurator.ConfigureDefaultDependencies(container);

            this.ConfigureDependencies(container);

            // Configure MSTest only dependencies
            container.Register <Logger, TraceLogger>();

            // Set test parameter ApplyTransform to false for ODL tests.
            container.TestParameters.Add("ApplyTransform", "false");

            container.RegisterInstance(container);
        }
示例#9
0
        /// <summary>
        /// Creates an instance of the ITestModuleRunner
        /// </summary>
        /// <param name="runnerType">The type of the runner to create</param>
        /// <returns>An implementation of the ITestModuleRunner </returns>
        public ITestModuleRunner CreateRunner(Type runnerType)
        {
            LightweightDependencyInjectionContainer dependencyInjectionContainer = null;
            ITestModuleRunner runner = null;

            try
            {
#if SILVERLIGHT
                runner = Activator.CreateInstance(runnerType) as ITestModuleRunner;
#else
                runner = new RunnerBridge(runnerType);
#endif
                dependencyInjectionContainer = new LightweightDependencyInjectionContainer();
                var implementationSelector = new ImplementationSelector();
                implementationSelector.AddAssembly(typeof(TestItem).GetAssembly());

                var helpGenerator       = new HelpGenerator(new LogLevelResolver(this.Parameters));
                var availableParameters = helpGenerator.GetAvailableParameters(implementationSelector.Types);
                Dictionary <string, string> availableParametersLookup = this.Parameters.Where(kvp => availableParameters.Any(p => p.ParameterName == kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                // Any TestParameters passed in are not used for injecting dependencies into RunnerBridge
                var configurator = new DependencyInjectionConfigurator(
                    implementationSelector,
                    availableParametersLookup);

                configurator.RootLogger = Logger.Null;
                configurator.ConfigureDefaultDependencies(dependencyInjectionContainer);

                dependencyInjectionContainer.InjectDependenciesInto(runner);
            }
            finally
            {
                if (dependencyInjectionContainer != null)
                {
                    dependencyInjectionContainer.Dispose();
                }
            }

            return(runner);
        }
 public void RegisterImplementationSelector(ImplementationSelector s)
 {
     implementationSelectors.Add(s);
 }
 public void RegisterImplementationSelector(ImplementationSelector s)
 {
     implementationSelectors.Add(s);
 }
 public ContainerConfigurationBuilder RegisterImplementationSelector(ImplementationSelector s)
 {
     RegistryBuilder.RegisterImplementationSelector(s);
     return(this);
 }
示例#13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHsts(opts =>
            {
                opts.Preload           = true;
                opts.IncludeSubDomains = true;
                opts.MaxAge            = TimeSpan.FromDays(365);
            });

            services.AddAntiforgery(x =>
            {
                x.Cookie.Name = "Rosetta-XSRF-Token";
                x.HeaderName  = "X-Rosetta-XSRF";
            });

            services.AddOptions <Data.ConfigurationRoot>()
            .Bind(this.Configuration)
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationDatastore>()
            .Bind(this.Configuration.GetSection("Database"))
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationCache>()
            .Bind(this.Configuration.GetSection("Cache"))
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationHttp>()
            .Bind(this.Configuration.GetSection("Http"))
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationHttpProxy>()
            .Bind(this.Configuration.GetSection("Http:ForwardHeaders"))
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationAuthentication>()
            .Bind(this.Configuration.GetSection("Authentication"))
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationOAuth>()
            .Bind(this.Configuration.GetSection("Authentication:OAuth"))
            .ValidateDataAnnotations();

            services.AddOptions <ConfigurationSecurity>()
            .Bind(this.Configuration.GetSection("KeyDerivation"))
            .ValidateDataAnnotations();

            services.AddAuthentication(JwtAuthenticationOptions.SchemeName)
            .AddScheme <JwtAuthenticationOptions, JwtAuthenticationHandler>(JwtAuthenticationOptions.SchemeName, opts => { });

            services.AddAuthorization();

            // Configure datastore providers
            var implSelector = new ImplementationSelector();

            services.AddSingleton(implSelector);
            implSelector.ConfigureCtfConfigurationLoaderProvider("yaml", services);
            implSelector.ConfigureDatabaseProvider(this.Configuration["Database:Type"], services);
            implSelector.ConfigureCacheProvider(this.Configuration["Cache:Type"], services);
            implSelector.ConfigureOAuthProviders(this.Configuration
                                                 .GetSection("Authentication:OAuth:Providers")
                                                 .Get <ConfigurationOAuthProvider[]>()
                                                 .Select(x => x.Type), services);

            services.AddTransient <UserPreviewRepository>()
            .AddTransient <ChallengePreviewRepository>()
            .AddSingleton <OAuthTokenHandler>()
            .AddSingleton <ActionTokenPairHandler>()
            .AddSingleton <HttpClient>()
            .AddSingleton <JwtHandler>()
            .AddTransient <PasswordHandler>()
            .AddSingleton <IdGenerator>()
            .AddTransient <IPasswordHashDeriver, Argon2idHashDeriver>()
            .AddTransient <IKeyDeriver, Pbkdf2KeyDeriver>()
            .AddSingleton <EnumDisplayConverter>()
            .AddTransient <IScoringModel, SlowLogisticDecayScoringModel>()
            .AddSingleton <OAuthConfigurationProvider>()
            .AddScoped <OAuthProviderSelector>()
            .AddScoped <LoginSettingsRepository>()
            .AddTransient <MfaValidatorService>()
            .AddScoped <ScoreCalculatorService>()
            .AddSingleton <ScoreLockService>();

            services.AddHostedService <ChallengeBootstrapperService>();

            // filters
            services.AddScoped <ValidRosettaUserFilter>()
            .AddScoped <OptionalRosettaUserFilter>()
            .AddScoped <EventNotStartedFilter>()
            .AddScoped <EventStartedFilter>()
            .AddScoped <EventNotOverFilter>();

#if !DEBUG
            services.AddControllers();

            foreach (var xsrfType in AbstractionUtilities.FindAntiforgeryFilters())
            {
                services.AddSingleton(xsrfType);
            }
#else
            services.AddControllersWithViews();
            services.AddSpaStaticFiles(cfg => cfg.RootPath = $"{this.SpaConfiguration.Root}/dist");
#endif
        }