Exemple #1
0
        public void GivenATaskWithTheFollowingAttributes(Table table)
        {
            var task = new Task();

            foreach (var row in table.Rows)
            {
                var prop = row["Property"];
                var stringVal = row["Value"];

                var pi = task.GetType().GetProperty(prop, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                object val;
                if (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
                {
                    var nonNullableType = pi.PropertyType.GetGenericArguments().First();

                    val = Convert.ChangeType(stringVal, nonNullableType, CultureInfo.GetCultureInfo("nb-no"));

                    val = Activator.CreateInstance(pi.PropertyType, new object[] {val});
                }
                else
                {
                    val = Convert.ChangeType(stringVal, pi.PropertyType, CultureInfo.GetCultureInfo("nb-no"));
                }

                pi.SetValue(task, val, null);
            }
            using (var repos = _context.Get<IRepository<Task>>())
            {
                repos.Save(task);
            }
            _context.Publish(new DatabaseChanged(@"C:\foo\bar.taskboard"));
        }
 private static string DumpImportantLinks(Task task)
 {
     return task.Title + " LessImportantTasks: " + DumpLinks(task.LessImportantTasks) +
            Environment.NewLine +
            task.Title + " MoreImportantTasks: " + DumpLinks(task.MoreImportantTasks) +
            Environment.NewLine +
            task.Title + " Subtasks: " + DumpLinks(task.SubTasks) +
            Environment.NewLine +
            task.Title + " Parent: " + task.Parent ?? "";
 }
Exemple #3
0
        public TaskViewModel(Task task, Func<Task, TaskViewModel> viewModelMapper)
        {
            _task = task;
            _viewModelMapper = viewModelMapper;
            _isEditing = false;
            _isVisible = true;

            var cmd = new ReactiveCommand();
            cmd.Subscribe(_ => ToggleCollapseHierarchy());

            ToggleCollapseHierarchyCommand = cmd;
        }
Exemple #4
0
        private Task CreateRandomTask()
        {
            DateTimeHelper.MoveAheadBy(TimeSpan.FromMinutes(_random.Next(50)));

            var task = new Task {Title = Guid.NewGuid().ToString()};

            DateTimeHelper.MoveAheadBy(TimeSpan.FromMinutes(_random.Next(50)));

            if (DateTime.Now.Ticks % 2 == 0)
            {
                task.Start();
            }

            DateTimeHelper.MoveAheadBy(TimeSpan.FromMinutes(_random.Next(50)));

            if (DateTime.Now.Ticks % 3 == 0)
            {
                task.Complete();
            }

            DateTimeHelper.MoveAheadBy(TimeSpan.FromMinutes(_random.Next(50)));

            if (DateTime.Now.Ticks % 4 == 0)
            {
                task.Abandon();
            }

            return task;
        }
Exemple #5
0
        private static void CheckDates(Task oldTask, Task newTask, IEnumerable<Expression<Func<Task, object>>> dateFuncs)
        {
            foreach (var expression in dateFuncs)
            {
                var func = expression.Compile();
                var oldDate = (DateTime?) func(oldTask);
                var newDate = (DateTime?) func(newTask);

                if (oldDate == null)
                {
                    newDate.Should().Be(null);
                }
                else
                {
                    oldDate.Should().BeWithin(TimeSpan.FromSeconds(0.5)).Before(newDate.GetValueOrDefault());
                }
            }
        }
Exemple #6
0
 private TaskViewModel ViewModelMapper(Task task)
 {
     return Tasks.FirstOrDefault(vm => vm.Task == task);
 }
Exemple #7
0
        private void OnCreateNewTask(CreateNewTask ignored)
        {
            var task = new Task();

            _repository.InsertNew(task);

            var taskViewModel = new TaskViewModel(task, ViewModelMapper);
            Tasks.Insert(0, taskViewModel);
            _tasks.Add(task);

            if (SelectedTask != null)
            {
                SelectedTask.Deselect();
            }

            SelectedTask = taskViewModel;
            taskViewModel.BeginEdit();
        }
Exemple #8
0
        public void GivenILoadATaskboardWithTheFollowingTasksAndSubtasks(Table table)
        {
            Given("that I have created a new database");

            using (var repos = _context.Get<IRepository<Task>>())
            {
                var tasks = new List<Task>();
                foreach (var tableRow in table.Rows)
                {
                    DateTimeHelper.MoveAheadBy(TimeSpan.FromSeconds(-5));
                    var task = new Task { Title = tableRow["Title"] };

                    var subtasks = tableRow["Subtasks"].Split(';');
                    foreach (var subtaskTitle in subtasks)
                    {
                        var subtask = task.CreateSubTask();

                        subtask.Title = subtaskTitle;
                        tasks.Add(subtask);
                    }
                    tasks.Add(task);
                }
                repos.SaveAll(tasks);
            }
            _context.Publish(new DatabaseChanged(@"C:\foo\bar.taskboard"));
        }
Exemple #9
0
 public Link(Task linkTo, LinkType type)
 {
     LinkTo = linkTo;
     Type = type;
 }
Exemple #10
0
        private void AddLink(Task otherTask, LinkType type)
        {
            var existingLink = Links.FirstOrDefault(link => link.LinkTo == otherTask);

            if (existingLink != null)
            {
                if (existingLink.Type == type)
                {
                    return;
                }
                Links.Remove(existingLink);
            }

            Links.Add(new Link(otherTask, type));
        }
Exemple #11
0
 public virtual void IsMoreImportantThan(Task otherTask)
 {
     if (!CanBeMoreImportantThan(otherTask))
     {
         throw new InvalidOperationException(String.Format("Cannot make {0} more important than {1}", this, otherTask));
     }
     AddLink(otherTask, LinkType.MoreImportantThan);
     otherTask.AddLink(this, LinkType.LessImportantThan);
 }
Exemple #12
0
 public virtual void IsLessImportantThan(Task otherTask)
 {
     AddLink(otherTask, LinkType.LessImportantThan);
     otherTask.AddLink(this, LinkType.MoreImportantThan);
 }
Exemple #13
0
        public virtual Task CreateSubTask()
        {
            var subTask = new Task();
            AddLink(subTask, LinkType.Child);
            subTask.AddLink(this, LinkType.Parent);

            return subTask;
        }
Exemple #14
0
        public virtual bool CanBeMoreImportantThan(Task otherTask)
        {
            if (Parent != null && otherTask.Parent == null)
            {
                return false;
            }
            if (otherTask.LessImportantTasks.Contains(this))
            {
                return true;
            }

            if (otherTask.LessImportantTasksTransitively().FirstOrDefault(t => t == this) != null)
            {
                return false;
            }

            return true;
        }