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 GetAllIssues_With_An_Exception_Should_Return_StatusCode_500_Test()
            {
                // Arrange

                const string expectedLog   = "Something went wrong inside GetAllIssuesAsync action: Some Error";
                const string expectedValue = "Internal server error";

                IssueServiceMock
                .Setup(x => x.GetAllIssuesAsync())
                .ThrowsAsync(new Exception("Some Error"));

                // Act

                var result = await ControllerUnderTest.GetAllIssuesAsync();

                // 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 GetAllAsync_Should_Return_OkObjectResult_With_a_List_of_IssueDtos_Test()
            {
                // Arrange

                var expectedIssues = new List <IssueDto>()
                {
                    new IssueDto()
                    {
                        Id = 1, IssueDescription = "Test 1", DateAdded = DateTimeOffset.Now
                    },
                    new IssueDto()
                    {
                        Id = 2, IssueDescription = "Test 2", DateAdded = DateTimeOffset.Now
                    },
                    new IssueDto()
                    {
                        Id = 3, IssueDescription = "Test 3", DateAdded = DateTimeOffset.Now
                    }
                };

                IssueServiceMock
                .Setup(x => x.GetAllIssuesAsync())
                .ReturnsAsync(expectedIssues);

                // Act

                var result = await ControllerUnderTest.GetAllIssuesAsync();

                // Assert

                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(expectedIssues, okResult.Value);
            }
            public async Task CreateIssueAsync_Should_Return_CreatedAtActionResult_With_The_created_Issue_Test()
            {
                // Arrange

                var expectedCreatedAtActionName = nameof(IssueController.IssueByIdAsync);
                var issueToCreate = new IssueForCreationDto {
                    IssueDescription = "Test  1"
                };
                var expectedResult = new IssueDto {
                    Id = 1, IssueDescription = "Test  1"
                };

                IssueServiceMock
                .Setup(x => x.CreateIssueAsync(issueToCreate))
                .ReturnsAsync(expectedResult);

                // Act

                var result = await ControllerUnderTest.CreateIssueAsync(issueToCreate);

                // Assert

                var createdResult = Assert.IsType <CreatedAtRouteResult>(result);

                Assert.Same(expectedResult, createdResult.Value);
                Assert.Equal(expectedCreatedAtActionName, createdResult.RouteName);
                Assert.Equal(expectedResult.Id, createdResult.RouteValues.GetValueOrDefault("id")
                             );
            }
            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 UpdateIssueAsync_Should_return_NoContentResult_Test()
            {
                // Arrange

                var expectedIssue = new IssueForUpdateDto()
                {
                    Id = 1, IssueDescription = "Test 1", DateAdded = DateTimeOffset.Now
                };

                IssueServiceMock
                .Setup(x => x.UpdateIssueAsync(expectedIssue))
                .ReturnsAsync(true);

                // Act

                var result = await ControllerUnderTest.UpdateIssueAsync(expectedIssue);

                // Assert

                result.Should().BeOfType <NoContentResult>();
            }
            IssueByIdAsync_With_An_InValid_Id_Should_Return_NotFoundResult_when_IssueNotFoundException_is_thrown_Test()
            {
                // Arrange

                const int badId = -1;

                IssueServiceMock
                .Setup(x => x.GetIssueByIdAsync(badId))
                .ThrowsAsync(new IssueNotFoundException(new Issue {
                    Id = badId
                }));

                // Act

                var result = await ControllerUnderTest
                             .IssueByIdAsync(badId);

                // Assert

                Assert.IsType <NotFoundResult>(result);
            }
            public async Task IssueByIdAsync_With_A_Valid_Id_Should_Return_OkObjectResult_with_a_Issue_Test()
            {
                // Arrange

                var expectedIssue = new IssueDto {
                    Id = 1, IssueDescription = "Test 1", DateAdded = DateTimeOffset.Now
                };

                IssueServiceMock
                .Setup(x => x.GetIssueByIdAsync(expectedIssue.Id))
                .ReturnsAsync(expectedIssue);

                // Act

                var result = await ControllerUnderTest
                             .IssueByIdAsync(expectedIssue.Id);

                // Assert

                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(expectedIssue, okResult.Value);
            }
            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);
            }