public async Task Get_ReturnsOkAndToDo_WhenServiceReturnsToDo() { // Arrange var mockServiceResponse = new BusinessModels.Todo() { Id = Guid.Parse("e0f36c5f-7b2d-45bd-a646-8bb1198879ae"), Name = "ToDo1" }; _todoServiceMock.Setup(s => s.GetTodo(It.IsAny <Guid>())).ReturnsAsync(mockServiceResponse); // We dont care to specify Id, we don't test the logic of the service/repository in controller tests. var unitUnderTest = new ToDoController(_mapper, _todoServiceMock.Object); var expectedControllerResponse = new ApiModels.TodoModel() { Id = Guid.Parse("e0f36c5f-7b2d-45bd-a646-8bb1198879ae"), Name = "ToDo1" }; // Act var response = await unitUnderTest.Get(Guid.NewGuid()); // We dont care to specify Id, we don't test the logic of the service/repository in controller tests. // Assert var okObjectResult = response as OkObjectResult; okObjectResult.Should().NotBe(null); okObjectResult.StatusCode.Should().Be((int)HttpStatusCode.OK); var todoReturned = okObjectResult.Value as ApiModels.TodoModel; todoReturned.Should().BeEquivalentTo(expectedControllerResponse); }
public async Task Get_ReturnsNotFound_WhenServiceReturnsNull() { // Arrange _todoServiceMock.Setup(s => s.GetTodo(It.IsAny <Guid>())).ReturnsAsync((BusinessModels.Todo)null); var unitUnderTest = new ToDoController(_mapper, _todoServiceMock.Object); var expectedControllerResponse = new ApiModels.TodoModel() { Id = Guid.Parse("e0f36c5f-7b2d-45bd-a646-8bb1198879ae"), Name = "ToDo1" }; // Act var response = await unitUnderTest.Get(Guid.NewGuid()); // Assert var notFoundResult = response as NotFoundResult; notFoundResult.Should().NotBe(null); notFoundResult.StatusCode.Should().Be((int)HttpStatusCode.NotFound); }