public void MarkComplete() { if (IsComplete) { return; } IsComplete = true; HoursRemaining = 0; AggregateEvents.Raise(new TaskCompletedEvent(this)); }
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."); }
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()); }
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; } }