public void TaskCancelledEvent() { var taskId = Guid.NewGuid(); var e = new TaskCancelledEvent() { DateOfCancellation = DateTime.Now, TaskId = taskId }; var task = OTask.Factory.Create(taskId, "Fake"); task.ApplyEvent(e); Assert.Equal(e.DateOfCancellation, task.DateOfCancellation); }
public void Cancel(Guid userId) { if (userId != this.CreatorId) { throw new ArgumentException("A task can be cancelled by its creator only", nameof(userId)); } if (this.DateOfCompletion.HasValue) { throw new InvalidOperationException("Can't cancel a closed task."); } if (this.DateOfCancellation.HasValue) { throw new InvalidOperationException("Can't cancel a task twice."); } var e = new TaskCancelledEvent() { TaskId = this.Id, DateOfCancellation = DateTime.Now, UserId = userId }; RaiseEvent(e); }
public void ApplyEvent(TaskCancelledEvent @event) { this.DateOfCancellation = @event.DateOfCancellation; }