public async Task CreateToDoListsBadRequestResponse() { //Arrange var mockService = new Mock <IToDoService>(); mockService.Setup( service => service.CreateToDoList(It.IsAny <int>(), It.IsAny <IEnumerable <CreateDTO> >()) ).ReturnsAsync(userId); var controller = new ToDoController(mockService.Object, _mockLogger, _mockCache); //Act var result = await controller.CreateList(userId, It.IsAny <IEnumerable <CreateDTO> >()); //Assert Assert.IsNotNull(result); Assert.IsInstanceOf <BadRequestResult>(result); }
public async Task CreateToDoListFourHundredNineResponse() { //Arrange var expected = StatusCodes.Status409Conflict; var mockService = new Mock <IToDoService>(); mockService.Setup( service => service.CreateToDoList(It.IsAny <int>(), It.IsAny <IEnumerable <CreateDTO> >()) ).ReturnsAsync(0); var controller = new ToDoController(mockService.Object, _mockLogger, _mockCache); //Act var result = await controller.CreateList(userId, _mockCreateList) as StatusCodeResult; //Assert Assert.IsInstanceOf <StatusCodeResult>(result); Assert.AreEqual(expected, result.StatusCode); }
public async Task CreateToDoListsReturnCreatedRoute() { //Arrange var mockService = new Mock <IToDoService>(); mockService.Setup( service => service.CreateToDoList(It.IsAny <int>(), It.IsAny <IEnumerable <CreateDTO> >()) ).ReturnsAsync(userId); var controller = new ToDoController(mockService.Object, _mockLogger, _mockCache); //Act var result = await controller.CreateList(userId, _mockCreateList); var resultResponse = result as CreatedAtRouteResult; //Assert Assert.IsInstanceOf <CreatedAtRouteResult>(resultResponse); Assert.AreEqual("Get", resultResponse.RouteName); }