Last active
November 3, 2016 08:39
-
-
Save heemskerkerik/e9842940d4a5867f7d5cd20193789c8f to your computer and use it in GitHub Desktop.
Testing an event-sourced object's behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private AppointmentCreated CreateAppointmentCreatedEvent() | |
{ | |
return new AppointmentCreated( | |
appointmentId: Guid.NewGuid(), | |
startTime: DateTimeOffset.Now.AddHours(3), | |
endTime: DateTimeOffset.Now.AddHours(4), | |
title: "Appointment"); | |
} | |
private AppointmentRenamed CreateAppointmentRenamedEvent() | |
{ | |
return new AppointmentRenamed(title: "Renamed appointment"); | |
} | |
private Appointment CreateSut(IEnumerable<IEvent> events) | |
{ | |
var sut = new Appointment(); | |
foreach (var @event in events) | |
sut.ReplayEvent(@event); | |
return sut; | |
} | |
[Fact] | |
public void Reschedule_AppendsAppointmentRescheduled() | |
{ | |
// GIVEN these events have happened | |
var events = new IEvent[] | |
{ | |
CreateAppointmentCreatedEvent(), | |
CreateAppointmentRenamedEvent() | |
}; | |
var sut = CreateSut(events); | |
// WHEN we ask to reschedule | |
var newStartTime = DateTimeOffset.Now.AddHours(5); | |
var newEndTime = DateTimeOffset.Now.AddHours(6); | |
sut.Reschedule(newStartTime, newEndTime); | |
// THEN does the AppointmentRescheduledEvent get published? | |
sut.AppendedEvents.ShouldAllBeEquivalentTo( | |
new[] | |
{ | |
new AppointmentRescheduled(newStartTime, newEndTime) | |
}, | |
config => config.RespectingRuntimeTypes()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment