-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from SaintAngeLs/comments_test
(#148) Comments tests new PR
- Loading branch information
Showing
586 changed files
with
265,181 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Dto/CommentDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Dto/PageableDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Dto/SortDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Core/Wrappers/PagedResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Core/Wrappers/Response.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...vices.Comments/src/MiniSpace.Services.Comments.Infrastructure/Contexts/IdentityContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...omments/src/MiniSpace.Services.Comments.Infrastructure/Mongo/Documents/CommentDocument.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ces.Comments/src/MiniSpace.Services.Comments.Infrastructure/Mongo/Documents/Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...omments/src/MiniSpace.Services.Comments.Infrastructure/Mongo/Documents/StudentDocument.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...MiniSpace.Services.Comments.Application.UnitTests/Commands/Handlers/AddLikeHandlerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Xunit; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using MiniSpace.Services.Comments.Application.Exceptions; | ||
using MiniSpace.Services.Comments.Application.Services; | ||
using MiniSpace.Services.Comments.Core.Entities; | ||
using MiniSpace.Services.Comments.Core.Repositories; | ||
using MiniSpace.Services.Comments.Application.Commands.Handlers; | ||
using MiniSpace.Services.Comments.Application.Commands; | ||
using MiniSpace.Services.Comments.Infrastructure.Contexts; | ||
using System.Threading; | ||
using FluentAssertions; | ||
|
||
namespace MiniSpace.Services.Comments.Application.UnitTests.Commands.Handlers | ||
{ | ||
public class AddLikeHandlerTest | ||
{ | ||
private readonly AddLikeHandler _addLikeHandler; | ||
private readonly Mock<ICommentRepository> _commentRepositoryMock; | ||
private readonly Mock<IMessageBroker> _messageBrokerMock; | ||
private readonly Mock<IAppContext> _appContextMock; | ||
|
||
public AddLikeHandlerTest() | ||
{ | ||
_commentRepositoryMock = new Mock<ICommentRepository>(); | ||
_messageBrokerMock = new Mock<IMessageBroker>(); | ||
_appContextMock = new Mock<IAppContext>(); | ||
_addLikeHandler = new AddLikeHandler(_commentRepositoryMock.Object, _appContextMock.Object, _messageBrokerMock.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task HandleAsync_WithValidCommentAndAuthorised_ShouldAddLike() | ||
{ | ||
// Arrange | ||
var commentId = Guid.NewGuid(); | ||
var comand = new AddLike(commentId); | ||
|
||
var comment = Comment.Create(new AggregateId(commentId), Guid.NewGuid(), CommentContext.Post, Guid.NewGuid(), "Adam", Guid.NewGuid(), "text", DateTime.Now); | ||
|
||
var identityContext = new IdentityContext(Guid.NewGuid().ToString(), "", true, new Dictionary<string, string>()); | ||
|
||
_appContextMock.Setup(ctx => ctx.Identity).Returns(identityContext); | ||
_commentRepositoryMock.Setup(repo => repo.GetAsync(comment.Id)).ReturnsAsync(comment); | ||
|
||
var cancelationToken = new CancellationToken(); | ||
|
||
// Act | ||
await _addLikeHandler.HandleAsync(comand, cancelationToken); | ||
|
||
// Assert | ||
_commentRepositoryMock.Verify(repo => repo.UpdateAsync(comment), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public async Task HandleAsync_WithInvalidComment_ShouldThrowCommentNotFoundExeption() | ||
{ | ||
// Arrange | ||
var commentId = Guid.NewGuid(); | ||
var comand = new AddLike(commentId); | ||
_commentRepositoryMock.Setup(repo => repo.GetAsync(comand.CommentId)).ReturnsAsync((Comment)null); | ||
var cancelationToken = new CancellationToken(); | ||
|
||
// Act & Assert | ||
Func<Task> act = async () => await _addLikeHandler.HandleAsync(comand, cancelationToken); | ||
await act.Should().ThrowAsync<CommentNotFoundException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task HandleAsync_WithNonPermitedIdentity_ShouldThrowUnauthorizedCommentAccessException() | ||
{ | ||
// Arrange | ||
var commentId = Guid.NewGuid(); | ||
var comand = new AddLike(commentId); | ||
|
||
var comment = Comment.Create(new AggregateId(commentId), Guid.NewGuid(), CommentContext.Post, Guid.NewGuid(), "Adam", Guid.NewGuid(), "text", DateTime.Now); | ||
|
||
var identityContext = new IdentityContext(Guid.NewGuid().ToString(), "", false, new Dictionary<string, string>()); | ||
|
||
_appContextMock.Setup(ctx => ctx.Identity).Returns(identityContext); | ||
_commentRepositoryMock.Setup(repo => repo.GetAsync(comment.Id)).ReturnsAsync(comment); | ||
|
||
var cancelationToken = new CancellationToken(); | ||
|
||
// Act & Assert | ||
Func<Task> act = async () => await _addLikeHandler.HandleAsync(comand, cancelationToken); | ||
await act.Should().ThrowAsync<UnauthorizedCommentAccessException>(); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.