Skip to content

Commit

Permalink
Remove add note data command
Browse files Browse the repository at this point in the history
  • Loading branch information
paullocknimble committed May 2, 2024
1 parent 3798f06 commit 936f886
Show file tree
Hide file tree
Showing 31 changed files with 74 additions and 233 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Linq;
using System.Threading.Tasks;
using AutoFixture;
using AutoMapper;
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.Data.Repositories;
using Dfe.Academies.Academisation.Data.UnitTest.Contexts;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.ProjectAggregate;
using Moq;
using Xunit;

namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate
Expand All @@ -13,13 +16,14 @@ public class IncompleteProjectsGetDataQueryTests
{
private readonly Fixture _fixture = new();

private readonly IncompleteProjectsGetDataQuery _subject;
private readonly ConversionProjectRepository _subject;
private readonly AcademisationContext _context;
private Mock<IMapper> _mockMapper = new Mock<IMapper>();

public IncompleteProjectsGetDataQueryTests()
{
_context = new TestProjectContext().CreateContext();
_subject = new IncompleteProjectsGetDataQuery(_context);
_subject = new ConversionProjectRepository(_context, _mockMapper.Object);
}

[Fact]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ private static IQueryable<Project> FilterFormAMAT(IQueryable<Project> queryable)
return queryable;
}

public async Task<IEnumerable<IProject>?> GetIncompleteProjects()
{
var createdProjectState = await _context.Projects
.Where(p => string.IsNullOrEmpty(p.Details.LocalAuthority) || string.IsNullOrEmpty(p.Details.Region) || string.IsNullOrEmpty(p.Details.SchoolPhase) || string.IsNullOrEmpty(p.Details.SchoolType))
.ToListAsync();

return createdProjectState;
}

private static IQueryable<Project> FilterByRegion(IEnumerable<string>? regions, IQueryable<Project> queryable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface IConversionProjectRepository : IRepository<Project>, IGenericRe
Task<IEnumerable<IProject>> GetConversionProjectsByFormAMatIds(IEnumerable<int?> ids, CancellationToken cancellationToken);
Task<(IEnumerable<IProject> projects, int totalCount)> SearchFormAMatProjects(
IEnumerable<string>? states, string? title, IEnumerable<string>? deliveryOfficers, IEnumerable<string>? regions, IEnumerable<string>? localAuthorities, IEnumerable<string>? advisoryBoardDates);

Task<IEnumerable<IProject>?> GetIncompleteProjects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,9 @@ public void SetDeletedAt()
{
DeletedAt = DateTime.UtcNow;
}

public void AddNote(string subject, string note, string author, DateTime date)
{
_notes.Add(new ProjectNote(subject, note, author, date, Id));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ public void SetSchoolOverview(
public void SetPerformanceData(string? keyStage2PerformanceAdditionalInformation, string? keyStage4PerformanceAdditionalInformation, string? keyStage5PerformanceAdditionalInformation, string? educationalAttendanceAdditionalInformation);
void SetFormAMatProjectId(int id);
void SetRoute(string route);
void AddNote(string subject, string note, string author, DateTime date);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate;
using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate;

namespace Dfe.Academies.Academisation.IService.Commands.Legacy.Project
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject;

namespace Dfe.Academies.Academisation.IService.Commands.Legacy.Project
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dfe.Academies.Academisation.Data.ProjectAggregate
namespace Dfe.Academies.Academisation.IService.ServiceModels
{
public class GetProjectSearchModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dfe.Academies.Academisation.Data.ProjectAggregate
namespace Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate
{
public class ConversionProjectSearchModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dfe.Academies.Academisation.Data.ProjectAggregate
namespace Dfe.Academies.Academisation.IService.ServiceModels.TransferProject
{
public class TransferProjectSearchModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutoFixture;
using Dfe.Academies.Academisation.Domain.ApplicationAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using Dfe.Academies.Academisation.IService.Query;
Expand All @@ -13,7 +14,7 @@ namespace Dfe.Academies.Academisation.Service.UnitTest.Commands.Legacy.Project
public class EnrichProjectCommandTests
{
private readonly EnrichProjectCommand _subject;
private readonly Mock<IIncompleteProjectsGetDataQuery> _incompleteProjectGetDataQuery;
private readonly Mock<IConversionProjectRepository> _conversionProjectRepository;
private readonly Mock<IAcademiesQueryService> _establishmentGetDataQuery;
private readonly Mock<IProjectUpdateDataCommand> _updateCommand;
private readonly Mock<ILogger<EnrichProjectCommand>> _logger;
Expand All @@ -22,14 +23,14 @@ public class EnrichProjectCommandTests

public EnrichProjectCommandTests()
{
_incompleteProjectGetDataQuery = new Mock<IIncompleteProjectsGetDataQuery>();
_conversionProjectRepository = new Mock<IConversionProjectRepository>();
_establishmentGetDataQuery = new Mock<IAcademiesQueryService>();
_updateCommand = new Mock<IProjectUpdateDataCommand>();
_logger = new Mock<ILogger<EnrichProjectCommand>>();

_subject = new EnrichProjectCommand(
_logger.Object,
_incompleteProjectGetDataQuery.Object,
_conversionProjectRepository.Object,
_establishmentGetDataQuery.Object,
_updateCommand.Object);
}
Expand All @@ -50,7 +51,7 @@ public async Task NoIncompleteProjects__LogAndReturn()
public async Task IncompleteProjects__UnknownSchool__LogAndContinue()
{
var projects = _fixture.CreateMany<Domain.ProjectAggregate.Project>();
_incompleteProjectGetDataQuery.Setup(m => m.GetIncompleteProjects())
_conversionProjectRepository.Setup(m => m.GetIncompleteProjects())
.ReturnsAsync(projects);

_establishmentGetDataQuery.SetupSequence(m => m.GetEstablishment(It.IsAny<int>()))
Expand All @@ -71,7 +72,7 @@ public async Task IncompleteProjects__UnknownSchool__LogAndContinue()
public async Task IncompleteProjects__KnownSchool__UpdateDb()
{
var project = _fixture.Create<Domain.ProjectAggregate.Project>();
_incompleteProjectGetDataQuery.Setup(m => m.GetIncompleteProjects())
_conversionProjectRepository.Setup(m => m.GetIncompleteProjects())
.ReturnsAsync(new List<IProject> { project });

_establishmentGetDataQuery.Setup(m => m.GetEstablishment(It.IsAny<int>()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using AutoFixture;
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Domain.ApplicationAggregate;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.SeedWork;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using Dfe.Academies.Academisation.Service.Commands.ConversionProject;
using Dfe.Academies.Academisation.Service.Commands.Legacy.Project;
using FluentAssertions;
using Moq;
using Xunit;
Expand All @@ -15,25 +13,24 @@ namespace Dfe.Academies.Academisation.Service.UnitTest.Commands.Legacy.Project
public class LegacyProjectAddNoteCommandTests
{
private readonly Fixture _fixture;
private readonly Mock<IConversionProjectRepository> _projectGetDataQuery;
private readonly Mock<IProjectNoteAddCommand> _projectNoteAddCommand;
private readonly Mock<IConversionProjectRepository> _repo;

public LegacyProjectAddNoteCommandTests()
{
_fixture = new Fixture();
_projectGetDataQuery = new Mock<IConversionProjectRepository>();
_projectNoteAddCommand = new Mock<IProjectNoteAddCommand>();
_repo = new Mock<IConversionProjectRepository>();
_repo.Setup(x => x.UnitOfWork).Returns(Mock.Of<IUnitOfWork>());
}

private ConversionProjectAddNoteCommandHandler System_under_test()
{
return new ConversionProjectAddNoteCommandHandler(_projectGetDataQuery.Object, _projectNoteAddCommand.Object);
return new ConversionProjectAddNoteCommandHandler(_repo.Object);
}

[Fact]
public async Task Should_return_not_found_command_result_if_the_project_is_unknown()
{
_projectGetDataQuery
_repo
.Setup(x => x.GetConversionProject(It.IsAny<int>()))
.ReturnsAsync((IProject?)null);

Expand All @@ -49,22 +46,16 @@ public async Task Should_pass_on_the_result_from_the_data_layer_command_if_the_p
{
IProject project = _fixture.Create<Domain.ProjectAggregate.Project>();

_projectGetDataQuery
.Setup(x => x.GetConversionProject(It.IsAny<int>()))
_repo.Setup(x => x.GetConversionProject(It.IsAny<int>()))
.ReturnsAsync(project);

var addCommandResult = new CommandSuccessResult();
_projectNoteAddCommand
.Setup(x => x.Execute(It.IsAny<int>(), It.IsAny<ProjectNote>()))
.ReturnsAsync(addCommandResult);

var command = System_under_test();

CommandResult result = await command.Handle(
_fixture.Create<ConversionProjectAddNoteCommand>() with { ProjectId = project.Id }, default
);

result.Should().Be(addCommandResult);
result.Should().BeOfType(typeof(CommandSuccessResult));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.IService.Query;
using Dfe.Academies.Academisation.IService.Query;
using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject;
using Dfe.Academies.Academisation.Service.Queries;
using Moq;
Expand Down
Loading

0 comments on commit 936f886

Please sign in to comment.