public async void UsesUserFirstAndLastNameAsSubjectWhenProvided() { const int taskSignupId = 1001; const int taskId = 12314; const string email = "*****@*****.**"; const string firstName = "Simon"; const string lastName = "Says"; const string userEmail = "*****@*****.**"; var mediator = new Mock <IMediator>(); var options = new Mock <IOptions <GeneralSettings> >(); options.Setup(o => o.Value).Returns(new GeneralSettings { SiteBaseUrl = "allready.com" }); var notification = new TaskSignupStatusChanged { SignupId = taskSignupId }; var taskSignup = CreateTaskSignup(taskSignupId, taskId, email, firstName, lastName, userEmail); Context.TaskSignups.Add(taskSignup); Context.SaveChanges(); var target = new NotifyAdminForTaskSignupStatusChangeHandler(Context, mediator.Object, options.Object); await target.Handle(notification); mediator.Verify(x => x.SendAsync(It.Is <NotifyVolunteersCommand>(y => y.ViewModel.Subject == $"{firstName} {lastName}"))); }
public async void PassANotifyVolunteersCommandToTheMediatorWhenEmailIsProvided() { const int taskSignupId = 1001; const int taskId = 12314; const string email = "*****@*****.**"; const string userMail = "*****@*****.**"; var mediator = new Mock <IMediator>(); var options = new Mock <IOptions <GeneralSettings> >(); options.Setup(o => o.Value).Returns(new GeneralSettings { SiteBaseUrl = "allready.com" }); var notification = new TaskSignupStatusChanged { SignupId = taskSignupId }; var context = Context; var taskSignup = CreateTaskSignup(taskSignupId, taskId, email, userMail: userMail); context.TaskSignups.Add(taskSignup); context.SaveChanges(); var target = new NotifyAdminForTaskSignupStatusChangeHandler(context, mediator.Object, options.Object); await target.Handle(notification); mediator.VerifyAll(); }
public async void UsesUserFirstAndLastNameAsSubjectWhenProvided() { const int taskSignupId = 1001; const int taskId = 12314; const string email = "*****@*****.**"; const string firstName = "Simon"; const string lastName = "Says"; const string userEmail = "*****@*****.**"; var mediator = new Mock <IMediator>(); NotifyVolunteersViewModel viewModel = null; mediator.Setup(m => m.SendAsync(It.IsAny <NotifyVolunteersCommand>())) .ReturnsAsync(new Unit()) .Callback <IAsyncRequest>(request => viewModel = ((NotifyVolunteersCommand)request).ViewModel); var options = new Mock <IOptions <GeneralSettings> >(); options.Setup(o => o.Value).Returns(new GeneralSettings { SiteBaseUrl = "allready.com" }); var notification = new TaskSignupStatusChanged { SignupId = taskSignupId }; var context = Context; var taskSignup = CreateTaskSignup(taskSignupId, taskId, email, firstName, lastName, userEmail); context.TaskSignups.Add(taskSignup); context.SaveChanges(); var target = new NotifyAdminForTaskSignupStatusChangeHandler(context, mediator.Object, options.Object); await target.Handle(notification); mediator.VerifyAll(); viewModel.Subject.ShouldBe($"{firstName} {lastName}"); }
public async void NotPassANotifyVolunteersCommandToTheMediatorWhenCampaignContactsIsNull() { const int taskSignupId = 1001; const int taskId = 12314; var mediator = new Mock <IMediator>(); var options = new Mock <IOptions <GeneralSettings> >(); var notification = new TaskSignupStatusChanged { SignupId = taskSignupId }; var context = Context; var taskSignup = CreateTaskSignupWithoutCampaignContacts(taskSignupId, taskId); context.TaskSignups.Add(taskSignup); context.SaveChanges(); var target = new NotifyAdminForTaskSignupStatusChangeHandler(context, mediator.Object, options.Object); await target.Handle(notification); mediator.Verify(m => m.SendAsync(It.IsAny <NotifyVolunteersCommand>()), Times.Never); }
public TaskChangeResult Handle(TaskStatusChangeCommand message) { var task = GetTask(message); if (task == null) { throw new InvalidOperationException($"Task {message.TaskId} does not exist"); } var taskSignup = task.AssignedVolunteers.SingleOrDefault(c => c.User.Id == message.UserId); if (taskSignup == null) { throw new InvalidOperationException($"Sign-up for user {message.UserId} does not exist"); } TaskStatus currentStatus; if (!Enum.TryParse <TaskStatus>(taskSignup.Status, out currentStatus)) { currentStatus = TaskStatus.Assigned; } switch (message.TaskStatus) { case TaskStatus.Assigned: break; case TaskStatus.Accepted: if (currentStatus != TaskStatus.Assigned && currentStatus != TaskStatus.CanNotComplete && currentStatus != TaskStatus.Completed) { throw new ArgumentException($"Task must be assigned before being accepted or undoing CanNotComplete or Completed"); } break; case TaskStatus.Rejected: if (currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be assigned before being rejected"); } break; case TaskStatus.Completed: if (currentStatus != TaskStatus.Accepted && currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be accepted before being completed"); } break; case TaskStatus.CanNotComplete: if (currentStatus != TaskStatus.Accepted && currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be assigned or accepted before it can be marked as {message.TaskStatus}"); } break; default: throw new ArgumentException($"Invalid sign-up status value: {message.TaskStatus}"); } taskSignup.Status = message.TaskStatus.ToString(); taskSignup.StatusDateTimeUtc = DateTime.UtcNow; taskSignup.StatusDescription = message.TaskStatusDescription; _context.SaveChanges(); var notification = new TaskSignupStatusChanged { SignupId = taskSignup.Id }; _mediator.Publish(notification); return(new TaskChangeResult() { Status = "success", Task = task }); }
protected override void HandleCore(TaskStatusChangeCommand message) { var task = _context.Tasks .Include(t => t.AssignedVolunteers).ThenInclude((TaskSignup ts) => ts.User) .SingleOrDefault(c => c.Id == message.TaskId); if (task == null) { throw new InvalidOperationException($"Task {message.TaskId} does not exist"); } var taskSignup = task.AssignedVolunteers.SingleOrDefault(c => c.User.Id == message.UserId); if (taskSignup == null) { throw new InvalidOperationException($"Sign-up for user {message.UserId} does not exist"); } TaskStatus currentStatus; if (!Enum.TryParse <TaskStatus>(taskSignup.Status, out currentStatus)) { currentStatus = TaskStatus.Assigned; } switch (message.TaskStatus) { case TaskStatus.Assigned: break; case TaskStatus.Accepted: if (currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be assigned before being accepted"); } break; case TaskStatus.Rejected: if (currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be assigned before being rejected"); } break; case TaskStatus.Completed: if (currentStatus != TaskStatus.Accepted && currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be accepted before being completed"); } break; case TaskStatus.CanNotComplete: if (currentStatus != TaskStatus.Accepted && currentStatus != TaskStatus.Assigned) { throw new ArgumentException($"Task must be assigned or accepted before it can be marked as {message.TaskStatus}"); } break; default: throw new ArgumentException($"Invalid sign-up status value: {message.TaskStatus}"); } taskSignup.Status = message.TaskStatus.ToString(); taskSignup.StatusDateTimeUtc = DateTime.UtcNow; taskSignup.StatusDescription = message.TaskStatusDescription; _context.SaveChanges(); var notification = new TaskSignupStatusChanged { SignupId = taskSignup.Id }; _bus.Publish(notification); }
public async Task <TaskChangeResult> Handle(ChangeTaskStatusCommand message) { var @task = await GetTask(message); if (@task == null) { throw new InvalidOperationException($"Task {message.TaskId} does not exist"); } var taskSignup = @task.AssignedVolunteers.SingleOrDefault(c => c.User.Id == message.UserId); if (taskSignup == null) { throw new InvalidOperationException($"Sign-up for user {message.UserId} does not exist"); } switch (message.TaskStatus) { case TaskStatus.Assigned: break; case TaskStatus.Accepted: if (taskSignup.Status != TaskStatus.Assigned && taskSignup.Status != TaskStatus.CanNotComplete && taskSignup.Status != TaskStatus.Completed) { throw new ArgumentException("Task must be assigned before being accepted or undoing CanNotComplete or Completed"); } break; case TaskStatus.Rejected: if (taskSignup.Status != TaskStatus.Assigned) { throw new ArgumentException("Task must be assigned before being rejected"); } break; case TaskStatus.Completed: if (taskSignup.Status != TaskStatus.Accepted && taskSignup.Status != TaskStatus.Assigned) { throw new ArgumentException("Task must be accepted before being completed"); } break; case TaskStatus.CanNotComplete: if (taskSignup.Status != TaskStatus.Accepted && taskSignup.Status != TaskStatus.Assigned) { throw new ArgumentException($"Task must be assigned or accepted before it can be marked as {message.TaskStatus}"); } break; default: throw new ArgumentException($"Invalid sign-up status value: {message.TaskStatus}"); } taskSignup.Status = message.TaskStatus; taskSignup.StatusDateTimeUtc = DateTimeUtcNow(); taskSignup.StatusDescription = message.TaskStatusDescription; await _context.SaveChangesAsync(); var notification = new TaskSignupStatusChanged { SignupId = taskSignup.Id }; await _mediator.PublishAsync(notification); return(new TaskChangeResult { Status = "success", Task = @task }); }