Ejemplo n.º 1
0
            public void Should_Replace_Arguments_If_New_Ones_Are_Set()
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                arguments.SetArguments(new Dictionary <string, string> {
                    { "C", "D" }, { "D", "E" }
                });

                // Then
                Assert.Equal(2, arguments.Arguments.Count);
            }
Ejemplo n.º 2
0
            public void Should_Only_Set_Arguments_If_Argument_Collection_Is_Empty()
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                arguments.SetArguments(new Dictionary <string, string> {
                    { "C", "D" }, { "D", "E" }
                });

                // Then
                Assert.Equal(1, arguments.Arguments.Count);
            }
Ejemplo n.º 3
0
            public void Should_Set_Arguments()
            {
                // Given
                var arguments = new CakeArguments();

                // When
                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // Then
                Assert.Equal(1, arguments.Arguments.Count);
            }
Ejemplo n.º 4
0
            public void Should_Return_Argument_Exist(string key, string expected)
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                var result = arguments.GetArgument(key);

                // Then
                Assert.Equal(expected, result);
            }
Ejemplo n.º 5
0
            public void Should_Be_Case_Insensitive(string key, bool expected)
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                var result = arguments.HasArgument(key);

                // Then
                Assert.Equal(expected, result);
            }
Ejemplo n.º 6
0
        public void Run(CakeOptions options)
        {
            // Initialize the script session factory.
            _sessionFactory.Initialize();

            // Copy the arguments from the options.
            _arguments.SetArguments(options.Arguments);

            // Create and prepare the session.
            var session = _sessionFactory.CreateSession(_host);

            // Process the script.
            var context = new ScriptProcessorContext();

            _processor.Process(options.Script, context);

            // Set the working directory.
            _environment.WorkingDirectory = options.Script.MakeAbsolute(_environment).GetDirectory();

            // Load all references.
            var assemblies = new List <Assembly>();

            assemblies.AddRange(GetDefaultAssemblies());
            foreach (var reference in context.References)
            {
                if (_fileSystem.Exist((FilePath)reference))
                {
                    var assembly = Assembly.LoadFile(reference);
                    assemblies.Add(assembly);
                }
                else
                {
                    // Add a reference to the session.
                    session.AddReferencePath(reference);
                }
            }

            // Got any assemblies?
            if (assemblies.Count > 0)
            {
                // Find all extension methods and generate proxy methods.
                _aliasGenerator.GenerateScriptAliases(context, assemblies);

                // Add assembly references to the session.
                foreach (var assembly in assemblies)
                {
                    session.AddReference(assembly);
                }
            }

            // Import all namespaces.
            var namespaces = new List <string>(context.Namespaces);

            namespaces.AddRange(GetDefaultNamespaces());
            foreach (var @namespace in namespaces.OrderBy(ns => ns))
            {
                session.ImportNamespace(@namespace);
            }

            // Execute the script.
            session.Execute(context.GetScriptCode());
        }