Example #1
0
        public async Task VolunteerCannotCompleteTaskFromAcceptedStatus()
        {
            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 TaskStatusChangeCommandAsync
            {
                TaskId                = task.Id,
                UserId                = user.Id,
                TaskStatus            = TaskStatus.CanNotComplete,
                TaskStatusDescription = $"{user.UserName} cannot complete {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.User.Id.ShouldBe(command.UserId);
            taskSignup.Task.Id.ShouldBe(command.TaskId);
            taskSignup.StatusDescription.ShouldBe(command.TaskStatusDescription);
        }
        public async Task VolunteerAcceptsTask()
        {
            var mediator = new Mock <IMediator>();

            var task    = Context.Tasks.First();
            var user    = Context.Users.First();
            var command = new TaskStatusChangeCommandAsync
            {
                TaskId     = task.Id,
                UserId     = user.Id,
                TaskStatus = TaskStatus.Accepted
            };
            var handler = new TaskStatusChangeHandlerAsync(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());
        }
Example #3
0
        public async Task VolunteerRejectsTask()
        {
            var task    = Context.Tasks.First();
            var user    = Context.Users.First();
            var command = new TaskStatusChangeCommandAsync
            {
                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);
        }
Example #4
0
        public async Task VolunteerCompletesTaskFromAssignedStatus()
        {
            var dateTime = DateTime.UtcNow;
            var task     = Context.Tasks.First();
            var user     = Context.Users.First();
            var command  = new TaskStatusChangeCommandAsync
            {
                TaskId                = task.Id,
                UserId                = user.Id,
                TaskStatus            = TaskStatus.Completed,
                TaskStatusDescription = $"{user.UserName} completed 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.Task.Id.ShouldBe(command.TaskId);
            taskSignup.User.Id.ShouldBe(command.UserId);
            taskSignup.StatusDescription.ShouldBe(command.TaskStatusDescription);
            taskSignup.StatusDateTimeUtc.ShouldBe(dateTime, TimeSpan.FromSeconds(3));
        }
        public async Task VolunteerAcceptsTask()
        {
            var mediator = new Mock<IMediator>();

            var task = Context.Tasks.First();
            var user = Context.Users.First();
            var command = new TaskStatusChangeCommandAsync
            {
                TaskId = task.Id,
                UserId = user.Id,
                TaskStatus = AllReady.Areas.Admin.Features.Tasks.TaskStatus.Accepted
            };
            var handler = new TaskStatusChangeHandlerAsync(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());
        }
        public async Task VolunteerCannotCompleteTaskFromAssignedStatus()
        {
            var dateTime = DateTime.UtcNow;
            var user = Context.Users.First();
            var task = Context.Tasks.First();
            var command = new TaskStatusChangeCommandAsync
            {
                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 TaskStatusChangeCommandAsync
            {
                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);
        }