Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void Updating_A_Job_That_Conflicts_With_MaintenanceJobs_In_Parallel_Should_Throw_Exception()
        {
            // arrange
            var date      = DateTime.Today;
            var jobId     = Guid.NewGuid();
            var startTime = date.AddHours(12);
            var endTime   = date.AddHours(13);

            var createdEvent = new WorkshopPlanningCreatedEventBuilder()
                               .WithDate(date)
                               .Build();
            var plannedEvent1 = new MaintenanceJobPlannedEventBuilder()
                                .Build();
            var plannedEvent2 = new MaintenanceJobPlannedEventBuilder()
                                .Build();
            var plannedEvent3 = new MaintenanceJobPlannedEventBuilder()
                                .Build();

            var plannedEvent4 = new MaintenanceJobPlannedEventBuilder()
                                .WithStartTime(startTime)
                                .WithEndTime(endTime)
                                .WithJobId(jobId)
                                .Build();

            var initializingEvents = new Event[] {
                createdEvent,
                plannedEvent1,
                plannedEvent2,
                plannedEvent3,
                plannedEvent4
            };

            var sut = new WorkshopPlanning(date, initializingEvents);

            var command = new UpdateMaintenanceJobCommandBuilder()
                          .WithEvent(plannedEvent4)
                          .WithChangedStartTime(plannedEvent1.StartTime)
                          .WithChangedEndTime(plannedEvent1.EndTime)
                          .Build();

            // act
            var thrownException = Assert.Throws <BusinessRuleViolationException>(() =>
            {
                sut.UpdateMaintenanceJob(command); // 4th job is updated to conflict with the 1st job
            });

            // assert
            Assert.Equal("Maintenancejob overlaps with more than 3 other jobs.", thrownException.Message);
        }
Exemplo n.º 3
0
        public void Update_MaintenanceJob_That_Spans_Two_Days_Should_Throw_Exception()
        {
            // arrange
            var date      = DateTime.Today;
            var jobId     = Guid.NewGuid();
            var startTime = date.AddHours(8);
            var endTime   = date.AddHours(11);

            var createdEvent = new WorkshopPlanningCreatedEventBuilder()
                               .WithDate(date)
                               .Build();

            var plannedEvent = new MaintenanceJobPlannedEventBuilder()
                               .WithStartTime(startTime)
                               .WithEndTime(endTime)
                               .WithJobId(jobId)
                               .Build();

            var initializingEvents = new Event[] {
                createdEvent,
                plannedEvent
            };

            var sut = new WorkshopPlanning(date, initializingEvents);

            var command = new UpdateMaintenanceJobCommandBuilder()
                          .WithEvent(plannedEvent)
                          .WithChangedStartTime(startTime.AddDays(-1))
                          .Build();

            // act
            var thrownException =
                Assert.Throws <BusinessRuleViolationException>(() => sut.UpdateMaintenanceJob(command));

            // assert
            Assert.Equal("Start-time and end-time of a Maintenance Job must be within a 1 day.",
                         thrownException.Message);
        }
Exemplo n.º 4
0
        public void Updating_A_MaintenanceJobs_For_The_Same_Vehicle_with_Time_Conflict_Should_Throw_Exception()
        {
            // arrange
            var date       = DateTime.Today;
            var jobId1     = Guid.NewGuid();
            var jobId2     = Guid.NewGuid();
            var jobId3     = Guid.NewGuid();
            var startTime1 = date.AddHours(12);
            var endTime1   = date.AddHours(13);
            var startTime2 = date.AddHours(14);
            var endTime2   = date.AddHours(15);
            var startTime3 = date.AddHours(8);
            var endTime3   = date.AddHours(11);

            var vehicleBuilder = new VehicleBuilder();

            var createdEvent = new WorkshopPlanningCreatedEventBuilder()
                               .WithDate(date)
                               .Build();

            var plannedEvent1 = new MaintenanceJobPlannedEventBuilder()
                                .WithStartTime(startTime1)
                                .WithEndTime(endTime1)
                                .WithJobId(jobId1)
                                .WithVehicleBuilder(vehicleBuilder)
                                .Build();

            var plannedEvent2 = new MaintenanceJobPlannedEventBuilder()
                                .WithStartTime(startTime2)
                                .WithEndTime(endTime2)
                                .WithJobId(jobId2)
                                .WithVehicleBuilder(vehicleBuilder)
                                .Build();

            var plannedEvent3 = new MaintenanceJobPlannedEventBuilder()
                                .WithStartTime(startTime3)
                                .WithEndTime(endTime3)
                                .WithJobId(jobId3)
                                .WithVehicleBuilder(vehicleBuilder)
                                .Build();

            var initializingEvents = new Event[] {
                createdEvent,
                plannedEvent1,
                plannedEvent2,
                plannedEvent3
            };

            var sut = new WorkshopPlanning(date, initializingEvents);

            var command = new UpdateMaintenanceJobCommandBuilder()
                          .WithEvent(plannedEvent3)
                          .WithChangedStartTime(plannedEvent1.StartTime)
                          .WithChangedEndTime(plannedEvent1.EndTime)
                          .Build();

            // act
            var thrownException = Assert.Throws <BusinessRuleViolationException>(() =>
            {
                sut.UpdateMaintenanceJob(command); // 4th job is updated to conflict with the 1st job
            });

            // assert
            Assert.Equal("Only 1 maintenance job can be executed on a vehicle during a certain time-slot.",
                         thrownException.Message);
        }