diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index 717c89b0..970648c4 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blog.Data.Specifications.Base; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -2200,6 +2201,22 @@ public void Any_WithEqualSpecification_WhenCommentDoesNotExists_ShouldReturnNoth Assert.False(areAnyComments); } + /// + /// Any. + /// When repository throws exception should throw exception. + /// + [Fact] + public void Any_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new CommentSpecification(x => x.CommentBody.Equals("Comment 0")); + _commentsRepositoryMock.Setup(r => r.Any(It.IsAny>())) + .Throws(new Exception("DB error")); + + //Assert + Assert.Throws(() => _commentsService.Any(specification)); + } + #endregion #region Any Async function With Specification @@ -2337,6 +2354,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenCommentDoesNotExists_Shoul Assert.False(areAnyComments); } + /// + /// Any async. + /// When repository throws exception should throw exception. + /// + [Fact] + public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new CommentSpecification(x => x.CommentBody.Equals("Comment 0")); + _commentsRepositoryMock.Setup(r => r.AnyAsync(It.IsAny>())) + .ThrowsAsync(new Exception("DB error")); + + //Assert + await Assert.ThrowsAsync(() => _commentsService.AnyAsync(specification)); + } + #endregion #endregion diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs index c261080c..379e8c60 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blog.Data.Specifications.Base; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -2270,6 +2271,22 @@ public void Any_WithEqualSpecification_WhenMessagesDoesNotExists_ShouldReturnNot Assert.False(areAnyMessages); } + /// + /// Any. + /// When repository throws exception should throw exception. + /// + [Fact] + public void Any_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new MessageSpecification(x => x.Subject.Equals("Test subject0")); + _messagesRepositoryMock.Setup(r => r.Any(It.IsAny>())) + .Throws(new Exception("DB error")); + + //Assert + Assert.Throws(() => _messagesService.Any(specification)); + } + #endregion #region Any Async function With Specification @@ -2407,6 +2424,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenMessagesDoesNotExists_Shou Assert.False(areAnyMessages); } + /// + /// Any async. + /// When repository throws exception should throw exception. + /// + [Fact] + public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new MessageSpecification(x => x.Subject.Equals("Test subject0")); + _messagesRepositoryMock.Setup(r => r.AnyAsync(It.IsAny>())) + .ThrowsAsync(new Exception("DB error")); + + //Assert + await Assert.ThrowsAsync(() => _messagesService.AnyAsync(specification)); + } + #endregion #endregion diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index efc676fa..d76a56a5 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -2748,6 +2748,23 @@ public void Any_WithEqualSpecification_WhenPostTagRelationDoesNotExists_ShouldRe Assert.False(areAnyPosts); } + /// + /// Any. + /// When repository throws exception should throw exception. + /// + [Fact] + public void Any_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = + new BaseSpecification(x => x.Tag.Title.Equals("Created from ServicesTests 0")); + _postsTagsRelationsRepositoryMock.Setup(r => r.Any(It.IsAny>())) + .Throws(new Exception("DB error")); + + //Assert + Assert.Throws(() => _postsTagsRelationsService.Any(specification)); + } + #endregion #region Any Async function With Specification @@ -2886,6 +2903,23 @@ public async Task AnyAsync_WithEqualSpecification_WhenPostTagRelationDoesNotExis Assert.False(areAnyPosts); } + /// + /// Any async. + /// When repository throws exception should throw exception. + /// + [Fact] + public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = + new BaseSpecification(x => x.Tag.Title.Equals("Created from ServicesTests 0")); + _postsTagsRelationsRepositoryMock.Setup(r => r.AnyAsync(It.IsAny>())) + .ThrowsAsync(new Exception("DB error")); + + //Assert + await Assert.ThrowsAsync(() => _postsTagsRelationsService.AnyAsync(specification)); + } + #endregion #endregion diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index edf5a4f0..0cfddbd5 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -16,6 +16,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blog.Data.Specifications.Base; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -2252,6 +2253,22 @@ public void Any_WithEqualSpecification_WhenPostDoesNotExists_ShouldReturnNothing Assert.False(areAnyPosts); } + /// + /// Any. + /// When repository throws exception should throw exception. + /// + [Fact] + public void Any_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new PostSpecification(x => x.Title.Equals("Created from ServicesTests 0")); + _postsRepositoryMock.Setup(r => r.Any(It.IsAny>())) + .Throws(new Exception("DB error")); + + //Assert + Assert.Throws(() => _postsService.Any(specification)); + } + #endregion #region Any Async function With Specification @@ -2389,6 +2406,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenPostDoesNotExists_ShouldRe Assert.False(areAnyPosts); } + /// + /// Any async. + /// When repository throws exception should throw exception. + /// + [Fact] + public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new PostSpecification(x => x.Title.Equals("Created from ServicesTests 0")); + _postsRepositoryMock.Setup(r => r.AnyAsync(It.IsAny>())) + .ThrowsAsync(new Exception("DB error")); + + //Assert + await Assert.ThrowsAsync(() => _postsService.AnyAsync(specification)); + } + #endregion #endregion diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index 9444f404..24f06479 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -16,6 +16,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blog.Data.Specifications.Base; using Xunit; using ProfileModel = Blog.Data.Models.Profile; @@ -2179,6 +2180,23 @@ public void Any_WithEqualSpecification_WhenProfilesDoesNotExists_ShouldReturnNot Assert.False(areAnyProfiles); } + /// + /// Any. + /// When repository throws exception should throw exception. + /// + [Fact] + public void Any_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var searchUserId = Guid.Empty.ToString(); + var specification = new ProfileSpecification(x => x.UserId.Equals(searchUserId)); + _profileRepositoryMock.Setup(r => r.Any(It.IsAny>())) + .Throws(new Exception("DB error")); + + //Assert + Assert.Throws(() => _profileService.Any(specification)); + } + #endregion #region Any Async function With Specification @@ -2290,6 +2308,23 @@ public async Task AnyAsync_WithEqualSpecification_WhenProfilesDoesNotExists_Shou Assert.False(areAnyProfiles); } + /// + /// Any async. + /// When repository throws exception should throw exception. + /// + [Fact] + public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var searchUserId = Guid.Empty.ToString(); + var specification = new ProfileSpecification(x => x.UserId.Equals(searchUserId)); + _profileRepositoryMock.Setup(r => r.AnyAsync(It.IsAny>())) + .ThrowsAsync(new Exception("DB error")); + + //Assert + await Assert.ThrowsAsync(() => _profileService.AnyAsync(specification)); + } + #endregion #endregion diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs index f7e4e794..19f13198 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blog.Data.Specifications.Base; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -2253,6 +2254,22 @@ public void Any_WithEqualSpecification_WhenCommentDoesNotExists_ShouldReturnNoth Assert.False(areAnyTags); } + /// + /// Any. + /// When repository throws exception should throw exception. + /// + [Fact] + public void Any_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new TagSpecification(x => x.Title.Equals("Tag 0")); + _tagsRepositoryMock.Setup(r => r.Any(It.IsAny>())) + .Throws(new Exception("DB error")); + + //Assert + Assert.Throws(() => _tagsService.Any(specification)); + } + #endregion #region Any Async function With Specification @@ -2394,6 +2411,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenTagDoesNotExists_ShouldRet Assert.False(areAnyTags); } + /// + /// Any async. + /// When repository throws exception should throw exception. + /// + [Fact] + public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var specification = new TagSpecification(x => x.Title.Equals("Tag 0")); + _tagsRepositoryMock.Setup(r => r.AnyAsync(specification)) + .ThrowsAsync(new Exception("DB error")); + + //Assert + await Assert.ThrowsAsync(() => _tagsService.AnyAsync(specification)); + } + #endregion #endregion