-
Notifications
You must be signed in to change notification settings - Fork 0
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 #37 from DFE-Digital/notes-unit-tests
notes unit tests
- Loading branch information
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...Tests/CommandHandlers/SupportProject/Notes/CreateSupportProjectNoteCommandHandlerTests.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,72 @@ | ||
using AutoFixture; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.CreateSupportProjectNote; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.UpdateSupportProject; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Interfaces.Repositories; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Domain.ValueObjects; | ||
using Moq; | ||
using System.Linq.Expressions; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Utils; | ||
|
||
namespace Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests.CommandHandlers.SupportProject.Notes; | ||
|
||
public class CreateSupportProjectNoteCommandHandlerTests | ||
{ | ||
private readonly Mock<ISupportProjectRepository> _mockSupportProjectRepository; | ||
private readonly Domain.Entities.SupportProject.SupportProject _mockSupportProject; | ||
private readonly CancellationToken _cancellationToken; | ||
private readonly Mock<IDateTimeProvider> _iDateTimeProvider; | ||
|
||
public CreateSupportProjectNoteCommandHandlerTests() | ||
{ | ||
_mockSupportProjectRepository = new Mock<ISupportProjectRepository>(); | ||
var fixture = new Fixture(); | ||
_mockSupportProject = fixture.Create<Domain.Entities.SupportProject.SupportProject>(); | ||
_cancellationToken = new CancellationToken(); | ||
_cancellationToken = CancellationToken.None; | ||
_iDateTimeProvider = new Mock<IDateTimeProvider>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_ValidCommand_CreateNote() | ||
{ | ||
|
||
var command = new CreateSupportProjectNote.CreateSupportProjectNoteCommand( | ||
_mockSupportProject.Id, | ||
"Note", | ||
"[email protected]" | ||
|
||
); | ||
|
||
_mockSupportProjectRepository.Setup(repo => repo.FindAsync(It.IsAny<Expression<Func<Domain.Entities.SupportProject.SupportProject, bool>>>(), It.IsAny<CancellationToken>())).ReturnsAsync(_mockSupportProject); | ||
var CreateNoteCommandHandler = | ||
new CreateSupportProjectNote.CreateSupportProjectNoteCommandHandler(_mockSupportProjectRepository.Object,_iDateTimeProvider.Object); | ||
|
||
var result = await CreateNoteCommandHandler.Handle(command, _cancellationToken); | ||
Assert.IsType<SupportProjectNoteId>(result); | ||
|
||
Assert.IsType<Guid>(result.Value); | ||
|
||
_mockSupportProjectRepository.Verify(repo => repo.UpdateAsync(It.IsAny<Domain.Entities.SupportProject.SupportProject>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_EmptyCommand_CreateNote() | ||
{ | ||
var command = new CreateSupportProjectNote.CreateSupportProjectNoteCommand( | ||
null, | ||
null, | ||
null | ||
); | ||
|
||
_mockSupportProjectRepository.Setup(repo => repo.FindAsync(It.IsAny<Expression<Func<Domain.Entities.SupportProject.SupportProject, bool>>>(), It.IsAny<CancellationToken>())).ReturnsAsync(_mockSupportProject); | ||
var createNoteCommandHandler = | ||
new CreateSupportProjectNote.CreateSupportProjectNoteCommandHandler(_mockSupportProjectRepository.Object,_iDateTimeProvider.Object); | ||
|
||
var result = await createNoteCommandHandler.Handle(command, _cancellationToken); | ||
Assert.IsType<SupportProjectNoteId>(result); | ||
|
||
Assert.IsType<Guid>(result.Value); | ||
|
||
_mockSupportProjectRepository.Verify(repo => repo.UpdateAsync(It.IsAny<Domain.Entities.SupportProject.SupportProject>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...n.Tests/CommandHandlers/SupportProject/Notes/EditSupportProjectNoteCommandHandlerTests.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,81 @@ | ||
using AutoFixture; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.CreateSupportProjectNote; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.UpdateSupportProject; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Interfaces.Repositories; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Domain.ValueObjects; | ||
using Moq; | ||
using System.Linq.Expressions; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.EditSupportProjectNote; | ||
using Dfe.RegionalImprovementForStandardsAndExcellence.Utils; | ||
|
||
namespace Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests.CommandHandlers.SupportProject.Notes; | ||
|
||
public class EditSupportProjectNoteCommandHandlerTests | ||
{ | ||
private readonly Mock<ISupportProjectRepository> _mockSupportProjectRepository; | ||
private readonly Domain.Entities.SupportProject.SupportProject _mockSupportProject; | ||
private readonly Domain.Entities.SupportProject.SupportProjectNote _mockSupportProjectNote; | ||
private readonly CancellationToken _cancellationToken; | ||
private readonly Mock<IDateTimeProvider> _iDateTimeProvider; | ||
|
||
public EditSupportProjectNoteCommandHandlerTests() | ||
{ | ||
_mockSupportProjectRepository = new Mock<ISupportProjectRepository>(); | ||
var fixture = new Fixture(); | ||
_mockSupportProject = fixture.Create<Domain.Entities.SupportProject.SupportProject>(); | ||
_mockSupportProjectNote = fixture.Create<Domain.Entities.SupportProject.SupportProjectNote>(); | ||
_cancellationToken = new CancellationToken(); | ||
_cancellationToken = CancellationToken.None; | ||
_iDateTimeProvider = new Mock<IDateTimeProvider>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_ValidCommand_EditNote() | ||
{ | ||
|
||
var command = new EditSupportProjectNote.EditSupportProjectNoteCommand( | ||
_mockSupportProjectNote.SupportProjectId, | ||
"Note",_mockSupportProjectNote.Id,_mockSupportProjectNote.CreatedBy); | ||
|
||
_mockSupportProject.AddNote(_mockSupportProjectNote.Id, | ||
_mockSupportProjectNote.Note, | ||
_mockSupportProjectNote.CreatedBy, | ||
_mockSupportProjectNote.CreatedOn, | ||
_mockSupportProjectNote.SupportProjectId); | ||
|
||
_mockSupportProjectRepository.Setup(repo => repo.GetSupportProjectById(It.IsAny<SupportProjectId>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_mockSupportProject); | ||
|
||
var editSupportProjectNoteCommandHandler = | ||
new EditSupportProjectNote.EditSupportProjectNoteCommandHandler(_mockSupportProjectRepository.Object,_iDateTimeProvider.Object); | ||
|
||
var result = await editSupportProjectNoteCommandHandler.Handle(command, _cancellationToken); | ||
Assert.IsType<SupportProjectNoteId>(result); | ||
|
||
Assert.Equal(result,_mockSupportProjectNote.Id); | ||
|
||
_mockSupportProjectRepository.Verify(repo => repo.UpdateAsync(It.IsAny<Domain.Entities.SupportProject.SupportProject>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_InvalidValidCommand_EditNote() | ||
{ | ||
|
||
var command = new EditSupportProjectNote.EditSupportProjectNoteCommand( | ||
null, | ||
"Note",null,_mockSupportProjectNote.CreatedBy); | ||
|
||
_mockSupportProjectRepository.Setup(repo => repo.GetSupportProjectById(It.IsAny<SupportProjectId>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_mockSupportProject); | ||
|
||
var editSupportProjectNoteCommandHandler = | ||
new EditSupportProjectNote.EditSupportProjectNoteCommandHandler(_mockSupportProjectRepository.Object,_iDateTimeProvider.Object); | ||
|
||
var result = await editSupportProjectNoteCommandHandler.Handle(command, _cancellationToken); | ||
Assert.IsNotType<SupportProjectNoteId>(result); | ||
|
||
_mockSupportProjectRepository.Verify(repo => repo.UpdateAsync(It.IsAny<Domain.Entities.SupportProject.SupportProject>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
|
||
} |