Ejemplo n.º 1
0
        public void Execute()
        {
            // Get a mock compiler
            ICompiler compiler = CreateMockCompiler();

            IronPythonCompilerTask task = new IronPythonCompilerTask(compiler);
            // Create a fake engine as the logger will call into it
            Type     engineType = GenericMockFactory.CreateType("MockBuildEngine", new Type[] { typeof(Microsoft.Build.Framework.IBuildEngine) });
            BaseMock mockEngine = (BaseMock)Activator.CreateInstance(engineType);

            task.BuildEngine = (Microsoft.Build.Framework.IBuildEngine)mockEngine;

            // Set parameters
            task.SourceFiles   = new string[] { "Foo.py", "bar.py" };
            task.TargetKind    = "exe";
            task.MainFile      = "Foo.py";
            task.ResourceFiles = null;
            Microsoft.Build.Framework.ITaskItem[] resources = new Microsoft.Build.Framework.ITaskItem[1];
            resources[0]       = new Microsoft.Build.Utilities.TaskItem(@"obj\i386\form1.resources");
            task.ResourceFiles = resources;
            // Execute
            bool result = task.Execute();

            // Validation
            Assert.IsTrue(result);
            BaseMock mock = (BaseMock)compiler;

            Assert.AreEqual(PEFileKinds.ConsoleApplication, mock["TargetKind"]);
            Assert.AreEqual(task.MainFile, mock["MainFile"]);
        }
Ejemplo n.º 2
0
        private static ICompiler CreateMockCompiler()
        {
            Type     compilerType = GenericMockFactory.CreateType("MockCompiler", new Type[] { typeof(ICompiler) });
            BaseMock mockCompiler = (BaseMock)Activator.CreateInstance(compilerType);
            string   name         = string.Format("{0}.{1}", typeof(ICompiler).FullName, "set_SourceFiles");

            mockCompiler.AddMethodCallback(name, new EventHandler <CallbackArgs>(SourceFilesCallBack));
            name = string.Format("{0}.{1}", typeof(ICompiler).FullName, "set_OutputAssembly");
            mockCompiler.AddMethodCallback(name, new EventHandler <CallbackArgs>(OutputAssemblyCallBack));
            name = string.Format("{0}.{1}", typeof(ICompiler).FullName, "set_ReferencedAssemblies");
            mockCompiler.AddMethodCallback(name, new EventHandler <CallbackArgs>(ReferencedAssembliesCallBack));
            name = string.Format("{0}.{1}", typeof(ICompiler).FullName, "set_MainFile");
            mockCompiler.AddMethodCallback(name, new EventHandler <CallbackArgs>(MainFileCallBack));
            name = string.Format("{0}.{1}", typeof(ICompiler).FullName, "set_IncludeDebugInformation");
            mockCompiler.AddMethodCallback(name, new EventHandler <CallbackArgs>(IncludeDebugInformationCallBack));
            name = string.Format("{0}.{1}", typeof(ICompiler).FullName, "set_TargetKind");
            mockCompiler.AddMethodCallback(name, new EventHandler <CallbackArgs>(TargetKindCallBack));

            return((ICompiler)mockCompiler);
        }