Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -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;
Expand Down Expand Up @@ -2200,6 +2201,22 @@ public void Any_WithEqualSpecification_WhenCommentDoesNotExists_ShouldReturnNoth
Assert.False(areAnyComments);
}

/// <summary>
/// Any.
/// When repository throws exception should throw exception.
/// </summary>
[Fact]
public void Any_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var specification = new CommentSpecification(x => x.CommentBody.Equals("Comment 0"));
_commentsRepositoryMock.Setup(r => r.Any(It.IsAny<ISpecification<Comment>>()))
.Throws(new Exception("DB error"));

//Assert
Assert.Throws<Exception>(() => _commentsService.Any(specification));
}

#endregion

#region Any Async function With Specification
Expand Down Expand Up @@ -2337,6 +2354,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenCommentDoesNotExists_Shoul
Assert.False(areAnyComments);
}

/// <summary>
/// Any async.
/// When repository throws exception should throw exception.
/// </summary>
[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<ISpecification<Comment>>()))
.ThrowsAsync(new Exception("DB error"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _commentsService.AnyAsync(specification));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2270,6 +2271,22 @@ public void Any_WithEqualSpecification_WhenMessagesDoesNotExists_ShouldReturnNot
Assert.False(areAnyMessages);
}

/// <summary>
/// Any.
/// When repository throws exception should throw exception.
/// </summary>
[Fact]
public void Any_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var specification = new MessageSpecification(x => x.Subject.Equals("Test subject0"));
_messagesRepositoryMock.Setup(r => r.Any(It.IsAny<ISpecification<Message>>()))
.Throws(new Exception("DB error"));

//Assert
Assert.Throws<Exception>(() => _messagesService.Any(specification));
}

#endregion

#region Any Async function With Specification
Expand Down Expand Up @@ -2407,6 +2424,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenMessagesDoesNotExists_Shou
Assert.False(areAnyMessages);
}

/// <summary>
/// Any async.
/// When repository throws exception should throw exception.
/// </summary>
[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<ISpecification<Message>>()))
.ThrowsAsync(new Exception("DB error"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _messagesService.AnyAsync(specification));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,23 @@ public void Any_WithEqualSpecification_WhenPostTagRelationDoesNotExists_ShouldRe
Assert.False(areAnyPosts);
}

/// <summary>
/// Any.
/// When repository throws exception should throw exception.
/// </summary>
[Fact]
public void Any_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var specification =
new BaseSpecification<PostsTagsRelations>(x => x.Tag.Title.Equals("Created from ServicesTests 0"));
_postsTagsRelationsRepositoryMock.Setup(r => r.Any(It.IsAny<ISpecification<PostsTagsRelations>>()))
.Throws(new Exception("DB error"));

//Assert
Assert.Throws<Exception>(() => _postsTagsRelationsService.Any(specification));
}

#endregion

#region Any Async function With Specification
Expand Down Expand Up @@ -2886,6 +2903,23 @@ public async Task AnyAsync_WithEqualSpecification_WhenPostTagRelationDoesNotExis
Assert.False(areAnyPosts);
}

/// <summary>
/// Any async.
/// When repository throws exception should throw exception.
/// </summary>
[Fact]
public async Task AnyAsync_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var specification =
new BaseSpecification<PostsTagsRelations>(x => x.Tag.Title.Equals("Created from ServicesTests 0"));
_postsTagsRelationsRepositoryMock.Setup(r => r.AnyAsync(It.IsAny<ISpecification<PostsTagsRelations>>()))
.ThrowsAsync(new Exception("DB error"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _postsTagsRelationsService.AnyAsync(specification));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2252,6 +2253,22 @@ public void Any_WithEqualSpecification_WhenPostDoesNotExists_ShouldReturnNothing
Assert.False(areAnyPosts);
}

/// <summary>
/// Any.
/// When repository throws exception should throw exception.
/// </summary>
[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<ISpecification<Post>>()))
.Throws(new Exception("DB error"));

//Assert
Assert.Throws<Exception>(() => _postsService.Any(specification));
}

#endregion

#region Any Async function With Specification
Expand Down Expand Up @@ -2389,6 +2406,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenPostDoesNotExists_ShouldRe
Assert.False(areAnyPosts);
}

/// <summary>
/// Any async.
/// When repository throws exception should throw exception.
/// </summary>
[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<ISpecification<Post>>()))
.ThrowsAsync(new Exception("DB error"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _postsService.AnyAsync(specification));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -2179,6 +2180,23 @@ public void Any_WithEqualSpecification_WhenProfilesDoesNotExists_ShouldReturnNot
Assert.False(areAnyProfiles);
}

/// <summary>
/// Any.
/// When repository throws exception should throw exception.
/// </summary>
[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<ISpecification<ProfileModel>>()))
.Throws(new Exception("DB error"));

//Assert
Assert.Throws<Exception>(() => _profileService.Any(specification));
}

#endregion

#region Any Async function With Specification
Expand Down Expand Up @@ -2290,6 +2308,23 @@ public async Task AnyAsync_WithEqualSpecification_WhenProfilesDoesNotExists_Shou
Assert.False(areAnyProfiles);
}

/// <summary>
/// Any async.
/// When repository throws exception should throw exception.
/// </summary>
[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<ISpecification<ProfileModel>>()))
.ThrowsAsync(new Exception("DB error"));

//Assert
await Assert.ThrowsAsync<Exception>(() => _profileService.AnyAsync(specification));
}

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2253,6 +2254,22 @@ public void Any_WithEqualSpecification_WhenCommentDoesNotExists_ShouldReturnNoth
Assert.False(areAnyTags);
}

/// <summary>
/// Any.
/// When repository throws exception should throw exception.
/// </summary>
[Fact]
public void Any_WhenRepositoryThrowsException_ShouldThrowException()
{
//Arrange
var specification = new TagSpecification(x => x.Title.Equals("Tag 0"));
_tagsRepositoryMock.Setup(r => r.Any(It.IsAny<ISpecification<Tag>>()))
.Throws(new Exception("DB error"));

//Assert
Assert.Throws<Exception>(() => _tagsService.Any(specification));
}

#endregion

#region Any Async function With Specification
Expand Down Expand Up @@ -2394,6 +2411,22 @@ public async Task AnyAsync_WithEqualSpecification_WhenTagDoesNotExists_ShouldRet
Assert.False(areAnyTags);
}

/// <summary>
/// Any async.
/// When repository throws exception should throw exception.
/// </summary>
[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<Exception>(() => _tagsService.AnyAsync(specification));
}

#endregion

#endregion
Expand Down
Loading