mirror of
https://github.com/farcasclaudiu/PracticeCalendar.git
synced 2026-06-22 07:01:16 +03:00
refactoring and integration tests
This commit is contained in:
@@ -3,5 +3,6 @@
|
||||
public class DomainEventBase
|
||||
{
|
||||
public DateTime EventDate { get; protected set; } = DateTime.UtcNow;
|
||||
public bool IsPublished { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using MediatR;
|
||||
|
||||
namespace PracticeCalendar.Domain.Common
|
||||
{
|
||||
public class DomainEventNotification<TDomainEvent> : INotification where TDomainEvent : DomainEventBase
|
||||
{
|
||||
public TDomainEvent DomainEvent { get; }
|
||||
|
||||
public DomainEventNotification(TDomainEvent domainEvent)
|
||||
{
|
||||
DomainEvent = domainEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PracticeCalendar.Domain.Common.Interfaces
|
||||
{
|
||||
public interface IDomainEventService
|
||||
{
|
||||
Task Publish(DomainEventBase domainEvent);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,9 @@ namespace PracticeCalendar.Domain.Entities
|
||||
{
|
||||
this.Title = title;
|
||||
this.Description = description;
|
||||
|
||||
var titleDescUpdatedEvent = new EventUpdateTitleAndDescriptionEvent(this);
|
||||
base.RegisterDomainEvent(titleDescUpdatedEvent);
|
||||
}
|
||||
|
||||
public void AttendeeAcceptEvent(int attendeeId)
|
||||
@@ -49,6 +52,9 @@ namespace PracticeCalendar.Domain.Entities
|
||||
if (attendee == null)
|
||||
throw new InvalidAttendeeException(attendeeId);
|
||||
attendee.SetIsAttending(true);
|
||||
|
||||
var attendeeAcceptedEvent = new AttendeeAcceptedEvent(this, attendee);
|
||||
base.RegisterDomainEvent(attendeeAcceptedEvent);
|
||||
}
|
||||
|
||||
public void AttendeeDeclineEvent(int attendeeId)
|
||||
@@ -57,6 +63,9 @@ namespace PracticeCalendar.Domain.Entities
|
||||
if (attendee == null)
|
||||
throw new InvalidAttendeeException(attendeeId);
|
||||
attendee.SetIsAttending(false);
|
||||
|
||||
var attendeeDeclinedEvent = new AttendeeDeclinedEvent(this, attendee);
|
||||
base.RegisterDomainEvent(attendeeDeclinedEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using PracticeCalendar.Domain.Common;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
|
||||
namespace PracticeCalendar.Domain.Events
|
||||
{
|
||||
public sealed class AttendeeAcceptedEvent : DomainEventBase
|
||||
{
|
||||
public AttendeeAcceptedEvent(PracticeEvent practiceEvent, Attendee attendee)
|
||||
{
|
||||
PracticeEvent = practiceEvent;
|
||||
Attendee = attendee;
|
||||
}
|
||||
|
||||
public PracticeEvent PracticeEvent { get; }
|
||||
public Attendee Attendee { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using PracticeCalendar.Domain.Common;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
|
||||
namespace PracticeCalendar.Domain.Events
|
||||
{
|
||||
public sealed class AttendeeDeclinedEvent : DomainEventBase
|
||||
{
|
||||
public AttendeeDeclinedEvent(PracticeEvent practiceEvent, Attendee attendee)
|
||||
{
|
||||
PracticeEvent = practiceEvent;
|
||||
Attendee = attendee;
|
||||
}
|
||||
|
||||
public PracticeEvent PracticeEvent { get; }
|
||||
public Attendee Attendee { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using PracticeCalendar.Domain.Common;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
|
||||
namespace PracticeCalendar.Domain.Events
|
||||
{
|
||||
public sealed class EventUpdateTitleAndDescriptionEvent : DomainEventBase
|
||||
{
|
||||
public EventUpdateTitleAndDescriptionEvent(PracticeEvent practiceEvent)
|
||||
{
|
||||
PracticeEvent = practiceEvent;
|
||||
}
|
||||
|
||||
public PracticeEvent PracticeEvent { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user