private ScriptServices CreateScriptServices()
        {
            var console     = new ScriptConsole();
            var logProvider = new ColoredConsoleLogProvider(LogLevel.Info, console);

            var initializationServices = new InitializationServices(logProvider);

            initializationServices.GetAppDomainAssemblyResolver().Initialize();

            var scriptServicesBuilder = new ScriptServicesBuilder(console, logProvider, null, null, initializationServices);

            scriptServicesBuilder.Overrides[typeof(IFileSystem)] = _options.FileSystem;
            scriptServicesBuilder.LoadScriptPacks();
            scriptServicesBuilder.LoadModules(".csx", _options.Modules);

            var scriptServices = scriptServicesBuilder.Build();

            var assemblies = scriptServices.AssemblyResolver.GetAssemblyPaths(_options.FileSystem.CurrentDirectory, true);
            var packs      = scriptServices.ScriptPackResolver.GetPacks();

            scriptServices.Executor.Initialize(assemblies, packs, _options.ScriptArgs);
            scriptServices.Executor.AddReferences(typeof(Attribute), typeof(ExportAttribute));
            scriptServices.Executor.ImportNamespaces("System.ComponentModel.Composition");

            if (_options.References != null)
            {
                scriptServices.Executor.AddReferenceAndImportNamespaces(_options.References);
            }

            return(scriptServices);
        }
 public void ShouldNotLoadScriptPacksIfLoadScriptPacksIsFalse(IConsole console, TestLogProvider logProvider, IScriptEngine engine)
 {
     var builder = new ScriptServicesBuilder(console, logProvider);
     builder.Overrides[typeof(IScriptEngine)] = engine.GetType();
     builder.LoadScriptPacks(false);
     builder.Build();
     var runtimeServices = (RuntimeServices)builder.RuntimeServices;
     runtimeServices.InitDirectoryCatalog.ShouldBeFalse();
 }
Exemple #3
0
            public void ShouldNotLoadScriptPacksIfLoadScriptPacksIsFalse(IConsole console, TestLogProvider logProvider, IScriptEngine engine)
            {
                var builder = new ScriptServicesBuilder(console, logProvider);

                builder.Overrides[typeof(IScriptEngine)] = engine.GetType();
                builder.LoadScriptPacks(false);
                builder.Build();
                var runtimeServices = (RuntimeServices)builder.RuntimeServices;

                runtimeServices.InitDirectoryCatalog.ShouldBeFalse();
            }
            public void ShoulLoadScriptPacksIfLoadScriptPacksIsTrue(IConsole console, TestLogProvider logProvider)
            {
                var builder = new ScriptServicesBuilder(console, logProvider);

                builder.Overrides[typeof(IScriptEngine)] = typeof(MockScriptEngine);
                builder.LoadScriptPacks();
                builder.Build();
                var runtimeServices = (RuntimeServices)builder.RuntimeServices;

                runtimeServices.InitDirectoryCatalog.ShouldBeTrue();
            }