Example #1
0
        /*public ITaskService TaskProvider
        {
            get
            {
                if (this.taskProvider == null)
                {
                    try
                    {
                        //taskProvider = ApplicationContext.TaskService;
                        //taskProvider = new TaskProvider;
                        throw new NotImplementedException("implement a TaskProvider");
                    }
                    catch (Exception ex)
                    {
                        // MessageBox.Show("TaskProvider f*****g: " + ex.ToString());
                        throw;
                    }
                }
                return this.taskProvider;
            }

            internal set
            {
                this.taskProvider = value;
            }
        }*/
        /// <summary>
        /// Modifies the task data.
        /// </summary>
        /// <param name="log">The logging callback.</param>
        /// <param name="taskAction">The action to perform with the new task. A
        /// return value of <c>false</c> indicates that the modification shouldn't
        /// persisted.</param>
        public void ModifyTaskData(Action<string> log, Func<ITask, bool?> taskAction)
        {
            // ITaskService taskProvider = TaskContext.Default;
            var logger = new LogHelper(log);
            using (this.tse = new TaskSetupEngine(logger, this.Path))
            {
                var task = this.tse.InitTaskEditor(this.Task.TypeName, this.Task.AnyAttr);

                // var task = InitTaskEditor(this.taskProvider);
                if (taskAction != null)
                {
                    var result = taskAction(task);
                    if ((!result.HasValue || !result.Value) && log != null)
                    {
                        log("Task modification canceled");
                    }
                }

                // this.Task.TaskInstance = task;
                // var wnd = ControlRegistrator.GetInstanceOfType<Window>(WindowTypes.TaskEditor);
                // var wnd = ApplicationContext.TaskWizardProvider.GetTaskEditor();
                // wnd.DataContext = this;
                // wnd.DataContext = task;
                // this.Task.PropertyChanged += Task_PropertyChanged;
                // var result = wnd.ShowDialog();
                // this.Task.PropertyChanged -= Task_PropertyChanged;
                this.tse.AfterTask(task, this.Task.AnyAttr);
            }
        }
Example #2
0
        public void AfterTask()
        {
            // Setup mocks
            // LogHelper should subscribe to the events of IEventSource.
            // Expect.Call(delegate { eventSource.MessageRaised += null; }).Constraints(Is.NotNull());
            // Expect.Call(delegate { eventSource.WarningRaised += null; }).Constraints(Is.NotNull());
            // Expect.Call(delegate { eventSource.ErrorRaised += null; }).Constraints(Is.NotNull());
            // Expect.Call(() => logger.Initialize(null));
            // logger.Initialize(null);

            // Expect.Call(delegate { logger.Initialize(null); }).Constraints(Is.TypeOf<EventSource>()).CallOriginalMethod(OriginalCallOptions.CreateExpectation);
            // Expect.Call(delegate { logger.Log(null, (BuildMessageEventArgs)null); }).Constraints(Is.TypeOf<TaskSetupEngine>(), Is.NotNull() && Property.Value("Message", "Initialized")).CallOriginalMethod(OriginalCallOptions.CreateExpectation);
            var task = this.mocks.StrictMock<ITask>();
            var taskAttributes = new List<XmlAttribute>();

            var doc = new XmlDocument();
            var attr = doc.CreateAttribute("TestAttribute");
            attr.Value = "TheValue";
            taskAttributes.Add(attr);

            var testObject = new TaskSetupEngine(this.blogger, this.paths);
            this.blogger.BackToRecord();
            this.mocks.ReplayAll();

            testObject.AfterTask(task, taskAttributes);

            this.mocks.VerifyAll();
        }
Example #3
0
        /// <summary>
        /// Runs the task represented by this instance.
        /// </summary>
        /// <param name="log">The logging callback.</param>
        public void RunTask(Action<string> log)
        {
            // ITaskService taskProvider = TaskContext.Default;
            if (!this.IsEnabled)
            {
                return;
            }

            try
            {
                var logger = new LogHelper(log);
                this.tse = new TaskSetupEngine(logger, this.Path);
                {
                    // using (var tse = new TaskSetupEngine(taskProvider, logger, this.Path, this.Task))
                    var bg = new BackgroundWorker();
                    bg.DoWork += (args, e) =>
                                     {
                                         var success = this.tse.ExecuteTask(this.Task.TypeName, this.Task.AnyAttr);
                                         if (log != null)
                                         {
                                             log("Finished Task: " + success);
                                         }
                                     };
                    bg.RunWorkerCompleted += (e, x) => this.tse.Dispose();
                    bg.RunWorkerAsync();
                }
            }
            catch (Exception e)
            {
                if (log != null)
                {
                    log("Exception: " + e);
                }
            }
        }
Example #4
0
        public void Construction()
        {
            Expect.Call(() => this.blogger.LogBuildMessage(null, null, null))
                .Constraints(
                Is.TypeOf<TaskSetupEngine>(),
                Is.NotNull(),
                Is.Equal("Initialized"));

            this.mocks.ReplayAll();

            var testObject = new TaskSetupEngine(this.blogger, this.paths);

            this.mocks.VerifyAll();
            Assert.IsNotNull(testObject.DefaultBuildEngine);
        }
Example #5
0
        public void PropertyIsDisposed()
        {
            var testObject = new TaskSetupEngine(this.blogger, this.paths);
            var expected = false;
            var actual = testObject.IsDisposed;
            Assert.AreEqual(expected, actual);

            expected = true;
            testObject.Dispose();
            actual = testObject.IsDisposed;
            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void ExecuteTask()
        {
            // Setup mocks
            // LogHelper should subscribe to the events of IEventSource.
            // Expect.Call(delegate { eventSource.MessageRaised += null; }).Constraints(Is.NotNull());
            // Expect.Call(delegate { eventSource.WarningRaised += null; }).Constraints(Is.NotNull());
            // Expect.Call(delegate { eventSource.ErrorRaised += null; }).Constraints(Is.NotNull());
            // Expect.Call(() => logger.Initialize(null));
            // logger.Initialize(null);
            var testObject = new TaskSetupEngine(this.blogger, this.paths);
            this.blogger.BackToRecord();

            Expect.Call(delegate { this.blogger.RegisterLogger(null); })
                .Constraints(Is.NotNull())
                .Repeat.Once()
                //.CallOriginalMethod(OriginalCallOptions.CreateExpectation)
                ;

            /*Expect.Call(delegate { this.logger.Log(null, (BuildMessageEventArgs)null); })
                .Constraints(
                    Is.TypeOf<Engine>(),
                    Is.NotNull()
                ).Repeat.Times(5)
                .CallOriginalMethod(OriginalCallOptions.CreateExpectation)
                ;*/

            /*Expect.Call(delegate { logger.Log(null, (BuildMessageEventArgs)null); })
                .Constraints(
                Is.TypeOf<TaskSetupEngine>(),
                Is.NotNull()
                ).Repeat.Times(0)
                .CallOriginalMethod(OriginalCallOptions.CreateExpectation)
                ;*/

            /*
            Expect.Call(delegate { logger.Log(null, (BuildErrorEventArgs)null); })
                .Constraints(
                Is.TypeOf<Microsoft.Build.BuildEngine.Engine>(),
                Is.NotNull()
                ).Repeat.Any()
                .CallOriginalMethod(OriginalCallOptions.CreateExpectation);
            */
            // var task = mocks.StrictMock<ITask>();
            var taskAttributes = new List<XmlAttribute>();

            // var engine = mocks.Stub<Engine>("");
            // testObject.DefaultBuildEngine = engine;

            // var project = mocks.StrictMock<Project>();
            // Expect.Call(engine.CreateNewProject()).Return(project);
            // theOnlyTask.Expect(t => t.Execute());
            this.mocks.ReplayAll();

            // var testObject = new TaskSetupEngine(logger, paths);
            // logger.BackToRecord();
            // logger.Replay();
            testObject.ExecuteTask("NameNotRelevant", taskAttributes);

            Assert.IsTrue(TestTask.HasExecuted);
            Assert.AreEqual(1, TestTask.Instantiated);
            Assert.IsNotNull(TestTask.MyBuildEngine);
            Assert.IsNull(TestTask.MyHostObject);

            this.mocks.VerifyAll();

            // Assert.EndsWith(resultOfLogHelper, "Initialized");
        }
Example #7
0
 public void DisposeTheTestObject()
 {
     var testObject = new TaskSetupEngine(this.blogger, this.paths);
     testObject.Dispose();
     Assert.Throws<InvalidOperationException>(() => testObject.Dispose());
 }
Example #8
0
        public void ConstructionXXX()
        {
            string resultOfLogHelper = string.Empty;
            Action<string> logMethod = (log) => resultOfLogHelper += log;
            var logger = new TestLogger(logMethod);

            this.mocks.ReplayAll();
            var testObject = new TaskSetupEngine(logger, this.paths);
            Assert.EndsWith(resultOfLogHelper, "Initialized");

            this.mocks.VerifyAll();
        }
Example #9
0
        public void ConstructionWithoutLogger()
        {
            this.mocks.ReplayAll();
            var testObject = new TaskSetupEngine(this.paths);

            // Assert.IsNotNull(testObject.
            this.mocks.VerifyAll();
        }