Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ae8c6fb
Add exception tests case for Update in comments service tests
lakatoshv Sep 19, 2025
82d7e31
Add exception tests case for Update Enumerable in comments service tests
lakatoshv Sep 19, 2025
603bdb6
Add exception tests case for Update Async in comments service tests
lakatoshv Sep 20, 2025
f0fb66f
Add exception tests case for Update Async Enumerable in comments serv…
lakatoshv Sep 20, 2025
16568c8
Add exception tests case for Update in messages service tests
lakatoshv Sep 20, 2025
d908f03
Add exception tests case for Update Enumerable in messages service tests
lakatoshv Sep 21, 2025
4b81837
Add exception tests case for Update Async in messages service tests
lakatoshv Sep 21, 2025
680f970
Add exception tests case for Update Async Enumerable in messages serv…
lakatoshv Sep 21, 2025
e186b68
Add exception tests case for Update in posts service tests
lakatoshv Sep 22, 2025
b08663f
Add exception tests case for Update Enumerable in posts service tests
lakatoshv Sep 22, 2025
0610b8f
Add exception tests case for Update Async in posts service tests
lakatoshv Sep 22, 2025
4a16f15
Add exception tests case for Update Async Enumerable in posts service…
lakatoshv Sep 23, 2025
2d11a2e
Add exception tests case for Update in post tag relations service tests
lakatoshv Sep 23, 2025
295740d
Add exception tests case for Update Enumerable in post tag relations …
lakatoshv Sep 23, 2025
1429cf1
Add exception tests case for Update Async in post tag relations servi…
lakatoshv Sep 24, 2025
e8af35a
Add exception tests case for Update Async Enumerable in post tag rela…
lakatoshv Sep 24, 2025
13f2293
Add exception tests case for Update in profie service tests
lakatoshv Sep 24, 2025
9bab1bc
Add exception tests case for Update Enumerable in profie service tests
lakatoshv Sep 25, 2025
86fcb6e
Add exception tests case for Update Async in profie service tests
lakatoshv Sep 25, 2025
b6704ef
Add exception tests case for Update Async Enumerable in profie servic…
lakatoshv Sep 25, 2025
88fed2b
Add exception tests case for Update in tags service tests
lakatoshv Sep 25, 2025
44da3ae
Add exception tests case for Update Enumerable in tags service tests
lakatoshv Sep 25, 2025
3de9db4
Add exception tests case for Update Async in tags service tests
lakatoshv Sep 26, 2025
5b0d7af
Add exception tests case for Update Async Enumerable in tags service …
lakatoshv Sep 26, 2025
679bbcf
Fix failing tests
lakatoshv Sep 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1261,6 +1261,23 @@ public void Update_WhenCommentExists_ShouldReturnComment(string newCommentBody)
Assert.Equal(newCommentBody, comment.CommentBody);
}

/// <summary>
/// Update comment.
/// Should throw exception when repository throws exception.
/// </summary>
[Fact]
public void Update_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var comment = SetupCommentFixture().Create();

_commentsRepositoryMock.Setup(x => x.Update(It.IsAny<Comment>()))
.Throws(new Exception("Test exception"));

//Assert
Assert.Throws<Exception>(() => _commentsService.Update(comment));
}

#endregion

#region Upadate Enumerable function
Expand Down Expand Up @@ -1344,6 +1361,27 @@ public void UpdateEnumerable_WhenCommentExists_ShouldReturnComment(string newCom
}
}

/// <summary>
/// Update Enumerable comments.
/// Should throw exception when repository throws exception.
/// </summary>
[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<IEnumerable<Comment>>()))
.Throws(new Exception("Test exception"));

//Assert
Assert.Throws<Exception>(() => _commentsService.Update(comments));
}

#endregion

#region Update Async function
Expand Down Expand Up @@ -1413,6 +1451,23 @@ public async Task UpdateAsync_WhenCommentExists_ShouldReturnComment(string newCo
Assert.Equal(newCommentBody, comment.CommentBody);
}

/// <summary>
/// Async Update comment.
/// Should throw exception when repository throws exception.
/// </summary>
[Fact]
public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var comment = SetupCommentFixture().Create();

_commentsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny<Comment>()))
.ThrowsAsync(new Exception("Test exception"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _commentsService.UpdateAsync(comment));
}

#endregion

#region Upadate Async Enumerable function
Expand Down Expand Up @@ -1498,6 +1553,27 @@ public async Task UpdateAsyncEnumerable_WhenCommentExists_ShouldReturnComment(st
}
}

/// <summary>
/// Update Async Enumerable comments.
/// Should throw exception when repository throws exception.
/// </summary>
[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<IEnumerable<Comment>>()))
.ThrowsAsync(new Exception("Test exception"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _commentsService.UpdateAsync(comments));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,23 @@ public void Update_WhenMessageExists_ShouldReturnMessage(string newMessageSubjec
Assert.Equal(newMessageSubject, message.Subject);
}

/// <summary>
/// Update message.
/// Should throw exception when repository throws exception.
/// </summary>
[Fact]
public void Update_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var message = SetupMessageFixture().Create();

_messagesRepositoryMock.Setup(x => x.Update(It.IsAny<Message>()))
.Throws(new Exception("Test exception"));

//Assert
Assert.Throws<Exception>(() => _messagesService.Update(message));
}

#endregion

#region Upadate Enumerable function
Expand Down Expand Up @@ -1368,6 +1385,27 @@ public void UpdateEnumerable_WhenMessageExists_ShouldReturnMessage(string newMes
}
}

/// <summary>
/// Update Enumerable messages.
/// Should throw exception when repository throws exception.
/// </summary>
[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<IEnumerable<Message>>()))
.Throws(new Exception("Test exception"));

//Assert
Assert.Throws<Exception>(() => _messagesService.Update(messages));
}

#endregion

#region Update Async function
Expand Down Expand Up @@ -1440,6 +1478,23 @@ public async Task UpdateAsync_WhenMessageExists_ShouldReturnMessage(string newMe
Assert.Equal(newMessageSubject, message.Subject);
}

/// <summary>
/// Async Update message.
/// Should throw exception when repository throws exception.
/// </summary>
[Fact]
public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var message = SetupMessageFixture().Create();

_messagesRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny<Message>()))
.ThrowsAsync(new Exception("Test exception"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _messagesService.UpdateAsync(message));
}

#endregion

#region Upadate Async Enumerable function
Expand Down Expand Up @@ -1526,6 +1581,27 @@ public async Task UpdateAsyncEnumerable_WhenMessageExists_ShouldReturnMessage(st
}
}

/// <summary>
/// Update Async Enumerable messages.
/// Should throw exception when repository throws exception.
/// </summary>
[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<IEnumerable<Message>>()))
.ThrowsAsync(new Exception("Test exception"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _messagesService.UpdateAsync(messages));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1673,6 +1673,23 @@ public void Update_WhenPostTagRelationsExists_ShouldReturnPostTagRelation()
Assert.Equal(postsTagsRelations.Tag.Title, newPostsTagsRelation.Tag.Title);
}

/// <summary>
/// Update post tag relations.
/// Should throw exception when repository throws exception.
/// </summary>
[Fact]
public void Update_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var postsTagsRelation = SetupPostsTagsRelationsFixture().Create();

_postsTagsRelationsRepositoryMock.Setup(x => x.Update(It.IsAny<PostsTagsRelations>()))
.Throws(new Exception("Test exception"));

//Assert
Assert.Throws<Exception>(() => _postsTagsRelationsService.Update(postsTagsRelation));
}

#endregion

#region Upadate Enumerable function
Expand Down Expand Up @@ -1756,6 +1773,27 @@ public void UpdateEnumerable_WhenPostTagRelationsExists_ShouldReturnPostTagRelat
});
}

/// <summary>
/// Update Enumerable post tag relations.
/// Should throw exception when repository throws exception.
/// </summary>
[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<IEnumerable<PostsTagsRelations>>()))
.Throws(new Exception("Test exception"));

//Assert
Assert.Throws<Exception>(() => _postsTagsRelationsService.Update(postsTagsRelations));
}

#endregion

#region Update Async function
Expand Down Expand Up @@ -1895,6 +1933,23 @@ public async Task UpdateAsync_WhenPostTagRelationExists_ShouldReturnPostTagRelat
Assert.Equal(postsTagsRelations.Tag.Title, newTag.Title);
}

/// <summary>
/// Async Update post tag relation.
/// Should throw exception when repository throws exception.
/// </summary>
[Fact]
public async Task UpdateAsync_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var postsTagsRelation = SetupPostsTagsRelationsFixture().Create();

_postsTagsRelationsRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny<PostsTagsRelations>()))
.ThrowsAsync(new Exception("Test exception"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _postsTagsRelationsService.UpdateAsync(postsTagsRelation));
}

#endregion

#region Upadate Async Enumerable function
Expand Down Expand Up @@ -1980,6 +2035,27 @@ public async Task UpdateAsyncEnumerable_WhenPostTagRelationsExists_ShouldReturnP
});
}

/// <summary>
/// Update Async Enumerable post tag relations.
/// Should throw exception when repository throws exception.
/// </summary>
[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<IEnumerable<PostsTagsRelations>>()))
.ThrowsAsync(new Exception("Test exception"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _postsTagsRelationsService.UpdateAsync(postsTagsRelations));
}

#endregion

#endregion
Expand Down
Loading
Loading