From 41cabcd6e24872c62090bf7f10a274a990a7ed12 Mon Sep 17 00:00:00 2001 From: danielryannimble Date: Fri, 17 Jan 2025 16:11:44 +0000 Subject: [PATCH] contact the school unit tests --- .../SetContactTheSchoolDetailsTests.cs | 116 ++++++++++++++++++ .../SupportProject/SupportProjectTests.cs | 26 ++++ 2 files changed, 142 insertions(+) create mode 100644 src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests/CommandHandlers/SupportProject/UpdateSupportProject/SetContactTheSchoolDetailsTests.cs diff --git a/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests/CommandHandlers/SupportProject/UpdateSupportProject/SetContactTheSchoolDetailsTests.cs b/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests/CommandHandlers/SupportProject/UpdateSupportProject/SetContactTheSchoolDetailsTests.cs new file mode 100644 index 0000000..df86a98 --- /dev/null +++ b/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Application.Tests/CommandHandlers/SupportProject/UpdateSupportProject/SetContactTheSchoolDetailsTests.cs @@ -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 _mockSupportProjectRepository; + private readonly Domain.Entities.SupportProject.SupportProject _mockSupportProject; + private readonly CancellationToken _cancellationToken; + + public SetContactTheSchoolDetailsTests() + { + + _mockSupportProjectRepository = new Mock(); + var fixture = new Fixture(); + _mockSupportProject = fixture.Create(); + _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>>(), It.IsAny())).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(), It.IsAny()), 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>>(), It.IsAny())).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(), It.IsAny()), 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>>(), It.IsAny())).ReturnsAsync((Domain.Entities.SupportProject.SupportProject)null); + var setAdviserConflictOfInterestDetailsCommandHandler = new SetContactTheSchoolDetailsCommandHandler(_mockSupportProjectRepository.Object); + + // Act + var result = await setAdviserConflictOfInterestDetailsCommandHandler.Handle(command, _cancellationToken); + + // Verify + Assert.False(result); + } + + + +} \ No newline at end of file diff --git a/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Tests/Entities/SupportProject/SupportProjectTests.cs b/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Tests/Entities/SupportProject/SupportProjectTests.cs index 0c5b2d6..936e62a 100644 --- a/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Tests/Entities/SupportProject/SupportProjectTests.cs +++ b/src/Tests/Dfe.RegionalImprovementForStandardsAndExcellence.Domain.Tests/Entities/SupportProject/SupportProjectTests.cs @@ -84,5 +84,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(); + } } }