Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contact the school unit tests #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
@@ -0,0 +1,116 @@
using System;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.UpdateSupportProject;
using Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Interfaces.Repositories;
using Dfe.RegionalImprovementForStandardsAndExcellence.Utils;
using Moq;
using static Dfe.RegionalImprovementForStandardsAndExcellence.Application.SupportProject.Commands.UpdateSupportProject.SetContactTheSchoolDetails;


namespace Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests.CommandHandlers.SupportProject.UpdateSupportProject;

public class SetContactTheSchoolDetailsTests
{
private readonly Mock<ISupportProjectRepository> _mockSupportProjectRepository;
private readonly Domain.Entities.SupportProject.SupportProject _mockSupportProject;
private readonly CancellationToken _cancellationToken;

public SetContactTheSchoolDetailsTests()
{

_mockSupportProjectRepository = new Mock<ISupportProjectRepository>();
var fixture = new Fixture();
_mockSupportProject = fixture.Create<Domain.Entities.SupportProject.SupportProject>();
_cancellationToken = new CancellationToken();
_cancellationToken = CancellationToken.None;
}

[Fact]
public async Task Handle_ValidCommand_UpdatesSupportProject()
{
// Arrange
bool? schoolEmailAddressFound = true;
bool? useTheNotificationLetterToCreateEmail = true;
bool? attachRiseInfoToEmail = true;
DateTime? schoolContactedDate = DateTime.UtcNow;

var command = new SetContactTheSchoolDetailsCommand(
_mockSupportProject.Id,
schoolEmailAddressFound,
useTheNotificationLetterToCreateEmail,
attachRiseInfoToEmail,
schoolContactedDate
);
_mockSupportProjectRepository.Setup(repo => repo.FindAsync(It.IsAny<Expression<Func<Domain.Entities.SupportProject.SupportProject, bool>>>(), It.IsAny<CancellationToken>())).ReturnsAsync(_mockSupportProject);
var setContactTheSchoolDetailsCommandHandler = new SetContactTheSchoolDetailsCommandHandler(_mockSupportProjectRepository.Object);

// Act
var result = await setContactTheSchoolDetailsCommandHandler.Handle(command, _cancellationToken);

// Verify
Assert.True(result);
_mockSupportProjectRepository.Verify(repo => repo.UpdateAsync(It.IsAny<Domain.Entities.SupportProject.SupportProject>(), It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
public async Task Handle_ValidEmptyCommand_UpdatesSupportProject()
{
// Arrange
bool? schoolEmailAddressFound = true;
bool? useTheNotificationLetterToCreateEmail = true;
bool? attachRiseInfoToEmail = true;
DateTime? schoolContactedDate = DateTime.UtcNow;

var command = new SetContactTheSchoolDetailsCommand(
_mockSupportProject.Id,
null,
null,
null,
null
);
_mockSupportProjectRepository.Setup(repo => repo.FindAsync(It.IsAny<Expression<Func<Domain.Entities.SupportProject.SupportProject, bool>>>(), It.IsAny<CancellationToken>())).ReturnsAsync(_mockSupportProject);
var setContactTheSchoolDetailsCommandHandler = new SetContactTheSchoolDetailsCommandHandler(_mockSupportProjectRepository.Object);

// Act
var result = await setContactTheSchoolDetailsCommandHandler.Handle(command, _cancellationToken);

// Verify
Assert.True(result);
_mockSupportProjectRepository.Verify(repo => repo.UpdateAsync(It.IsAny<Domain.Entities.SupportProject.SupportProject>(), It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
public async Task Handle_ProjectNotFound_ReturnsFalse()
{
// Arrange
// Arrange

bool? schoolEmailAddressFound = true;
bool? useTheNotificationLetterToCreateEmail = true;
bool? attachRiseInfoToEmail = true;
DateTime? schoolContactedDate = DateTime.UtcNow;

var command = new SetContactTheSchoolDetailsCommand(
_mockSupportProject.Id,
schoolEmailAddressFound,
useTheNotificationLetterToCreateEmail,
attachRiseInfoToEmail,
schoolContactedDate
);

_mockSupportProjectRepository.Setup(repo => repo.FindAsync(It.IsAny<Expression<Func<Domain.Entities.SupportProject.SupportProject, bool>>>(), It.IsAny<CancellationToken>())).ReturnsAsync((Domain.Entities.SupportProject.SupportProject)null);
var setAdviserConflictOfInterestDetailsCommandHandler = new SetContactTheSchoolDetailsCommandHandler(_mockSupportProjectRepository.Object);

// Act
var result = await setAdviserConflictOfInterestDetailsCommandHandler.Handle(command, _cancellationToken);

// Verify
Assert.False(result);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,31 @@ private static Domain.Entities.SupportProject.SupportProject CreateSupportProjec
localAuthority,
region);
}

[Fact]
public void SetContactTheSchool_WithValidDetails_SetsTheCorrectProperties()
{
// Arrange
var supportProject = CreateSupportProject();

bool? schoolEmailAddressFound = true;
bool? useTheNotificationLetterToCreateEmail = true;
bool? attachRiseInfoToEmail = true;
DateTime? schoolContactedDate = DateTime.UtcNow;

// Act
supportProject.SetContactTheSchoolDetails(
schoolEmailAddressFound,
useTheNotificationLetterToCreateEmail,
attachRiseInfoToEmail,
schoolContactedDate);

// Assert
supportProject.FindSchoolEmailAddress.Should().Be(schoolEmailAddressFound);
supportProject.UseTheNotificationLetterToCreateEmail.Should().Be(useTheNotificationLetterToCreateEmail);
supportProject.AttachRiseInfoToEmail.Should().Be(attachRiseInfoToEmail);
supportProject.ContactedTheSchoolDate.Should().Be(schoolContactedDate);
this.mockRepository.VerifyAll();
}
}
}
Loading