public async Task ShouldDisposeChildScopesWhenParentDisposed(Mock <IJobMetadata> jobMetadata)
        {
            // Arrange
            jobMetadata.Setup(s => s.JobClass).Returns(typeof(TestJob));
            var sut = new DefaultJobFactory(this.CreateServiceProvider(jobMetadata.Object, ServiceLifetime.Scoped));

            // Act
            IJob parentJob;
            IJob childJob;

            using (sut.BeginScope())
            {
                var rootJob = sut.CreateJobInstance(jobMetadata.Object);

                using (sut.BeginScope())
                {
                    parentJob = sut.CreateJobInstance(jobMetadata.Object);

                    sut.BeginScope();
                    childJob = sut.CreateJobInstance(jobMetadata.Object);
                }

                // Assert
                await Assert.ThrowsAsync <ObjectDisposedException>(() => childJob.Invoke(null, CancellationToken.None));

                await Assert.ThrowsAsync <ObjectDisposedException>(() => parentJob.Invoke(null, CancellationToken.None));

                await rootJob.Invoke(null, CancellationToken.None);
            }
        }
        public void ShouldCreateJobInstanceInScope(ServiceLifetime serviceLifetime, int disctictInstanceCount, Mock <IJobMetadata> jobMetadata)
        {
            // Arrange
            jobMetadata.Setup(s => s.JobClass).Returns(typeof(TestJob));
            var sut = new DefaultJobFactory(this.CreateServiceProvider(jobMetadata.Object, serviceLifetime));

            // Act
            var results = new List <IJob>(3);

            using (sut.BeginScope())
            {
                results.Add(sut.CreateJobInstance(jobMetadata.Object));
                using (sut.BeginScope())
                {
                    results.Add(sut.CreateJobInstance(jobMetadata.Object));
                }

                results.Add(sut.CreateJobInstance(jobMetadata.Object));
            }

            // Assert
            Assert.All(results, job => Assert.IsType <TestJob>(job));
            Assert.Equal(disctictInstanceCount, results.Cast <TestJob>().Select(j => j.JobId).Distinct().Count());
        }