public async Task VolunteerAcceptsTask()
        {
            var mediator = new Mock<IMediator>();

            var @task = Context.Tasks.First();
            var user = Context.Users.First();
            var command = new TaskStatusChangeCommand
            {
                TaskId = @task.Id,
                UserId = user.Id,
                TaskStatus = AllReady.Areas.Admin.Features.Tasks.TaskStatus.Accepted
            };
            var handler = new TaskStatusChangeHandler(Context, mediator.Object);
            await handler.Handle(command);

            var taskSignup = Context.TaskSignups.First();
            mediator.Verify(b => b.PublishAsync(It.Is<TaskSignupStatusChanged>(notifyCommand => notifyCommand.SignupId == taskSignup.Id)), Times.Once());
        }
Beispiel #2
0
        public void VolunteerAcceptsTask()
        {
            var bus = new Mock<IMediator>();

            var task = Context.Tasks.First();
            var user = Context.Users.First();
            var command = new TaskStatusChangeCommand
            {
                TaskId = task.Id, UserId = user.Id, TaskStatus = TaskStatus.Accepted
            };
            var handler = new TaskStatusChangeHandler(Context, bus.Object);
            var result = handler.Handle(command);

            var taskSignup = Context.TaskSignups.First();
            bus.Verify(b => b.Publish(It.Is<TaskSignupStatusChanged>(notifyCommand =>
                   notifyCommand.SignupId == taskSignup.Id
            )), Times.Once());
        }
        public async Task VolunteerCannotCompleteTaskFromAssignedStatus()
        {
            var dateTime = DateTime.UtcNow;
            var user = Context.Users.First();
            var task = Context.Tasks.First();
            var command = new TaskStatusChangeCommand
            {
                TaskId = task.Id,
                UserId = user.Id,
                TaskStatus = TaskStatus.CanNotComplete,
                TaskStatusDescription = $"{user.UserName} cannot complete task {task.Name}"
            };

            await handler.Handle(command);

            var taskSignup = Context.TaskSignups.First();
            mediator.Verify(b => b.PublishAsync(It.Is<TaskSignupStatusChanged>(notifyCommand => notifyCommand.SignupId == taskSignup.Id)), Times.Once());
            taskSignup.Status.ShouldBe(command.TaskStatus.ToString());
            taskSignup.User.Id.ShouldBe(command.UserId);
            taskSignup.Task.Id.ShouldBe(command.TaskId);
            taskSignup.StatusDescription.ShouldBe(command.TaskStatusDescription);
            taskSignup.StatusDateTimeUtc.ShouldBe(dateTime, TimeSpan.FromSeconds(1));
        }
        public async Task VolunteerCompletesTaskFromAcceptedStatus()
        {
            var taskSignup = Context.TaskSignups.First();
            taskSignup.Status = TaskStatus.Accepted.ToString();
            await Context.SaveChangesAsync();

            var task = Context.Tasks.First();
            var user = Context.Users.First();
            var command = new TaskStatusChangeCommand
            {
                TaskId = task.Id,
                UserId = user.Id,
                TaskStatus = TaskStatus.Completed,
                TaskStatusDescription = $"{user.UserName} completed {task.Name}"
            };
            await handler.Handle(command);

            taskSignup = Context.TaskSignups.First();
            mediator.Verify(b => b.PublishAsync(It.Is<TaskSignupStatusChanged>(notifyCommand => notifyCommand.SignupId == taskSignup.Id)), Times.Once());
            taskSignup.Status.ShouldBe(command.TaskStatus.ToString());
            taskSignup.Task.Id.ShouldBe(command.TaskId);
            taskSignup.User.Id.ShouldBe(command.UserId);
            taskSignup.StatusDescription.ShouldBe(command.TaskStatusDescription);
        }
        public async Task VolunteerRejectsTask()
        {
            var @task = Context.Tasks.First();
            var user = Context.Users.First();
            var command = new TaskStatusChangeCommand
            {
                TaskId = @task.Id,
                UserId = user.Id,
                TaskStatus = TaskStatus.Rejected,
                TaskStatusDescription = $"{user.UserName} rejected task {@task.Name}"
            };
            await handler.Handle(command);

            var taskSignup = Context.TaskSignups.First();
            mediator.Verify(b => b.PublishAsync(It.Is<TaskSignupStatusChanged>(notifiyCommand => notifiyCommand.SignupId == taskSignup.Id)), Times.Once());
            taskSignup.Status.ShouldBe(command.TaskStatus.ToString());
            taskSignup.Task.Id.ShouldBe(command.TaskId);
            taskSignup.User.Id.ShouldBe(command.UserId);
            taskSignup.StatusDescription.ShouldBe(command.TaskStatusDescription);
        }