public async Task ChangeStatusInvokesSendAsyncWithCorrectTaskStatusChangeCommand() { var model = new TaskChangeModel { TaskId = 1, UserId = "1", Status = TaskStatus.Accepted, StatusDescription = "statusDescription" }; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <TaskStatusChangeCommandAsync>())).Returns(() => Task.FromResult(new TaskChangeResult())); var sut = new TaskApiController(null, mediator.Object, null); await sut.ChangeStatus(model); mediator.Verify(x => x.SendAsync(It.Is <TaskStatusChangeCommandAsync>(y => y.TaskId == model.TaskId && y.TaskStatus == model.Status && y.TaskStatusDescription == model.StatusDescription && y.UserId == model.UserId))); }
public async Task ChangeStatusReturnsTaskViewModelWhenResultTaskIsNotNull() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <TaskStatusChangeCommandAsync>())).Returns(() => Task.FromResult(new TaskChangeResult { Task = new AllReadyTask() })); var sut = new TaskApiController(null, mediator.Object, null); sut.SetDefaultHttpContext(); var jsonResult = await sut.ChangeStatus(new TaskChangeModel()); var result = jsonResult.GetValueForProperty <TaskViewModel>("Task"); Assert.IsType <JsonResult>(jsonResult); Assert.IsType <TaskViewModel>(result); }
public async Task ChangeStatusReturnsNullForTaskWhenResultTaskIsNull() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <TaskStatusChangeCommand>())).Returns(() => Task.FromResult(new TaskChangeResult { Status = "status" })); var sut = new TaskApiController(mediator.Object, null, null); sut.SetDefaultHttpContext(); var jsonResult = await sut.ChangeStatus(new TaskChangeModel()); var result = jsonResult.GetValueForProperty <string>("Task"); Assert.IsType <JsonResult>(jsonResult); Assert.Null(result); }
public async Task ChangeStatusReturnsCorrectStatus() { const string status = "status"; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <TaskStatusChangeCommandAsync>())).Returns(() => Task.FromResult(new TaskChangeResult { Status = status })); var sut = new TaskApiController(null, mediator.Object, null); sut.SetDefaultHttpContext(); var jsonResult = await sut.ChangeStatus(new TaskChangeModel()); var result = jsonResult.GetValueForProperty <string>("Status"); Assert.IsType <JsonResult>(jsonResult); Assert.IsType <string>(result); Assert.Equal(result, status); }