public async Task <WorkshopPlanning> HandleCommandAsync(DateTime planningDate, UpdateMaintenanceJob command) { // get or create workshop-planning WorkshopPlanning planning = await planningRepository.GetWorkshopPlanningAsync(planningDate); if (planning == null) { return(null); } // handle command planning.UpdateMaintenanceJob(command); // persist IEnumerable <Event> events = planning.GetEvents(); await planningRepository.SaveWorkshopPlanningAsync( planning.Id, planning.OriginalVersion, planning.Version, events); // publish event foreach (var e in events) { await messagePublisher.PublishMessageAsync(e.MessageType, e, ""); } // return result return(planning); }
public void Finish_MaintenanceJob_Should_Finish_A_New_MaintenanceJob() { // arrange DateTime date = DateTime.Today; string workshopPlanningId = date.ToString("yyyy-MM-dd"); Guid jobId = Guid.NewGuid(); DateTime startTime = date.AddHours(8); DateTime endTime = date.AddHours(11); DateTime actualStartTime = date.AddHours(9); DateTime actualEndTime = date.AddHours(12); var initializingEvents = new Event[] { new WorkshopPlanningCreatedEventBuilder() .WithDate(date) .Build(), new MaintenanceJobPlannedEventBuilder() .WithStartTime(startTime) .WithEndTime(endTime) .WithJobId(jobId) .Build() }; WorkshopPlanning sut = new WorkshopPlanning(date, initializingEvents); FinishMaintenanceJob command = new FinishMaintenanceJobCommandBuilder() .WithJobId(jobId) .WithActualStartTime(actualStartTime) .WithActualEndTime(actualEndTime) .Build(); // act sut.FinishMaintenanceJob(command); IEnumerable <Event> events = sut.GetEvents(); // assert Assert.NotNull(sut); Assert.NotNull(sut.Id); Assert.Equal(workshopPlanningId, sut.Id); Assert.Equal(2, sut.OriginalVersion); Assert.Equal(3, sut.Version); Assert.Collection(sut.Jobs, item0 => { Assert.Equal(command.JobId, item0.Id); Assert.Equal(startTime, item0.StartTime); Assert.Equal(endTime, item0.EndTime); Assert.Equal(command.StartTime, item0.ActualStartTime); Assert.Equal(command.Notes, item0.Notes); } ); Assert.Collection(events, item0 => Assert.IsAssignableFrom <MaintenanceJobFinished>(item0)); }
public void Create_Should_Create_A_New_Instance() { // arrange DateTime date = DateTime.Today; // act WorkshopPlanning sut = WorkshopPlanning.Create(date); IEnumerable <Event> events = sut.GetEvents(); // assert Assert.NotNull(sut); Assert.NotNull(sut.Id); Assert.Equal(date, sut.Id); Assert.Equal(0, sut.OriginalVersion); Assert.Equal(1, sut.Version); Assert.Empty(sut.Jobs); Assert.Collection(events, item0 => Assert.IsAssignableFrom <WorkshopPlanningCreated>(item0)); }
public void Plan_MaintenanceJob_Should_Add_A_New_MaintenanceJob() { // arrange DateTime date = DateTime.Today; string workshopPlanningId = date.ToString("yyyy-MM-dd"); var initializingEvents = new Event[] { new WorkshopPlanningCreatedEventBuilder().WithDate(date).Build() }; WorkshopPlanning sut = new WorkshopPlanning(date, initializingEvents); PlanMaintenanceJob command = new PlanMaintenanceJobCommandBuilder() .Build(); // act sut.PlanMaintenanceJob(command); IEnumerable <Event> events = sut.GetEvents(); // assert Assert.NotNull(sut); Assert.NotNull(sut.Id); Assert.Equal(workshopPlanningId, sut.Id); Assert.Equal(1, sut.OriginalVersion); Assert.Equal(2, sut.Version); Assert.Collection(sut.Jobs, item0 => { Assert.Equal(command.JobId, item0.Id); Assert.Equal(command.StartTime, item0.StartTime); Assert.Equal(command.EndTime, item0.EndTime); Assert.Equal(command.CustomerInfo.Id, item0.Customer.Id); Assert.Equal(command.CustomerInfo.Name, item0.Customer.Name); Assert.Equal(command.CustomerInfo.TelephoneNumber, item0.Customer.TelephoneNumber); Assert.Equal(command.VehicleInfo.LicenseNumber, item0.Vehicle.Id); Assert.Equal(command.VehicleInfo.Brand, item0.Vehicle.Brand); Assert.Equal(command.VehicleInfo.Type, item0.Vehicle.Type); Assert.Equal(command.CustomerInfo.Id, item0.Vehicle.OwnerId); Assert.Equal(command.Description, item0.Description); } ); Assert.Collection(events, item0 => Assert.IsAssignableFrom <MaintenanceJobPlanned>(item0)); }