From dcfd828fe8a7c7a4ecc2e03c6c728ddd5a1415de Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Fri, 23 Jan 2026 21:49:56 +0200 Subject: [PATCH 01/12] Add exception tests case for Any in comments service tests --- .../EntityServices/CommentsServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index 717c89b0..40a6faee 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 From 4052a9300e5f6eed4c47f7aacb639d58a71c150c Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Fri, 23 Jan 2026 21:50:12 +0200 Subject: [PATCH 02/12] Add exception tests case for Any Async in comments service tests --- .../EntityServices/CommentsServiceTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index 40a6faee..970648c4 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -2354,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 From 55b0128e510b94d3440e1eb9c5d30cfe9c3f078c Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 26 Jan 2026 21:50:50 +0200 Subject: [PATCH 03/12] Add exception tests case for Any in messages service tests --- .../EntityServices/MessagesServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs index c261080c..5e78a0b9 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 From a9cccb243ea5ee8d1a0b72cbaf8d977c043ae6b4 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 26 Jan 2026 21:51:07 +0200 Subject: [PATCH 04/12] Add exception tests case for Any Async in messages service tests --- .../EntityServices/MessagesServiceTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs index 5e78a0b9..379e8c60 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -2424,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 From 100b7a9758fc383e875dd2ecf2ded3f3dffca708 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 26 Jan 2026 21:51:36 +0200 Subject: [PATCH 05/12] Add exception tests case for Any in posts service tests --- .../EntityServices/PostsServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index edf5a4f0..5b026393 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 From 00cd083c4284f415e91089353cde000ffe3a623f Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 26 Jan 2026 21:51:55 +0200 Subject: [PATCH 06/12] Add exception tests case for Any Async in posts service tests --- .../EntityServices/PostsServiceTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index 5b026393..0cfddbd5 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -2406,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 From 91e615d560735ca9a2a372d24f149fc963916a77 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 27 Jan 2026 21:52:46 +0200 Subject: [PATCH 07/12] Add exception tests case for Any in post tag relations service tests --- .../PostTagRelationsServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index efc676fa..9e10c335 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 From 868c0c25e46f48004438caeceb38062e7111f911 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 27 Jan 2026 21:53:09 +0200 Subject: [PATCH 08/12] Add exception tests case for Any Async in post tag relations service tests --- .../PostTagRelationsServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index 9e10c335..d76a56a5 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -2903,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 From 9f3327d33d1764fcd1752ffe4d81a234d6e666bf Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 27 Jan 2026 21:54:16 +0200 Subject: [PATCH 09/12] Add exception tests case for Any in profile service tests --- .../EntityServices/ProfileServiceTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index 9444f404..07cd3534 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 From 82d64784c44ef38da2392210fefac8026aec8e25 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 27 Jan 2026 21:54:30 +0200 Subject: [PATCH 10/12] Add exception tests case for Any Async in profile service tests --- .../EntityServices/ProfileServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index 07cd3534..24f06479 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -2308,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 From 3cace931bf09bf288a04ab23dd4fe2dce68991c6 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Wed, 28 Jan 2026 21:55:27 +0200 Subject: [PATCH 11/12] Add exception tests case for Any in tags service tests --- .../EntityServices/TagsServiceTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs index f7e4e794..c771d331 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 From fb7796ec10c5f9a9e792a4747727e68dbc5b60a4 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Wed, 28 Jan 2026 21:55:50 +0200 Subject: [PATCH 12/12] Add exception tests case for Any Async in tags service tests --- .../EntityServices/TagsServiceTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs index c771d331..19f13198 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -2411,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