public void Post_WhenServiceThrowsUnauthorized_ThenReturnsUnauthorized() { // Arrange var sut = new ReactionsController(_reactionsServiceMock.Object, _mapperMock.Object); var request = new ReactionSaveRequest { Token = "MHZ52UYA1ZL" }; var mappedRequest = new Reaction(); _mapperMock .Setup(m => m.Map <Reaction>(request)) .Returns(mappedRequest); _reactionsServiceMock .Setup(s => s.Save(request.Token, mappedRequest)) .Throws <UnauthorizedException>(); // Act var actual = sut.Post(request); // Assert actual.ShouldBeOfType <UnauthorizedResult>(); _mockRepository.VerifyAll(); }
public void Post_WhenSavesSuccessfuly_ThenReturnsOk() { // Arrange var sut = new ReactionsController(_reactionsServiceMock.Object, _mapperMock.Object); var request = new ReactionSaveRequest { Token = "MHZ52UYA1ZL" }; var mappedRequest = new Reaction(); _mapperMock .Setup(m => m.Map <Reaction>(request)) .Returns(mappedRequest); _reactionsServiceMock .Setup(s => s.Save(request.Token, mappedRequest)); // Act var actual = sut.Post(request) as OkObjectResult; // Assert actual.Value.ShouldBe("Reaction saved!"); _mockRepository.VerifyAll(); }