Skip to content

Commit

Permalink
Remove delete note data command
Browse files Browse the repository at this point in the history
  • Loading branch information
paullocknimble committed May 2, 2024
1 parent 936f886 commit 8146091
Show file tree
Hide file tree
Showing 30 changed files with 203 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<ItemGroup>
<ProjectReference Include="..\Dfe.Academies.Academisation.Data\Dfe.Academies.Academisation.Data.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.Domain\Dfe.Academies.Academisation.Domain.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.IData\Dfe.Academies.Academisation.IData.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Net.Http;
using Dfe.Academies.Academisation.Data.Http;
using Dfe.Academies.Academisation.IData.Http;
using Dfe.Academisation.CorrelationIdMiddleware;
using FluentAssertions;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoFixture;
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.Data.UnitTest.Contexts;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using FluentAssertions;
using Xunit;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
//using AutoFixture;
//using Dfe.Academies.Academisation.Core;
//using Dfe.Academies.Academisation.Data.ProjectAggregate;
//using Dfe.Academies.Academisation.Data.UnitTest.Contexts;
//using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
//using Dfe.Academies.Academisation.Domain.ProjectAggregate;
//using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
//using FluentAssertions;
//using Xunit;

namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate
{
public class ProjectNoteDeleteCommandTests
{
private readonly AcademisationContext _context;
private readonly Fixture _fixture;
private readonly IList<ProjectNote> _notes;
//namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate
//{
// public class ProjectNoteDeleteCommandTests
// {
// private readonly AcademisationContext _context;
// private readonly Fixture _fixture;
// private readonly IList<ProjectNote> _notes;

public ProjectNoteDeleteCommandTests()
{
var testProjectContext = new TestProjectContext();
_context = testProjectContext.CreateContext();
// public ProjectNoteDeleteCommandTests()
// {
// var testProjectContext = new TestProjectContext();
// _context = testProjectContext.CreateContext();

_fixture = new Fixture();
// _fixture = new Fixture();

IList<Project> projects = _fixture.CreateMany<Project>(3).ToList();
// IList<Project> projects = _fixture.CreateMany<Project>(3).ToList();

_notes = _fixture.CreateMany<ProjectNote>().ToList();
// _notes = _fixture.CreateMany<ProjectNote>().ToList();

_notes = _notes.Select(x => new ProjectNote(x.Subject, x.Note, x.Author, x.Date, projects[Random.Shared.Next(projects.Count)].Id))
.ToList();
// _notes = _notes.Select(x => new ProjectNote(x.Subject, x.Note, x.Author, x.Date, projects[Random.Shared.Next(projects.Count)].Id))
// .ToList();

_context.Projects.AddRangeAsync(projects);
_context.ProjectNotes.AddRangeAsync(_notes);
_context.SaveChanges();
}
// _context.Projects.AddRangeAsync(projects);
// _context.ProjectNotes.AddRangeAsync(_notes);
// _context.SaveChanges();
// }

private ProjectNote RandomNote => _notes[Random.Shared.Next(_notes.Count)];
// private ProjectNote RandomNote => _notes[Random.Shared.Next(_notes.Count)];

private ProjectNoteDeleteCommand System_under_test()
{
return new ProjectNoteDeleteCommand(_context);
}
// private ProjectNoteDeleteCommand System_under_test()
// {
// return new ProjectNoteDeleteCommand(_context);
// }

[Fact]
public async Task Should_return_not_found_result_if_the_note_does_not_exist()
{
ProjectNote noteToDelete = _fixture.Create<ProjectNote>();
// [Fact]
// public async Task Should_return_not_found_result_if_the_note_does_not_exist()
// {
// ProjectNote noteToDelete = _fixture.Create<ProjectNote>();

ProjectNoteDeleteCommand command = System_under_test();
// ProjectNoteDeleteCommand command = System_under_test();

_context.ProjectNotes.Should().NotContain(noteToDelete);
// _context.ProjectNotes.Should().NotContain(noteToDelete);

CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete);
// CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete);

result.Should().BeOfType<NotFoundCommandResult>();
}
// result.Should().BeOfType<NotFoundCommandResult>();
// }

[Fact]
public async Task Should_remove_the_note()
{
ProjectNote noteToDelete = RandomNote;
// [Fact]
// public async Task Should_remove_the_note()
// {
// ProjectNote noteToDelete = RandomNote;

ProjectNoteDeleteCommand command = System_under_test();
// ProjectNoteDeleteCommand command = System_under_test();

_context.ProjectNotes.Should().Contain(noteToDelete);
// _context.ProjectNotes.Should().Contain(noteToDelete);

CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete);
// CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete);

result.Should().BeOfType<CommandSuccessResult>();
// result.Should().BeOfType<CommandSuccessResult>();

_context.ProjectNotes.Should().NotContain(noteToDelete);
}
}
}
// _context.ProjectNotes.Should().NotContain(noteToDelete);
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<ItemGroup>
<ProjectReference Include="..\Dfe.Academies.Academisation.Domain.Core\Dfe.Academies.Academisation.Domain.Core.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.Domain\Dfe.Academies.Academisation.Domain.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.IData\Dfe.Academies.Academisation.IData.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.IDomain\Dfe.Academies.Academisation.IDomain.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dfe.Academies.Academisation.IData.Http;
using Dfe.Academisation.CorrelationIdMiddleware;
using Dfe.Academisation.CorrelationIdMiddleware;

namespace Dfe.Academies.Academisation.Data.Http
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Dfe.Academisation.CorrelationIdMiddleware;

namespace Dfe.Academies.Academisation.IData.Http
namespace Dfe.Academies.Academisation.Data.Http
{
public interface IAcademiesApiClientFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;

namespace Dfe.Academies.Academisation.Data.ProjectAggregate;

public interface IProjectUpdateDataCommand
{
Task Execute(IProject project);
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Microsoft.EntityFrameworkCore;
//using Dfe.Academies.Academisation.Core;
//using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
//using Dfe.Academies.Academisation.IData.ProjectAggregate;
//using Microsoft.EntityFrameworkCore;

namespace Dfe.Academies.Academisation.Data.ProjectAggregate
{
public class ProjectNoteDeleteCommand : IProjectNoteDeleteCommand
{
private readonly AcademisationContext _context;
//namespace Dfe.Academies.Academisation.Data.ProjectAggregate
//{
// public class ProjectNoteDeleteCommand : IProjectNoteDeleteCommand
// {
// private readonly AcademisationContext _context;

public ProjectNoteDeleteCommand(AcademisationContext context)
{
_context = context;
}
// public ProjectNoteDeleteCommand(AcademisationContext context)
// {
// _context = context;
// }

public async Task<CommandResult> Execute(int projectId, ProjectNote note)
{
ProjectNote? matchedNote =
await _context.ProjectNotes
.FirstOrDefaultAsync(x => x.ProjectId == projectId &&
x.Subject == note.Subject &&
x.Note == note.Note &&
x.Author == note.Author &&
x.Date == note.Date);
// public async Task<CommandResult> Execute(int projectId, ProjectNote note)
// {
// ProjectNote? matchedNote =
// await _context.ProjectNotes
// .FirstOrDefaultAsync(x => x.ProjectId == projectId &&
// x.Subject == note.Subject &&
// x.Note == note.Note &&
// x.Author == note.Author &&
// x.Date == note.Date);

if (matchedNote is null)
{
return new NotFoundCommandResult();
}
// if (matchedNote is null)
// {
// return new NotFoundCommandResult();
// }

_context.ProjectNotes.Remove(matchedNote);
await _context.SaveChangesAsync();
// _context.ProjectNotes.Remove(matchedNote);
// await _context.SaveChangesAsync();

return new CommandSuccessResult();
}
}
}
// return new CommandSuccessResult();
// }
// }
//}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dfe.Academies.Academisation.Domain.ProjectAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using Microsoft.EntityFrameworkCore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Dfe.Academies.Academisation.Domain.SeedWork;
using Dfe.Academies.Academisation.IDomain.ApplicationAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Dfe.Academies.Academisation.Domain.ProjectAggregate;

Expand Down Expand Up @@ -553,4 +554,11 @@ public void AddNote(string subject, string note, string author, DateTime date)
{
_notes.Add(new ProjectNote(subject, note, author, date, Id));
}

public void RemoveNote(int id)
{
var note = _notes.SingleOrDefault(x => x.Id == id);
if (note != null) { _notes.Remove(note); }

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ public void SetSchoolOverview(
void SetFormAMatProjectId(int id);
void SetRoute(string route);
void AddNote(string subject, string note, string author, DateTime date);
void RemoveNote(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<ProjectReference Include="..\Dfe.Academies.Academisation.Core\Dfe.Academies.Academisation.Core.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.Data\Dfe.Academies.Academisation.Data.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.Domain.Core\Dfe.Academies.Academisation.Domain.Core.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.IData\Dfe.Academies.Academisation.IData.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<ItemGroup>
<ProjectReference Include="..\Dfe.Academies.Academisation.Data\Dfe.Academies.Academisation.Data.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.Domain\Dfe.Academies.Academisation.Domain.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.IData\Dfe.Academies.Academisation.IData.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.IDomain\Dfe.Academies.Academisation.IDomain.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.Service\Dfe.Academies.Academisation.Service.csproj" />
<ProjectReference Include="..\Dfe.Academies.Academisation.WebApi\Dfe.Academies.Academisation.WebApi.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
using Dfe.Academies.Academisation.Domain.ApplicationAggregate;
using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate;
using Dfe.Academies.Academisation.Domain.SeedWork;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ApplicationAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.Services;
using Dfe.Academies.Academisation.IService.RequestModels;
using Dfe.Academies.Academisation.Service.Commands.Application;
using Moq;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AutoFixture;
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.ApplicationAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;
using Dfe.Academies.Academisation.IService.Query;
using Dfe.Academies.Academisation.Service.Commands.Legacy.Project;
Expand Down
Loading

0 comments on commit 8146091

Please sign in to comment.