/// <exception cref="UnknownPriorityException">Condition.</exception> /// <exception cref="TaskWithSameTitleExistsInProjectException">Condition.</exception> public void Handle(RegisterTask command) { var title = new Title(command.Title); var projectId = new ProjectId(command.ProjectId); TaskPriority priority; if (!TaskPriority.TryParse(command.Priority, out priority)) { throw new UnknownPriorityException(command.Priority); } Task task; if (command.Deadline.HasValue) { var deadline = new TaskDeadline(command.Deadline.Value); task = new Task(projectId, title, priority, deadline); } else { task = new Task(projectId, title, priority); } var query = new DoesTaskWithTitleAlreadyExistUnderSameProjectQuery(title, projectId); bool taskWithSameTitleExists = _taskQueryHandler.Handle(query); if (taskWithSameTitleExists) { throw new TaskWithSameTitleExistsInProjectException(); } _eventStoreRepository.Save(task); }
/// <exception cref="DeadlineIsInThePastException">Condition.</exception> public void Handle(ChangeDeadlineOnTask command) { Task task = _eventStoreRepository.GetById(command.Id); var newDeadline = new TaskDeadline(command.Deadine); task.ChangeDeadline(newDeadline); _eventStoreRepository.Save(task); }
public void Register_Task_With_Deadline_Can_Be_Saved_In_Event_Store() { var title = new Title(Fixture.Create <string>()); var deadline = new TaskDeadline(DateTime.UtcNow); var task = new Task(_projectId, title, TaskPriority.Low, deadline); _eventStoreRepository.Save(task); Task taskFromEventStore = _eventStoreRepository.GetById(task.Id); Assert.That(taskFromEventStore, Is.Not.Null); }
public void Task_With_Note_Can_Be_Saved_In_Event_Store() { var projectId = new ProjectId(Fixture.Create <string>()); var title = new Title(Fixture.Create <string>()); var deadline = new TaskDeadline(DateTime.UtcNow); var task = new Task(projectId, title, TaskPriority.Low, deadline); task.SaveNote(new Note(Fixture.Create <string>())); var eventStoreRepository = new EventStoreRepository <Task>(EventBus, InMemoryEventStoreConnectionBuilder); eventStoreRepository.Save(task); Task taskFromEventStore = eventStoreRepository.GetById(task.Id); Assert.That(taskFromEventStore, Is.Not.Null); }