public async Task DeleteIssueAsync_Where_SaveChangesAsync_Fails_Should__return_a_IssueNotCreatedException_Test() { // Arrange var expectedLog = $"Delete Issue: {IssueToDeleteDto.Id} Failed!"; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id)) .ReturnsAsync(Issues[0]).Verifiable(); RepositoryWrapperMock .Setup(x => x.SaveAsync()) .Throws(new Exception("Save Changes Failed")).Verifiable(); // Act await Assert.ThrowsAsync <IssueNotDeletedException>(() => ServiceUnderTest.DeleteIssueAsync(IssueToDeleteDto)); // Assert LoggerMock.VerifyLog(LogLevel.Error, expectedLog); RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once); RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id), Times.Once); }
public async Task UpdateIssueAsync_Should_Update_and_return_the_specified_Issue_Test() { // Arrange const int id = 1; var issueToUpdateDto = new IssueForUpdateDto() { Id = 1, IssueDescription = "Test 1 updated", DateAdded = DateTimeOffset.Now }; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(id)) .ReturnsAsync(Issues[0]).Verifiable(); RepositoryWrapperMock .Setup(x => x.SaveAsync()) .Returns(() => Task.Run(() => { return(1); })).Verifiable(); // Act var result = await ServiceUnderTest.UpdateIssueAsync(issueToUpdateDto); // Assert result.Should().BeTrue(); RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once); RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(id), Times.Once); }
public async Task UpdateIssueAsync_Where_SaveChangesAsync_Fails_Should__return_a_IssueNotCreatedException_Test() { // Arrange const int id = 1; var expectedLog = $"Updating Issue: {id} Failed!"; var issueToUpdateDto = new IssueForUpdateDto { Id = 1, IssueDescription = "Test 1 updated", DateAdded = DateTimeOffset.Now }; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(id)) .ReturnsAsync(Issues[0]).Verifiable(); RepositoryWrapperMock .Setup(x => x.SaveAsync()) .Throws(new Exception("Save Changes Failed")).Verifiable(); // Act await Assert.ThrowsAsync <IssueNotUpdatedException>(() => ServiceUnderTest.UpdateIssueAsync(issueToUpdateDto)); // Assert LoggerMock.VerifyLog(LogLevel.Error, expectedLog); RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once); RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(id), Times.Once); }
public async Task CreateIssueAsync_Should_create_and_return_the_specified_Issue_Test() { // Arrange const int id = 5; var newIssueDto = new IssueForCreationDto { Id = 5, IssueDescription = "Test 5", DateAdded = DateTimeOffset.Now }; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(It.IsAny <int>())) .ReturnsAsync(default(Issue)).Verifiable(); RepositoryWrapperMock .Setup(x => x.SaveAsync()) .Returns(() => Task.Run(() => { return(1); })).Verifiable(); // Act var result = await ServiceUnderTest.CreateIssueAsync(newIssueDto); // Assert result.Should().NotBeNull(); result.Should().BeOfType <IssueDto>(); result.Id.Should().Be(id); result.IssueDescription.Should().Be(newIssueDto.IssueDescription); RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once); }
public async Task DeleteIssueAsync_With_A_NonExisting_Issue_Should_Return_IssueNotFoundException_Test() { // Arrange RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id)) .ReturnsAsync(default(Issue)).Verifiable(); // Act await Assert.ThrowsAsync <IssueNotFoundException>(() => ServiceUnderTest.DeleteIssueAsync(IssueToDeleteDto)); // Assert RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id), Times.Once); }
public async Task EnforceUserExistanceAsync_Should_Return_UserNotFoundException_If_The_User_Does_Not_Exist_Test() { // Arrange const int id = 1; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(id)) .ReturnsAsync(default(Issue)); // Act await Assert.ThrowsAsync <IssueNotFoundException>(() => ServiceUnderTest.EnforceIssueExistenceAsync(id)); // Assert RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(id), Times.Once); }
public async Task EnforceUserExistanceAsync_Should_Return_User_If_The_User_Exists_Test() { // Arrange var issueId = Issues[0].Id; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(issueId)) .ReturnsAsync(Issues[0]).Verifiable(); // Act var result = await ServiceUnderTest.EnforceIssueExistenceAsync(issueId); // Assert result.Should().BeSameAs(Issues[0]); RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(issueId), Times.Once); }
public async Task UpdateIssueAsync_With_A_NonExisting_Issue_Should_Return_IssueNotUpdatedException_Test() { // Arrange var issueToUpdateDto = new IssueForUpdateDto() { Id = 1, IssueDescription = "Test 1 updated" }; RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(issueToUpdateDto.Id)) .ReturnsAsync(default(Issue)).Verifiable(); // Act await Assert.ThrowsAsync <IssueNotFoundException>(() => ServiceUnderTest.UpdateIssueAsync(issueToUpdateDto)); // Assert RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(issueToUpdateDto.Id), Times.Once); }
public async Task DeleteIssueAsync_Should_Update_and_return_the_specified_Issue_Test() { // Arrange RepositoryWrapperMock .Setup(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id)) .ReturnsAsync(Issues[0]).Verifiable(); RepositoryWrapperMock .Setup(x => x.SaveAsync()) .Returns(() => Task.Run(() => { return(1); })).Verifiable(); // Act var result = await ServiceUnderTest.DeleteIssueAsync(IssueToDeleteDto); // Assert result.Should().BeTrue(); RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once); RepositoryWrapperMock .Verify(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id), Times.Once); }