public async Task DeleteIssueAsync_With_An_Exception_Should_Return_StatusCode_500_Test() { // Arrange var expectedIssue = new IssueForDeleteDto { Id = 1, IssueDescription = "Test 1", }; const string expectedLog = "Something went wrong inside DeleteIssueAsync action: Some Error"; const string expectedValue = "Internal server error"; IssueServiceMock .Setup(x => x.DeleteIssueAsync(It.IsAny <IssueForDeleteDto>())) .ThrowsAsync(new Exception("Some Error")); // Act var result = await ControllerUnderTest.DeleteIssueAsync(expectedIssue); // Assert result.Should().BeOfType <ObjectResult>(); LoggerMock.Invocations.Count.Should().Be(1); LoggerMock.Invocations[0].Arguments[2].ToString().Should().Contain(expectedLog); var content = (ObjectResult)result; content.StatusCode.Should().Be(500); content.Value.Should().Be(expectedValue); }
public async Task DeleteIssueAsync_With_Null_IssueForCreationDto_Should_Return_BadRequest_Test() { // Arrange const string expectedLog = "Issue object sent from client is null"; // Act var result = await ControllerUnderTest.DeleteIssueAsync(null); // Assert result.Should().BeOfType <BadRequestObjectResult>(); LoggerMock.Invocations.Count.Should().Be(1); LoggerMock.Invocations[0].Arguments[2].ToString().Should().Contain(expectedLog); }
public async Task DeleteIssueAsync_With_Valid_Id_Should_return_NoContentResult_on_successful_delete_Test() { // Arrange var expectedIssue = new IssueForDeleteDto() { Id = 1 }; IssueServiceMock .Setup(x => x.DeleteIssueAsync(expectedIssue)) .ReturnsAsync(true); // Act var result = await ControllerUnderTest.DeleteIssueAsync(expectedIssue); // Assert result.Should().BeOfType <NoContentResult>(); }
public async Task DeleteIssueAsync_Should_return_NotFoundResult_when_IssueNotFoundException_is_thrown_Test() { // Arrange var expectedIssue = new IssueForDeleteDto() { Id = 1 }; var expectedResult = new Issue { Id = 1, IssueDescription = "Test 1", DateAdded = DateTimeOffset.Now }; IssueServiceMock .Setup(x => x.DeleteIssueAsync(expectedIssue)) .ThrowsAsync(new IssueNotFoundException(expectedResult)); // Act var result = await ControllerUnderTest.DeleteIssueAsync(expectedIssue); // Assert Assert.IsType <NotFoundResult>(result); }