public void Handle(DisableJob command)
        {
            SchedulerJob job = repository.GetById(command.JobId);

            job.Disable();
            repository.Save(job);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //NativeQueue<CrashInfo> destroyedPlanetoidsQueue = new NativeQueue<CrashInfo>(Allocator.TempJob);
        EntityQuery             entityQuery = GetEntityQuery(typeof(Planetoid));
        NativeArray <Planetoid> planetoids  = entityQuery.ToComponentDataArray <Planetoid>(Allocator.TempJob);
        NativeArray <int>       keys        = QuadrantSystem.quadrantMultiHashMap.GetKeyArray(Allocator.TempJob);
        NativeArray <JobHandle> jobHandles  = new NativeArray <JobHandle>(keys.Length, Allocator.TempJob);


        for (int i = 0; i < keys.Length; i++)
        {
            NativeArray <EntityWithProps> entityWithPropsArray = new NativeArray <EntityWithProps>(QuadrantSystem.GetEntityCountInQuadrant(QuadrantSystem.quadrantMultiHashMap, keys[i]), Allocator.TempJob);
            SortPositionsJob sortPositionsJob = new SortPositionsJob
            {
                quadrantMultiHashMap = QuadrantSystem.quadrantMultiHashMap,
                entityWithPropsArray = entityWithPropsArray,
                realtimeSinceStartUp = Time.realtimeSinceStartup,
                planetoids           = planetoids,
                keys  = keys,
                index = i
            };

            jobHandles[i] = sortPositionsJob.Schedule();
        }

        JobHandle job = JobHandle.CombineDependencies(jobHandles);

        JobHandle.CompleteAll(jobHandles);
        jobHandles.Dispose();
        keys.Dispose();


        //destroyedPlanetoidsQueue.Dispose();

        DisableJob disableJob = new DisableJob
        {
            entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        };

        JobHandle jobHandle = disableJob.Schedule(this, job);//TODO try job handles combine

        endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);


        AddTranslationJob addTranslationJob = new AddTranslationJob
        {
            seed = UnityEngine.Random.Range(1, 1000000),
            realTimeSinceStartUp = Time.realtimeSinceStartup,
            entityCommandBuffer  = endPresentationSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            cameraMaxLeftDown    = Camera.main.ViewportToWorldPoint(new Vector3(0, 0)),
            cameraMaxRightUp     = Camera.main.ViewportToWorldPoint(new Vector3(1, 1))
        };

        jobHandle = addTranslationJob.Schedule(this, jobHandle);
        endPresentationSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);



        return(jobHandle);
    }
        public void HandleDisableJobCommandEventStoreSavesJob()
        {
            // Arrange
            List <ISchedulerTask> tasks = new List <ISchedulerTask>();
            ISchedulerTask        task  = MockRepository.GenerateMock <ISchedulerTask>();

            tasks.Add(task);

            DisableJob command = new DisableJob(Guid.NewGuid());

            List <Event> events = new List <Event>();

            eventStore.Stub(x => x.GetEventsForAggregate(command.JobId)).Return(new List <Event>()
            {
                new JobCreated(command.JobId, tasks)
            });

            // Act
            schedulerJobCommandHandlers.Handle(command);

            // Assert
            eventStore.AssertWasCalled(x => x.SaveEvents(
                                           Arg <Guid> .Matches(s => s.Equals(command.JobId)),

                                           Arg <IEnumerable <Event> > .Matches(s =>
                                                                               s.Count() == 1 &&
                                                                               ((JobDisabled)s.ElementAt(0)).JobId.Equals(command.JobId)),

                                           Arg <int> .Matches(s => s == 2)
                                           ));
        }
        public void HandleDisableJobCommandEventStoreSavesJob()
        {
            // Arrange
            List<ISchedulerTask> tasks = new List<ISchedulerTask>();
            ISchedulerTask task = MockRepository.GenerateMock<ISchedulerTask>();
            tasks.Add(task);

            DisableJob command = new DisableJob(Guid.NewGuid());

            List<Event> events = new List<Event>();
            eventStore.Stub(x => x.GetEventsForAggregate(command.JobId)).Return(new List<Event>()
            {
                new JobCreated(command.JobId, tasks)
            });

            // Act
            schedulerJobCommandHandlers.Handle(command);

            // Assert
            eventStore.AssertWasCalled(x => x.SaveEvents(
                Arg<Guid>.Matches(s => s.Equals(command.JobId)),

                Arg<IEnumerable<Event>>.Matches(s =>
                    s.Count() == 1 &&
                    ((JobDisabled)s.ElementAt(0)).JobId.Equals(command.JobId)),

                Arg<int>.Matches(s => s == 2)
            ));
        }