public void CreateToDoListItem_ReturnsOKResult() { //Arrange var httpContext = new DefaultHttpContext(); CreateToDoItemCommand command = new CreateToDoItemCommand(); command.Name = "Test"; command.Completed = false; var mediator = new Mock <IMediator>(); mediator.Setup(m => m.Send(It.IsAny <CreateToDoItemCommand>(), new System.Threading.CancellationToken())); var controller = new ToDoListController(mediator.Object) { ControllerContext = new ControllerContext() { HttpContext = httpContext, } }; //ACT var result = controller.CreateToDoListItem(command); //ASSERT Assert.IsType <ActionResult <ToDoItemListDto> >(result.Result); Assert.Null(result.Result.Value); }
public async void CreateToDoListItem_ReturnsValidDto_ReturnsOKResult() { //Arrange var httpContext = new DefaultHttpContext(); var items = await GetToDoListItemsFromFileAsync(); CreateToDoItemCommand command = new CreateToDoItemCommand(); command.Name = "Test"; command.Completed = false; var mediator = new Mock <IMediator>(); mediator.Setup(m => m.Send(It.IsAny <CreateToDoItemCommand>(), new System.Threading.CancellationToken())) .Returns(Task.FromResult(items.First())); var controller = new ToDoListController(mediator.Object) { ControllerContext = new ControllerContext() { HttpContext = httpContext, } }; //ACT var result = await controller.CreateToDoListItem(command); //ASSERT Assert.IsType <OkObjectResult>(result.Result); Assert.NotNull(result.Result); }