Exemple #1
0
        public void ShouldGetParentTasks()
        {
            var connector = new Mock <ITaskDataConnector>();

            connector.Setup(m => m.GetAllParentTasks(It.IsAny <int>())).Returns(tasks);
            var process = new TaskManagerProcess(connector.Object);
            var result  = process.GetParentTasks(1);

            Assert.IsNotNull(result);
            Assert.AreEqual(tasks.Count(), result.Count());
        }
Exemple #2
0
        public void ShouldNotGetTaskByTaskId()
        {
            var taskId    = 0;
            var connector = new Mock <ITaskDataConnector>();

            connector.Setup(m => m.GetTaskById(It.IsAny <int>())).Returns <int>(
                id => { return(tasks.FirstOrDefault(t => t.ID == id)); });
            var process = new TaskManagerProcess(connector.Object);
            var result  = process.GetTaskByTaskId(taskId);

            Assert.IsNull(result);
        }
Exemple #3
0
        public void ShouldNotDeleteTasks()
        {
            var connector = new Mock <ITaskDataConnector>();

            connector.Setup(m => m.GetAllTasks()).Returns(tasks);
            connector.Setup(m => m.DeleteTask(It.IsAny <int>()));
            var process = new TaskManagerProcess(connector.Object);
            var result  = process.DeleteTask(0);

            Assert.IsNotNull(result);
            Assert.AreEqual(false, result);
        }
Exemple #4
0
        public void ShouldNotUpdateTasks()
        {
            var connector = new Mock <ITaskDataConnector>();

            connector.Setup(m => m.GetAllTasks()).Returns(tasks);
            connector.Setup(m => m.EditTask(It.IsAny <Task>()));
            var process = new TaskManagerProcess(connector.Object);
            var result  = process.EditTask(new Entities.Task {
                Id = 0
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(false, result);
        }
Exemple #5
0
        public void ShouldAddTasks()
        {
            var newTaskId = new Random().Next(4, 10);
            var connector = new Mock <ITaskDataConnector>();

            connector.Setup(m => m.GetAllTasks()).Returns(tasks);
            connector.Setup(m => m.AddTask(It.IsAny <Task>())).Callback <Task>(t => { t.ID = newTaskId; });
            var process = new TaskManagerProcess(connector.Object);
            var result  = process.AddTask(new Entities.Task {
                Id = 0, Name = "New-Task"
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(true, result);
        }
        public IEnumerable <TaskManagerProcess> GetAllProcesses()
        {
            LinkedList <TaskManagerProcess> taskManagerProcesses = new LinkedList <TaskManagerProcess>();

            foreach (Process p in Process.GetProcesses())
            {
                PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", p.ProcessName, true);

                try
                {
                    float  cpu    = cpuCounter.NextValue();
                    double memory = p.PrivateMemorySize64 / 1000000;


                    TaskManagerProcess taskManagerProcess = new TaskManagerProcess();
                    taskManagerProcess.TMProcessId   = p.Id.ToString();
                    taskManagerProcess.TMProcessName = p.ProcessName;
                    try { taskManagerProcess.TMPriority = p.PriorityClass.ToString(); }catch (Exception) { taskManagerProcess.TMPriority = "Unidentified"; }
                    try{ taskManagerProcess.TMPath = p.MainModule.FileName.ToString(); }catch (Exception) { taskManagerProcess.TMPath = "Unidentified"; }

                    //TMProcessCpuUsage = string.Format("{0.00}", cpuCounter.NextValue()).ToString() + "%",
                    //TMProcessMemoryUsage = string.Format("{0.00}", ((p.PrivateMemorySize64) / sumMemory) * 100) + "%",
                    taskManagerProcess.TMProcessCpuUsage    = cpu.ToString() + "%";
                    taskManagerProcess.TMProcessMemoryUsage = memory.ToString().Substring(0, 3) + " MB";

                    //taskManagerProcess.TMProcessDescription = p.MainModule.FileVersionInfo.FileDescription;

                    taskManagerProcesses.AddLast(taskManagerProcess);
                }
                catch (Exception e)
                {
                    continue;
                }
            }

            return(taskManagerProcesses);
        }