From ae8c6fb9ea4e9cd1a8a11a246d612b8716d2bfaf Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Fri, 19 Sep 2025 23:08:01 +0300 Subject: [PATCH 01/25] Add exception tests case for Update in comments service tests --- .../EntityServices/CommentsServiceTests.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index 1e2647ff..7706aeb2 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using AutoFixture; using AutoFixture.Dsl; using Blog.Core.Enums; @@ -15,6 +11,10 @@ using Blog.EntityServices.Interfaces; using Microsoft.EntityFrameworkCore; using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -1261,6 +1261,23 @@ public void Update_WhenCommentExists_ShouldReturnComment(string newCommentBody) Assert.Equal(newCommentBody, comment.CommentBody); } + /// + /// Update comment. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void Update_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var comment = SetupCommentFixture().Create(); + + _commentsRepositoryMock.Setup(x => x.Update(It.IsAny())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _commentsService.Update(comment)); + } + #endregion #region Upadate Enumerable function From 82d7e31376c784df5e7fab876ea7bf8eeee4c6fb Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Fri, 19 Sep 2025 23:08:25 +0300 Subject: [PATCH 02/25] Add exception tests case for Update Enumerable in comments service tests --- .../EntityServices/CommentsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index 7706aeb2..aa916a63 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -1361,6 +1361,27 @@ public void UpdateEnumerable_WhenCommentExists_ShouldReturnComment(string newCom } } + /// + /// Update Enumerable comments. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void UpdateEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var comments = SetupCommentFixture() + .CreateMany(itemsCount) + .ToList(); + + _commentsRepositoryMock.Setup(x => x.Update(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _commentsService.Update(comments)); + } + #endregion #region Update Async function From 603bdb6df8784622c2bb28546e969653b067f4c3 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sat, 20 Sep 2025 23:08:52 +0300 Subject: [PATCH 03/25] Add exception tests case for Update Async 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 aa916a63..0332fe19 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -1451,6 +1451,23 @@ public async Task UpdateAsync_WhenCommentExists_ShouldReturnComment(string newCo Assert.Equal(newCommentBody, comment.CommentBody); } + /// + /// Async Update comment. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var comment = SetupCommentFixture().Create(); + + _commentsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _commentsService.UpdateAsync(comment)); + } + #endregion #region Upadate Async Enumerable function From f0fb66fdfabe5e2fc2dd850ceac54d52fb8e8543 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sat, 20 Sep 2025 23:09:13 +0300 Subject: [PATCH 04/25] Add exception tests case for Update Async Enumerable in comments service tests --- .../EntityServices/CommentsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index 0332fe19..be0f7949 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -1553,6 +1553,27 @@ public async Task UpdateAsyncEnumerable_WhenCommentExists_ShouldReturnComment(st } } + /// + /// Update Async Enumerable comments. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var comments = SetupCommentFixture() + .CreateMany(itemsCount) + .ToList(); + + _commentsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _commentsService.UpdateAsync(comments)); + } + #endregion #endregion From 16568c86dc8366117d09bee5c696818ebe65afe9 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sat, 20 Sep 2025 23:09:58 +0300 Subject: [PATCH 05/25] Add exception tests case for Update 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 2c43e695..d58a7614 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -1284,6 +1284,23 @@ public void Update_WhenMessageExists_ShouldReturnMessage(string newMessageSubjec Assert.Equal(newMessageSubject, message.Subject); } + /// + /// Update message. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void Update_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var message = SetupMessageFixture().Create(); + + _messagesRepositoryMock.Setup(x => x.Update(It.IsAny())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _messagesService.Update(message)); + } + #endregion #region Upadate Enumerable function From d908f03f9c6232ebb748948cbf29c69045cc88c7 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sun, 21 Sep 2025 23:10:29 +0300 Subject: [PATCH 06/25] Add exception tests case for Update Enumerable in messages service tests --- .../EntityServices/MessagesServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs index d58a7614..3960a2a1 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -1385,6 +1385,27 @@ public void UpdateEnumerable_WhenMessageExists_ShouldReturnMessage(string newMes } } + /// + /// Update Enumerable messages. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void UpdateEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var messages = SetupMessageFixture() + .CreateMany(itemsCount) + .ToList(); + + _messagesRepositoryMock.Setup(x => x.Update(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _messagesService.Update(messages)); + } + #endregion #region Update Async function From 4b81837eeca07646b0b599f89a4ed50b4db1ec70 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sun, 21 Sep 2025 23:10:59 +0300 Subject: [PATCH 07/25] Add exception tests case for Update Async 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 3960a2a1..22a7570c 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -1478,6 +1478,23 @@ public async Task UpdateAsync_WhenMessageExists_ShouldReturnMessage(string newMe Assert.Equal(newMessageSubject, message.Subject); } + /// + /// Async Update message. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var message = SetupMessageFixture().Create(); + + _messagesRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _messagesService.UpdateAsync(message)); + } + #endregion #region Upadate Async Enumerable function From 680f970e818df357aecaada5514383adaf27ee8d Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sun, 21 Sep 2025 23:11:18 +0300 Subject: [PATCH 08/25] Add exception tests case for Update Async Enumerable in messages service tests --- .../EntityServices/MessagesServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs index 22a7570c..27cd0474 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -1581,6 +1581,27 @@ public async Task UpdateAsyncEnumerable_WhenMessageExists_ShouldReturnMessage(st } } + /// + /// Update Async Enumerable messages. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var messages = SetupMessageFixture() + .CreateMany(itemsCount) + .ToList(); + + _messagesRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _messagesService.UpdateAsync(messages)); + } + #endregion #endregion From e186b6899418a556f5b348e324283d6524301dea Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 22 Sep 2025 23:12:23 +0300 Subject: [PATCH 09/25] Add exception tests case for Update in posts service tests --- .../EntityServices/PostsServiceTests.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index 08daee22..22876006 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using AutoFixture; using AutoFixture.Dsl; using AutoMapper; @@ -17,6 +13,10 @@ using Blog.EntityServices.Interfaces; using Microsoft.EntityFrameworkCore; using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -1294,6 +1294,23 @@ public void Update_WhenPostExists_ShouldReturnPost(string newTitle) Assert.Equal(newTitle, post.Title); } + /// + /// Update post. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void Update_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var post = SetupPostFixture().Create(); + + _postsRepositoryMock.Setup(x => x.Update(It.IsAny())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _postsService.Update(post)); + } + #endregion #region Upadate Enumerable function From b08663f9f0403a4e9fbd369f33544f6e4fd1eaa0 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 22 Sep 2025 23:12:37 +0300 Subject: [PATCH 10/25] Add exception tests case for Update Enumerable in posts service tests --- .../EntityServices/PostsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index 22876006..9f7002ae 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -1399,6 +1399,27 @@ public void UpdateEnumerable_WhenPostExists_ShouldReturnPost(string newTitle) } } + /// + /// Update Enumerable posts. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void UpdateEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var posts = SetupPostFixture() + .CreateMany(itemsCount) + .ToList(); + + _postsRepositoryMock.Setup(x => x.Update(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _postsService.Update(posts)); + } + #endregion #region Update Async function From 0610b8f36045ee9ede8cc49e5b6a9592f3ab5ddd Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Mon, 22 Sep 2025 23:12:48 +0300 Subject: [PATCH 11/25] Add exception tests case for Update Async 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 9f7002ae..b3c98506 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -1488,6 +1488,23 @@ public async Task UpdateAsync_WhenPostExists_ShouldReturnPost(string newTitle) Assert.Equal(newTitle, post.Title); } + /// + /// Async Update post. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var post = SetupPostFixture().Create(); + + _postsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _postsService.UpdateAsync(post)); + } + #endregion #region Upadate Async Enumerable function From 4a16f15be36798b5c4c880f5563866d51b864f35 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 23 Sep 2025 23:13:06 +0300 Subject: [PATCH 12/25] Add exception tests case for Update Async Enumerable in posts service tests --- .../EntityServices/PostsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index b3c98506..adfbd368 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -1595,6 +1595,27 @@ public async Task UpdateAsyncEnumerable_WhenPostExists_ShouldReturnPost(string n } } + /// + /// Update Async Enumerable posts. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var posts = SetupPostFixture() + .CreateMany(itemsCount) + .ToList(); + + _postsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _postsService.UpdateAsync(posts)); + } + #endregion #endregion From 2d11a2ecb882c764c76aabe8bd7f09da898a6798 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 23 Sep 2025 23:13:54 +0300 Subject: [PATCH 13/25] Add exception tests case for Update in post tag relations service tests --- .../PostTagRelationsServiceTests.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index 2e2da07d..e8029c20 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using AutoFixture; using AutoFixture.Dsl; using Blog.Core.Enums; @@ -15,6 +11,10 @@ using Blog.EntityServices.Interfaces; using Microsoft.EntityFrameworkCore; using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Xunit; namespace Blog.ServicesTests.EntityServices; @@ -1673,6 +1673,23 @@ public void Update_WhenPostTagRelationsExists_ShouldReturnPostTagRelation() Assert.Equal(postsTagsRelations.Tag.Title, newPostsTagsRelation.Tag.Title); } + /// + /// Update post tag relations. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void Update_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var postsTagsRelation = SetupPostsTagsRelationsFixture().Create(); + + _postsTagsRelationsRepositoryMock.Setup(x => x.Update(It.IsAny())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _postsTagsRelationsService.Update(postsTagsRelation)); + } + #endregion #region Upadate Enumerable function From 295740d9c9cf5f2f09bf9d92c9763a52ea884858 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Tue, 23 Sep 2025 23:14:07 +0300 Subject: [PATCH 14/25] Add exception tests case for Update Enumerable in post tag relations service tests --- .../PostTagRelationsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index e8029c20..92df2325 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -1773,6 +1773,27 @@ public void UpdateEnumerable_WhenPostTagRelationsExists_ShouldReturnPostTagRelat }); } + /// + /// Update Enumerable post tag relations. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void UpdateEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var postsTagsRelations = SetupPostsTagsRelationsFixture() + .CreateMany(itemsCount) + .ToList(); + + _postsTagsRelationsRepositoryMock.Setup(x => x.Update(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _postsTagsRelationsService.Update(postsTagsRelations)); + } + #endregion #region Update Async function From 1429cf13973b3c612e80c05037651adcae82ff98 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Wed, 24 Sep 2025 23:14:25 +0300 Subject: [PATCH 15/25] Add exception tests case for Update 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 92df2325..642c3225 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -1933,6 +1933,23 @@ public async Task UpdateAsync_WhenPostTagRelationExists_ShouldReturnPostTagRelat Assert.Equal(postsTagsRelations.Tag.Title, newTag.Title); } + /// + /// Async Update post tag relation. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var postsTagsRelation = SetupPostsTagsRelationsFixture().Create(); + + _postsTagsRelationsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _postsTagsRelationsService.UpdateAsync(postsTagsRelation)); + } + #endregion #region Upadate Async Enumerable function From e8af35a2ab81a1c74b18360da7c5c01361b6acda Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Wed, 24 Sep 2025 23:14:44 +0300 Subject: [PATCH 16/25] Add exception tests case for Update Async Enumerable in post tag relations service tests --- .../PostTagRelationsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index 642c3225..07b326df 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -2035,6 +2035,27 @@ public async Task UpdateAsyncEnumerable_WhenPostTagRelationsExists_ShouldReturnP }); } + /// + /// Update Async Enumerable post tag relations. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var postsTagsRelations = SetupPostsTagsRelationsFixture() + .CreateMany(itemsCount) + .ToList(); + + _postsTagsRelationsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _postsTagsRelationsService.UpdateAsync(postsTagsRelations)); + } + #endregion #endregion From 13f229370eacd7c9978ebd734dc78636de663ff6 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Wed, 24 Sep 2025 23:15:27 +0300 Subject: [PATCH 17/25] Add exception tests case for Update in profie service tests --- .../EntityServices/ProfileServiceTests.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index f826bd49..913602ac 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using AutoFixture; using AutoFixture.Dsl; using AutoMapper; @@ -16,6 +12,10 @@ using Blog.EntityServices.Interfaces; using Microsoft.EntityFrameworkCore; using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Xunit; using ProfileModel = Blog.Data.Models.Profile; @@ -1235,6 +1235,23 @@ public void Update_WhenProfileExists_ShouldReturnProfile() Assert.Equal(newUserId, profile.UserId); } + /// + /// Update profile. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void Update_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var profile = SetupProfileFixture().Create(); + + _profileRepositoryMock.Setup(x => x.Update(It.IsAny())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _profileService.Update(profile)); + } + #endregion #region Upadate Enumerable function From 9bab1bc267d4cf817640ed04ec50bb4f6036ff7c Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Thu, 25 Sep 2025 23:15:46 +0300 Subject: [PATCH 18/25] Add exception tests case for Update Enumerable in profie service tests --- .../EntityServices/ProfileServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index 913602ac..35d69cc5 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -1338,6 +1338,27 @@ public void UpdateEnumerable_WhenProfileExists_ShouldReturnProfile() } } + /// + /// Update Enumerable profiles. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void UpdateEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var profiles = SetupProfileFixture() + .CreateMany(itemsCount) + .ToList(); + + _profileRepositoryMock.Setup(x => x.Update(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _profileService.Update(profiles)); + } + #endregion #region Update Async function From 86fcb6e26a4033b838019788e443cce880fb34fe Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Thu, 25 Sep 2025 23:16:05 +0300 Subject: [PATCH 19/25] Add exception tests case for Update Async in profie 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 35d69cc5..ff6689f4 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -1424,6 +1424,23 @@ public async Task UpdateAsync_WhenMessageExists_ShouldReturnMessage() Assert.Equal(newUserId, profile.UserId); } + /// + /// Async Update profile. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var profile = SetupProfileFixture().Create(); + + _profileRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _profileService.UpdateAsync(profile)); + } + #endregion #region Upadate Async Enumerable function From b6704ef44e93afd6098ca39fc383caf1c066e352 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Thu, 25 Sep 2025 23:16:26 +0300 Subject: [PATCH 20/25] Add exception tests case for Update Async Enumerable in profie service tests --- .../EntityServices/ProfileServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index ff6689f4..a5e2683b 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -1529,6 +1529,27 @@ public async Task UpdateAsyncEnumerable_WhenProfileExists_ShouldReturnProfile() } } + /// + /// Update Async Enumerable profiles. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var profiles = SetupProfileFixture() + .CreateMany(itemsCount) + .ToList(); + + _profileRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _profileService.UpdateAsync(profiles)); + } + #endregion #endregion From 88fed2b128b500d94ff93a7c5d61b48fb8aac473 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Thu, 25 Sep 2025 23:16:53 +0300 Subject: [PATCH 21/25] Add exception tests case for Update 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 669596df..eccb8dcf 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -1277,6 +1277,23 @@ public void Update_WhenCommentExists_ShouldReturnComment(string newTagTitle) Assert.Equal(newTagTitle, tag.Title); } + /// + /// Update tag. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void Update_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var tag = SetupTagFixture().Create(); + + _tagsRepositoryMock.Setup(x => x.Update(It.IsAny())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _tagsService.Update(tag)); + } + #endregion #region Upadate Enumerable function From 44da3aea4dd53dde17b787f03eb92860335cb88c Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Thu, 25 Sep 2025 23:17:20 +0300 Subject: [PATCH 22/25] Add exception tests case for Update Enumerable in tags service tests --- .../EntityServices/TagsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs index eccb8dcf..891ad66a 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -1384,6 +1384,27 @@ public void UpdateEnumerable_WhenCommentExists_ShouldReturnComment(string newTag } } + /// + /// Update Enumerable tags. + /// Should throw exception when repository throws exception. + /// + [Fact] + public void UpdateEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var tags = SetupTagFixture() + .CreateMany(itemsCount) + .ToList(); + + _tagsRepositoryMock.Setup(x => x.Update(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + Assert.Throws(() => _tagsService.Update(tags)); + } + #endregion #region Update Async function From 3de9db4a501a3a96ec37dcea0a673dc5041dc32d Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Fri, 26 Sep 2025 23:17:54 +0300 Subject: [PATCH 23/25] Add exception tests case for Update Async 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 891ad66a..f96f6a2b 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -1477,6 +1477,23 @@ public async Task UpdateAsync_WhenCommentExists_ShouldReturnTag(string newTagTit Assert.Equal(newTagTitle, tag.Title); } + /// + /// Async Update tag. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var tag = SetupTagFixture().Create(); + + _tagsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _tagsService.UpdateAsync(tag)); + } + #endregion #region Upadate Async Enumerable function From 5b0d7af20f2d63a8090087f3f846356894b82576 Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Fri, 26 Sep 2025 23:18:14 +0300 Subject: [PATCH 24/25] Add exception tests case for Update Async Enumerable in tags service tests --- .../EntityServices/TagsServiceTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs index f96f6a2b..e6c35fe7 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -1582,6 +1582,27 @@ public async Task UpdateAsyncEnumerable_WhenCommentExists_ShouldReturnComment(st } } + /// + /// Update Async Enumerable tags. + /// Should throw exception when repository throws exception. + /// + [Fact] + public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThrowException() + { + //Arrange + var random = new Random(); + var itemsCount = random.Next(100); + var tags = SetupTagFixture() + .CreateMany(itemsCount) + .ToList(); + + _tagsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) + .Throws(new Exception("Test exception")); + + //Assert + await Assert.ThrowsAsync(() => _tagsService.UpdateAsync(tags)); + } + #endregion #endregion From 679bbcf64fd7c638dd9f99f87d6204ade80c28dc Mon Sep 17 00:00:00 2001 From: Vitalii Lakatosh Date: Sat, 27 Sep 2025 11:45:46 +0300 Subject: [PATCH 25/25] Fix failing tests --- .../Blog.ServicesTests/EntityServices/CommentsServiceTests.cs | 2 +- .../Blog.ServicesTests/EntityServices/MessagesServiceTests.cs | 2 +- .../EntityServices/PostTagRelationsServiceTests.cs | 2 +- .../Blog.ServicesTests/EntityServices/PostsServiceTests.cs | 2 +- .../Blog.ServicesTests/EntityServices/ProfileServiceTests.cs | 2 +- .../Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs index be0f7949..7dec1841 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs @@ -1568,7 +1568,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro .ToList(); _commentsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) - .Throws(new Exception("Test exception")); + .ThrowsAsync(new Exception("Test exception")); //Assert await Assert.ThrowsAsync(() => _commentsService.UpdateAsync(comments)); diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs index 27cd0474..a52c5371 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs @@ -1596,7 +1596,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro .ToList(); _messagesRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) - .Throws(new Exception("Test exception")); + .ThrowsAsync(new Exception("Test exception")); //Assert await Assert.ThrowsAsync(() => _messagesService.UpdateAsync(messages)); diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs index 07b326df..7e265c89 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs @@ -2050,7 +2050,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro .ToList(); _postsTagsRelationsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) - .Throws(new Exception("Test exception")); + .ThrowsAsync(new Exception("Test exception")); //Assert await Assert.ThrowsAsync(() => _postsTagsRelationsService.UpdateAsync(postsTagsRelations)); diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs index adfbd368..ddd35862 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs @@ -1610,7 +1610,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro .ToList(); _postsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) - .Throws(new Exception("Test exception")); + .ThrowsAsync(new Exception("Test exception")); //Assert await Assert.ThrowsAsync(() => _postsService.UpdateAsync(posts)); diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs index a5e2683b..911e57ff 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs @@ -1544,7 +1544,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro .ToList(); _profileRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) - .Throws(new Exception("Test exception")); + .ThrowsAsync(new Exception("Test exception")); //Assert await Assert.ThrowsAsync(() => _profileService.UpdateAsync(profiles)); diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs index e6c35fe7..f8a6f8c4 100644 --- a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs +++ b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs @@ -1597,7 +1597,7 @@ public async Task UpdateAsyncEnumerable_WhenRepositoryThrowsException_ShouldThro .ToList(); _tagsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny>())) - .Throws(new Exception("Test exception")); + .ThrowsAsync(new Exception("Test exception")); //Assert await Assert.ThrowsAsync(() => _tagsService.UpdateAsync(tags));