Exemple #1
0
 public void MarkComplete()
 {
     if (IsComplete)
     {
         return;
     }
     IsComplete     = true;
     HoursRemaining = 0;
     AggregateEvents.Raise(new TaskCompletedEvent(this));
 }
Exemple #2
0
        public void DeleteTask(Guid id)
        {
            var taskToDelete = _tasks.SingleOrDefault(t => t.Id == id);

            if (taskToDelete == null)
            {
                return;
            }
            _tasks.Remove(taskToDelete);

            // why raise this event here?
            // TODO: Replace with Domain Event?
            AggregateEvents.Raise(new TaskDeletedEvent(taskToDelete));
            Log($"{taskToDelete.Name} deleted.");
        }
Exemple #3
0
        public void HandleOwnTaskCompletedEventOnly()
        {
            AggregateEvents.ClearCallbacks();
            var    project  = new Project();
            string taskName = Guid.NewGuid().ToString();

            project.AddTask(taskName, 1);

            // project 2 has no tasks assigned to it.
            var project2 = new Project();

            AggregateEvents.Raise(new TaskCompletedEvent(project.Tasks.First()));

            Assert.Contains(taskName, project.ToString());
            Assert.DoesNotContain(taskName, project2.ToString());
        }
Exemple #4
0
        public void UpdateHoursRemaining(int hours)
        {
            if (hours < 0)
            {
                return;
            }
            int currentHoursRemaining = HoursRemaining;

            try
            {
                HoursRemaining = hours;
                if (HoursRemaining == 0)
                {
                    MarkComplete();
                    return;
                }
                IsComplete = false;
                AggregateEvents.Raise(new TaskHoursUpdatedEvent(this));
            }
            catch (Exception)
            {
                HoursRemaining = currentHoursRemaining;
            }
        }