-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/RealEskalate/2023-project-p…
…hase-starter-projects into aait.mobile.g1.fikremariam-fikadu.Article-imageUpload
- Loading branch information
Showing
709 changed files
with
19,900 additions
and
5,254 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
96 changes: 96 additions & 0 deletions
96
...group-1A/Application.Tests/Features/CommentFeatureTest/Command/CreatCommentHandlerTest.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,96 @@ | ||
using Application.DTO.CommentDTO.DTO; | ||
using Application.Profiles; | ||
using Application.Response; | ||
using Application.Tests.Mocks; | ||
using AutoMapper; | ||
using Shouldly; | ||
using Application.Features.CommentFeatures.Handlers.Commands; | ||
using Application.Features.CommentFeatures.Requests.Commands; | ||
using Application.Exceptions; | ||
using MediatR; | ||
using Moq; | ||
using Application.Contracts; | ||
using Application.Features.NotificationFeaure.Requests.Commands; | ||
|
||
namespace Application.Tests.Features.CommentFeatureTest.Commands | ||
{ | ||
public class CreateCommentHandlerTest | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly Mock<IUnitOfWork> _mockUnitOfWork; | ||
|
||
private readonly Mock<IMediator> _mediator; | ||
private CommentCreateDTO testComment; | ||
public CreateCommentHandlerTest() | ||
{ | ||
|
||
_mockUnitOfWork = MockUnitOfWork.GetUnitOfWork(); | ||
|
||
var mapperConfig = new MapperConfiguration(c => | ||
{ | ||
c.AddProfile<MappingProfile>(); | ||
}); | ||
|
||
_mapper = mapperConfig.CreateMapper(); | ||
_mediator = new Mock<IMediator>(); | ||
|
||
testComment = new CommentCreateDTO() | ||
{ | ||
PostId = 1, | ||
Content = "Test comment" | ||
}; | ||
} | ||
|
||
[Fact] | ||
public async Task ValidCreateCommentTest() | ||
{ | ||
// arrange | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var mocCommentRepository = MockCommentRepository.GetCommentRepository().Object; | ||
var mocPostRepository = MockPostRepository.GetPostRepository().Object; | ||
var handler = new CommentCreateHandler(_mockUnitOfWork.Object,_mapper,_mediator.Object ); | ||
|
||
// act | ||
var result = await handler.Handle(new CommentCreateCommand() {NewCommentData = testComment,userId = 1}, CancellationToken.None); | ||
|
||
// assert | ||
result.ShouldBeOfType<BaseResponse<CommentResponseDTO>>(); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateCommentForNonExistentPostTest() | ||
{ | ||
// arrange | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var mocCommentRepository = MockCommentRepository.GetCommentRepository().Object; | ||
var mocPostRepository = MockPostRepository.GetPostRepository().Object; | ||
var handler = new CommentCreateHandler(_mockUnitOfWork.Object,_mapper,_mediator.Object ); | ||
testComment.PostId = 100; | ||
|
||
// act and assert | ||
await Should.ThrowAsync<NotFoundException>(async () => | ||
await handler.Handle(new CommentCreateCommand() {NewCommentData = testComment,userId = 1}, CancellationToken.None)); | ||
} | ||
[Fact] | ||
public async Task CreateCommentWithNoContentTest() | ||
{ | ||
// arrange | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var mocCommentRepository = MockCommentRepository.GetCommentRepository().Object; | ||
var mocPostRepository = MockPostRepository.GetPostRepository().Object; | ||
var handler = new CommentCreateHandler(_mockUnitOfWork.Object,_mapper,_mediator.Object ); | ||
testComment.Content = ""; | ||
|
||
// act and arrange | ||
|
||
await Should.ThrowAsync<ValidationException>(async () => | ||
await handler.Handle(new CommentCreateCommand() {NewCommentData = testComment,userId = 1}, CancellationToken.None)); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...roup-1A/Application.Tests/Features/CommentFeatureTest/Command/DeleteCommentHandlerTest.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,52 @@ | ||
using Application.Contracts; | ||
using Application.Exceptions; | ||
using Application.Features.CommentFeatures.Handlers.Commands; | ||
using Application.Features.CommentFeatures.Requests.Commands; | ||
using Application.Features.NotificationFeaure.Requests.Commands; | ||
using Application.Response; | ||
using Application.Tests.Mocks; | ||
using MediatR; | ||
using Moq; | ||
using Shouldly; | ||
|
||
namespace Application.Tests.Features.CommentFeatureTest.Commands | ||
{ | ||
public class DeleteCommentHandlerTest | ||
{ | ||
private readonly Mock<IUnitOfWork> _mockUnitOfWork; | ||
|
||
private readonly Mock<IMediator> _mediator; | ||
public DeleteCommentHandlerTest() | ||
{ | ||
_mockUnitOfWork = MockUnitOfWork.GetUnitOfWork(); | ||
_mediator = new Mock<IMediator>(); | ||
|
||
} | ||
|
||
[Fact] | ||
public async Task DeleteCommentValidTest() | ||
{ | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var mocCommentRepository = MockCommentRepository.GetCommentRepository().Object; | ||
var handler = new CommentDeleteHandler(_mockUnitOfWork.Object, _mediator.Object); | ||
|
||
var result = await handler.Handle(new CommentDeleteCommand() { Id = 1 }, CancellationToken.None); | ||
|
||
result.ShouldBeOfType<BaseResponse<int>>(); | ||
} | ||
[Fact] | ||
public async Task DeleteCommentWithInValidIdTest() | ||
{ | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var mocCommentRepository = MockCommentRepository.GetCommentRepository().Object; | ||
var handler = new CommentDeleteHandler(_mockUnitOfWork.Object, _mediator.Object); | ||
|
||
await Should.ThrowAsync<NotFoundException>(async () => | ||
await handler.Handle(new CommentDeleteCommand(), CancellationToken.None)); | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...roup-1A/Application.Tests/Features/CommentFeatureTest/Command/UpdateCommentHandlerTest.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,106 @@ | ||
using Application.Contracts; | ||
using Application.DTO.CommentDTO.DTO; | ||
using Application.Exceptions; | ||
using Application.Features.CommentFeatures.Handlers.Commands; | ||
using Application.Features.CommentFeatures.Requests.Commands; | ||
using Application.Features.NotificationFeaure.Requests.Commands; | ||
using Application.Profiles; | ||
using Application.Response; | ||
using Application.Tests.Mocks; | ||
using AutoMapper; | ||
using MediatR; | ||
using Moq; | ||
using Shouldly; | ||
|
||
namespace Application.Tests.Features.CommentFeatureTest.Commands | ||
{ | ||
public class UpdateCommentHandlerTest | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly Mock<IUnitOfWork> _mockUnitOfWork; | ||
|
||
private readonly Mock<IMediator> _mediator; | ||
CommentUpdateDTO testComment; | ||
public UpdateCommentHandlerTest() | ||
{ | ||
|
||
_mockUnitOfWork = MockUnitOfWork.GetUnitOfWork(); | ||
|
||
var mapperConfig = new MapperConfiguration(c => | ||
{ | ||
c.AddProfile<MappingProfile>(); | ||
}); | ||
|
||
_mapper = mapperConfig.CreateMapper(); | ||
_mediator = new Mock<IMediator>(); | ||
|
||
testComment = new CommentUpdateDTO() | ||
{ | ||
Content = "Test comment" | ||
}; | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateCommentValidTest() | ||
{ | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var _mockRepo = MockCommentRepository.GetCommentRepository(); | ||
|
||
var handler = new UpdateCommentHandler(_mockUnitOfWork.Object, _mapper, _mediator.Object); | ||
|
||
testComment.Content = "Updated comment"; | ||
var result = await handler.Handle(new UpdateCommentCommand() | ||
{ | ||
Id = 1, | ||
userId = 1, | ||
CommentData = testComment | ||
|
||
}, CancellationToken.None); | ||
|
||
result.ShouldBeOfType<BaseResponse<CommentResponseDTO>>(); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateCommentWithNoContentTest() | ||
{ | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var _mockRepo = MockCommentRepository.GetCommentRepository(); | ||
|
||
var handler = new UpdateCommentHandler(_mockUnitOfWork.Object, _mapper, _mediator.Object); | ||
|
||
testComment.Content = ""; | ||
await Should.ThrowAsync<ValidationException>(async () => await handler.Handle(new UpdateCommentCommand() | ||
{ | ||
Id = 1, | ||
userId = 1, | ||
CommentData = testComment | ||
|
||
}, CancellationToken.None)); | ||
|
||
} | ||
[Fact] | ||
public async Task UpdateNonExistentCommentTest() | ||
{ | ||
_mediator.Setup( | ||
x => x.Send(It.IsAny<CreateNotification>(), It.IsAny<CancellationToken>())).ReturnsAsync(true); | ||
|
||
var _mockRepo = MockCommentRepository.GetCommentRepository(); | ||
|
||
var handler = new UpdateCommentHandler(_mockUnitOfWork.Object, _mapper, _mediator.Object); | ||
|
||
testComment.Content = "Updated comment"; | ||
await Should.ThrowAsync<NotFoundException>(async () => await handler.Handle(new UpdateCommentCommand() | ||
{ | ||
Id = 100, | ||
userId = 1, | ||
CommentData = testComment | ||
|
||
}, CancellationToken.None)); | ||
|
||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...d/group-1A/Application.Tests/Features/CommentFeatureTest/Queries/GetCommentHandlerTest.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,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Application.Contracts; | ||
using Application.DTO.CommentDTO.DTO; | ||
using Application.Exceptions; | ||
using Application.Features.CommentFeatures.Handlers.Queries; | ||
using Application.Features.CommentFeatures.Requests.Queries; | ||
using Application.Profiles; | ||
using Application.Response; | ||
using Application.Tests.Mocks; | ||
using AutoMapper; | ||
using Moq; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Application.Tests.Features.CommentFeatureTest.Queries | ||
{ | ||
public class GetCommentHandlerTest | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly Mock<IUnitOfWork> _mockUnitOfWork; | ||
|
||
public GetCommentHandlerTest() | ||
{ | ||
_mockUnitOfWork = MockUnitOfWork.GetUnitOfWork(); | ||
|
||
var mapperConfig = new MapperConfiguration(c => | ||
{ | ||
c.AddProfile<MappingProfile>(); | ||
}); | ||
|
||
_mapper = mapperConfig.CreateMapper(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetValidCommentTest() | ||
{ | ||
var _mockRepo = MockCommentRepository.GetCommentRepository(); | ||
|
||
var handler = new GetCommentQueryHandler(_mockUnitOfWork.Object, _mapper); | ||
var result = await handler.Handle(new GetSingleCommentQuery() | ||
{ | ||
Id = 1 | ||
}, CancellationToken.None); | ||
|
||
result.ShouldBeOfType<BaseResponse<CommentResponseDTO>>(); | ||
} | ||
[Fact] | ||
public async Task GetInValidCommentTest() | ||
{ | ||
var _mockRepo = MockCommentRepository.GetCommentRepository(); | ||
|
||
var handler = new GetCommentQueryHandler(_mockUnitOfWork.Object, _mapper); | ||
|
||
await Should.ThrowAsync<BadRequestException>(async () => await handler.Handle(new GetSingleCommentQuery() | ||
{ | ||
Id = 100 | ||
}, CancellationToken.None)); | ||
} | ||
} | ||
} |
Oops, something went wrong.