Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fc4d297
Voeg nieuwe projecten toe voor Core, Application, Infrastructure en A…
Wael-Orraby Jun 22, 2025
4da1ed9
Verwijder de EPDDbContext-klasse en bijbehorende configuratie voor de…
Wael-Orraby Jun 22, 2025
3716dbf
Herstructureer de hoofdprogramma-logica door gebruik te maken van Dep…
Wael-Orraby Jun 22, 2025
325e79f
Voeg de AddAppointmentCommand en bijbehorende validator toe voor het …
Wael-Orraby Jun 22, 2025
b313f78
Voeg AppointmentDto toe voor het beheren van afspraakgegevens, inclus…
Wael-Orraby Jun 22, 2025
ea937c3
Voeg query's toe voor het ophalen van afspraken op basis van patiënt-…
Wael-Orraby Jun 22, 2025
0dd22da
Voeg validatiegedrag en bijbehorende uitzondering toe voor het verwer…
Wael-Orraby Jun 22, 2025
b084648
Voeg AddPatientCommand en bijbehorende validator toe voor het beheren…
Wael-Orraby Jun 22, 2025
ddda141
Voeg DeletePatientCommand en DeletePhysicianCommand toe met bijbehore…
Wael-Orraby Jun 22, 2025
4897787
Voeg GetPatientsListQuery en AddPhysicianCommand toe met bijbehorende…
Wael-Orraby Jun 22, 2025
c6919a8
Voeg GetPhysiciansListQuery en bijbehorende handler toe voor het opha…
Wael-Orraby Jun 22, 2025
10cebec
Voeg de entiteiten Appointment, Patient en Physician toe voor het beh…
Wael-Orraby Jun 22, 2025
b78c430
Voeg IApplicationDbContext interface en EPDDbContext klasse toe voor …
Wael-Orraby Jun 22, 2025
6c76a76
Voeg unit tests toe voor het toevoegen, ophalen en verwijderen van pa…
Wael-Orraby Jun 22, 2025
b5274de
Herstructureer entiteiten Appointment, Patient en Physician door de n…
Wael-Orraby Jun 22, 2025
69ef4d4
Verbeter de structuur van de EPDDbContext klasse door de namespace en…
Wael-Orraby Jun 22, 2025
df046b5
Herstructureer de Program.cs door de afhankelijkheden te scheiden in …
Wael-Orraby Jun 22, 2025
b658c20
Verbeter validatieregels in AddPatientCommandValidator en voeg nieuwe…
Wael-Orraby Jun 22, 2025
ec5f81f
Voeg validatieregels toe voor PatientId en PhysicianId in AddAppointm…
Wael-Orraby Jun 22, 2025
bf802b1
Voeg extra validatieregels en bijbehorende unit tests toe voor de Add…
Wael-Orraby Jun 22, 2025
cb7d958
Herstructureer en vereenvoudig de testklassen voor de command handler…
Wael-Orraby Jun 22, 2025
04f72ab
Herstructureer en vereenvoudig de command handlers en validators voor…
Wael-Orraby Jun 22, 2025
6c9a728
Voeg een nieuw document toe met ontwerpkeuzes voor EPDConsole, inclus…
Wael-Orraby Jun 22, 2025
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,41 @@
using Chipsoft.Assignments.EPDConsole.Application.Appointments.Commands;
using Chipsoft.Assignments.EPDConsole.Core.Entities;
using Chipsoft.Assignments.EPDConsole.Core.Interfaces;
using Moq;
using Moq.EntityFrameworkCore;


namespace Chipsoft.Assignments.EPDConsole.Application.Tests.Appointments.Commands;

public class AddAppointmentCommandHandlerTests
{
private readonly Mock<IApplicationDbContext> _contextMock;
private readonly AddAppointmentCommandHandler _handler;

public AddAppointmentCommandHandlerTests()
{
_contextMock = new Mock<IApplicationDbContext>();
_handler = new AddAppointmentCommandHandler(_contextMock.Object);
}

[Fact]
public async Task Handle_Should_Add_Appointment_And_Save_Changes()
{
// Arrange
_contextMock.Setup(c => c.Appointments).ReturnsDbSet(new List<Appointment>());

var command = new AddAppointmentCommand
{
PatientId = 1,
PhysicianId = 1,
AppointmentDateTime = DateTime.Now.AddHours(1)
};

// Act
await _handler.Handle(command, CancellationToken.None);

// Assert
_contextMock.Verify(x => x.Appointments.Add(It.IsAny<Appointment>()), Times.Once);
_contextMock.Verify(x => x.SaveChangesAsync(CancellationToken.None), Times.Once);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Chipsoft.Assignments.EPDConsole.Application.Appointments.Queries;
using Chipsoft.Assignments.EPDConsole.Core.Entities;
using Chipsoft.Assignments.EPDConsole.Core.Interfaces;
using FluentAssertions;
using Moq;
using Moq.EntityFrameworkCore;

namespace Chipsoft.Assignments.EPDConsole.Application.Tests.Appointments.Queries;

public class GetAppointmentsByPatientQueryHandlerTests
{
private readonly Mock<IApplicationDbContext> _contextMock;
private readonly GetAppointmentsByPatientQueryHandler _handler;

public GetAppointmentsByPatientQueryHandlerTests()
{
_contextMock = new Mock<IApplicationDbContext>();
_handler = new GetAppointmentsByPatientQueryHandler(_contextMock.Object);
}

[Fact]
public async Task Handle_Should_Return_Only_Appointments_For_Given_Patient()
{
// Arrange
var patient1 = new Patient { Id = 1, FirstName = "John", LastName = "Doe" };
var patient2 = new Patient { Id = 2, FirstName = "Jane", LastName = "Doe" };
var physician = new Physician { Id = 1, FirstName = "Dr.", LastName = "Smith" };

var appointments = new List<Appointment>
{
new Appointment { PatientId = 1, PhysicianId = 1, Patient = patient1, Physician = physician, AppointmentDateTime = DateTime.Now.AddDays(1) },
new Appointment { PatientId = 2, PhysicianId = 1, Patient = patient2, Physician = physician, AppointmentDateTime = DateTime.Now.AddDays(2) },
new Appointment { PatientId = 1, PhysicianId = 1, Patient = patient1, Physician = physician, AppointmentDateTime = DateTime.Now.AddDays(3) }
};

_contextMock.Setup(c => c.Appointments).ReturnsDbSet(appointments);

var query = new GetAppointmentsByPatientQuery { PatientId = 1 };

// Act
var result = await _handler.Handle(query, CancellationToken.None);

// Assert
result.Should().NotBeNull();
result.Should().HaveCount(2);
result.All(a => a.PatientName == "John Doe").Should().BeTrue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Chipsoft.Assignments.EPDConsole.Application.Appointments.Queries;
using Chipsoft.Assignments.EPDConsole.Core.Entities;
using Chipsoft.Assignments.EPDConsole.Core.Interfaces;
using FluentAssertions;
using Moq;
using Moq.EntityFrameworkCore;

namespace Chipsoft.Assignments.EPDConsole.Application.Tests.Appointments.Queries;

public class GetAppointmentsByPhysicianQueryHandlerTests
{
private readonly Mock<IApplicationDbContext> _contextMock;
private readonly GetAppointmentsByPhysicianQueryHandler _handler;

public GetAppointmentsByPhysicianQueryHandlerTests()
{
_contextMock = new Mock<IApplicationDbContext>();
_handler = new GetAppointmentsByPhysicianQueryHandler(_contextMock.Object);
}

[Fact]
public async Task Handle_Should_Return_Only_Appointments_For_Given_Physician()
{
// Arrange
var patient = new Patient { Id = 1, FirstName = "John", LastName = "Doe" };
var physician1 = new Physician { Id = 1, FirstName = "Dr.", LastName = "Smith" };
var physician2 = new Physician { Id = 2, FirstName = "Dr.", LastName = "Who" };


var appointments = new List<Appointment>
{
new Appointment { PatientId = 1, PhysicianId = 1, Patient = patient, Physician = physician1, AppointmentDateTime = DateTime.Now.AddDays(1) },
new Appointment { PatientId = 1, PhysicianId = 2, Patient = patient, Physician = physician2, AppointmentDateTime = DateTime.Now.AddDays(2) },
new Appointment { PatientId = 1, PhysicianId = 1, Patient = patient, Physician = physician1, AppointmentDateTime = DateTime.Now.AddDays(3) }
};

_contextMock.Setup(c => c.Appointments).ReturnsDbSet(appointments);

var query = new GetAppointmentsByPhysicianQuery { PhysicianId = 1 };

// Act
var result = await _handler.Handle(query, CancellationToken.None);

// Assert
result.Should().NotBeNull();
result.Should().HaveCount(2);
result.All(a => a.PhysicianName == "Dr. Smith").Should().BeTrue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Chipsoft.Assignments.EPDConsole.Application.Appointments.Queries;
using Chipsoft.Assignments.EPDConsole.Core.Entities;
using Chipsoft.Assignments.EPDConsole.Core.Interfaces;
using FluentAssertions;
using Moq;
using Moq.EntityFrameworkCore;


namespace Chipsoft.Assignments.EPDConsole.Application.Tests.Appointments.Queries;

public class GetAppointmentsListQueryHandlerTests
{
private readonly Mock<IApplicationDbContext> _contextMock;
private readonly GetAppointmentsListQueryHandler _handler;

public GetAppointmentsListQueryHandlerTests()
{
_contextMock = new Mock<IApplicationDbContext>();
_handler = new GetAppointmentsListQueryHandler(_contextMock.Object);
}

[Fact]
public async Task Handle_Should_Return_All_Appointments_As_Dtos()
{
// Arrange
var patients = new List<Patient> { new Patient { Id = 1, FirstName = "John", LastName = "Doe" } };
var physicians = new List<Physician> { new Physician { Id = 1, FirstName = "Jane", LastName = "Smith" } };
var appointments = new List<Appointment>
{
new Appointment { Id = 1, PatientId = 1, PhysicianId = 1, AppointmentDateTime = DateTime.Now.AddDays(1), Patient = patients[0], Physician = physicians[0] }
};

_contextMock.Setup(c => c.Appointments).ReturnsDbSet(appointments);

var query = new GetAppointmentsListQuery();

// Act
var result = await _handler.Handle(query, CancellationToken.None);

// Assert
result.Should().NotBeNull();
result.Should().HaveCount(1);
result[0].PatientName.Should().Be("John Doe");
result[0].PhysicianName.Should().Be("Jane Smith");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Chipsoft.Assignments.EPDConsole.Application.Appointments.Commands;
using Chipsoft.Assignments.EPDConsole.Core.Entities;
using Chipsoft.Assignments.EPDConsole.Core.Interfaces;
using FluentValidation.TestHelper;
using Moq;
using Moq.EntityFrameworkCore;
using FluentAssertions;

namespace Chipsoft.Assignments.EPDConsole.Application.Tests.Appointments.Validators;

public class AddAppointmentCommandValidatorTests
{
private readonly Mock<IApplicationDbContext> _contextMock;

public AddAppointmentCommandValidatorTests()
{
_contextMock = new Mock<IApplicationDbContext>();
}

[Fact]
public async Task Should_Not_Have_Error_When_Appointment_Is_Valid()
{
// Arrange
_contextMock.Setup(x => x.Patients).ReturnsDbSet(new List<Patient> { new Patient { Id = 1 } });
_contextMock.Setup(x => x.Physicians).ReturnsDbSet(new List<Physician> { new Physician { Id = 1 } });
_contextMock.Setup(x => x.Appointments).ReturnsDbSet(new List<Appointment>());

var validator = new AddAppointmentCommandValidator(_contextMock.Object);
var command = new AddAppointmentCommand { PatientId = 1, PhysicianId = 1, AppointmentDateTime = DateTime.Now.AddDays(1) };

// Act
var result = await validator.TestValidateAsync(command);

// Assert
result.ShouldNotHaveAnyValidationErrors();
}

[Fact]
public async Task Should_Have_Error_When_Physician_Has_Conflict()
{
// Arrange
var appointmentTime = DateTime.Now.AddDays(1);
var existingAppointments = new List<Appointment>
{
new Appointment { PhysicianId = 1, AppointmentDateTime = appointmentTime }
};

_contextMock.Setup(x => x.Patients).ReturnsDbSet(new List<Patient> { new Patient { Id = 1 } });
_contextMock.Setup(x => x.Physicians).ReturnsDbSet(new List<Physician> { new Physician { Id = 1 } });
_contextMock.Setup(x => x.Appointments).ReturnsDbSet(existingAppointments);

var validator = new AddAppointmentCommandValidator(_contextMock.Object);
var command = new AddAppointmentCommand { PatientId = 1, PhysicianId = 1, AppointmentDateTime = appointmentTime };

// Act
var result = await validator.TestValidateAsync(command);

// Assert
result.Errors.Should().Contain(e => e.ErrorMessage == "De arts of patiënt heeft op dit tijdstip al een andere afspraak.");
}

[Fact]
public async Task Should_Have_Error_When_Patient_Has_Conflict()
{
// Arrange
var appointmentTime = DateTime.Now.AddDays(1);
var existingAppointments = new List<Appointment>
{
new Appointment { PatientId = 1, AppointmentDateTime = appointmentTime }
};

_contextMock.Setup(x => x.Patients).ReturnsDbSet(new List<Patient> { new Patient { Id = 1 } });
_contextMock.Setup(x => x.Physicians).ReturnsDbSet(new List<Physician> { new Physician { Id = 1 } });
_contextMock.Setup(x => x.Appointments).ReturnsDbSet(existingAppointments);

var validator = new AddAppointmentCommandValidator(_contextMock.Object);
var command = new AddAppointmentCommand { PatientId = 1, PhysicianId = 1, AppointmentDateTime = appointmentTime };

// Act
var result = await validator.TestValidateAsync(command);

// Assert
result.Errors.Should().Contain(e => e.ErrorMessage == "De arts of patiënt heeft op dit tijdstip al een andere afspraak.");
}

[Fact]
public async Task Should_Have_Error_When_Date_Is_In_The_Past()
{
// Arrange
_contextMock.Setup(x => x.Patients).ReturnsDbSet(new List<Patient> { new Patient { Id = 1 } });
_contextMock.Setup(x => x.Physicians).ReturnsDbSet(new List<Physician> { new Physician { Id = 1 } });
_contextMock.Setup(x => x.Appointments).ReturnsDbSet(new List<Appointment>());
var validator = new AddAppointmentCommandValidator(_contextMock.Object);
var command = new AddAppointmentCommand { PatientId = 1, PhysicianId = 1, AppointmentDateTime = DateTime.Now.AddDays(-1) };

// Act
var result = await validator.TestValidateAsync(command);

// Assert
result.ShouldHaveValidationErrorFor(cmd => cmd.AppointmentDateTime);
}

[Fact]
public async Task Should_Have_Error_When_PatientId_Does_Not_Exist()
{
// Arrange
_contextMock.Setup(x => x.Patients).ReturnsDbSet(new List<Patient>());
_contextMock.Setup(x => x.Physicians).ReturnsDbSet(new List<Physician> { new Physician { Id = 1 } });
_contextMock.Setup(x => x.Appointments).ReturnsDbSet(new List<Appointment>());
var validator = new AddAppointmentCommandValidator(_contextMock.Object);
var command = new AddAppointmentCommand { PatientId = 99, PhysicianId = 1, AppointmentDateTime = DateTime.Now.AddDays(1) };

// Act
var result = await validator.TestValidateAsync(command);

// Assert
result.ShouldHaveValidationErrorFor(cmd => cmd.PatientId)
.WithErrorMessage("De geselecteerde patiënt bestaat niet.");
}

[Fact]
public async Task Should_Have_Error_When_PhysicianId_Does_Not_Exist()
{
// Arrange
_contextMock.Setup(x => x.Patients).ReturnsDbSet(new List<Patient> { new Patient { Id = 1 } });
_contextMock.Setup(x => x.Physicians).ReturnsDbSet(new List<Physician>());
_contextMock.Setup(x => x.Appointments).ReturnsDbSet(new List<Appointment>());
var validator = new AddAppointmentCommandValidator(_contextMock.Object);
var command = new AddAppointmentCommand { PatientId = 1, PhysicianId = 99, AppointmentDateTime = DateTime.Now.AddDays(1) };

// Act
var result = await validator.TestValidateAsync(command);

// Assert
result.ShouldHaveValidationErrorFor(cmd => cmd.PhysicianId)
.WithErrorMessage("De geselecteerde arts bestaat niet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="8.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Moq.EntityFrameworkCore" Version="9.0.0.5" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Chipsoft.Assignments.EPDConsole.Application\Chipsoft.Assignments.EPDConsole.Application.csproj" />
</ItemGroup>

</Project>
Loading