diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/CommentsServiceTests.cs
index 1e2647ff..7dec1841 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
@@ -1344,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
@@ -1413,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
@@ -1498,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>()))
+ .ThrowsAsync(new Exception("Test exception"));
+
+ //Assert
+ await Assert.ThrowsAsync(() => _commentsService.UpdateAsync(comments));
+ }
+
#endregion
#endregion
diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/MessagesServiceTests.cs
index 2c43e695..a52c5371 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
@@ -1368,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
@@ -1440,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
@@ -1526,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>()))
+ .ThrowsAsync(new Exception("Test exception"));
+
+ //Assert
+ await Assert.ThrowsAsync(() => _messagesService.UpdateAsync(messages));
+ }
+
#endregion
#endregion
diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostTagRelationsServiceTests.cs
index 2e2da07d..7e265c89 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
@@ -1756,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
@@ -1895,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
@@ -1980,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>()))
+ .ThrowsAsync(new Exception("Test exception"));
+
+ //Assert
+ await Assert.ThrowsAsync(() => _postsTagsRelationsService.UpdateAsync(postsTagsRelations));
+ }
+
#endregion
#endregion
diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/PostsServiceTests.cs
index 08daee22..ddd35862 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
@@ -1382,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
@@ -1450,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
@@ -1540,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>()))
+ .ThrowsAsync(new Exception("Test exception"));
+
+ //Assert
+ await Assert.ThrowsAsync(() => _postsService.UpdateAsync(posts));
+ }
+
#endregion
#endregion
diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/ProfileServiceTests.cs
index f826bd49..911e57ff 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
@@ -1321,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
@@ -1386,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
@@ -1474,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>()))
+ .ThrowsAsync(new Exception("Test exception"));
+
+ //Assert
+ await Assert.ThrowsAsync(() => _profileService.UpdateAsync(profiles));
+ }
+
#endregion
#endregion
diff --git a/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs b/BlogWebApp/Tests/Blog.ServicesTests/EntityServices/TagsServiceTests.cs
index 669596df..f8a6f8c4 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
@@ -1367,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
@@ -1439,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
@@ -1527,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>()))
+ .ThrowsAsync(new Exception("Test exception"));
+
+ //Assert
+ await Assert.ThrowsAsync(() => _tagsService.UpdateAsync(tags));
+ }
+
#endregion
#endregion