コード例 #1
0
            public async Task GivenJobWithConstructorArgs_ItResolvesThemFromTheContainer()
            {
                // Arrange
                var expected = new SomeService();
                var host     = new TestServiceHost(
                    componentRegistrations: b => {
                    b.RegisterInstance(expected).As <SomeService>();
                });

                host.Initialize();

                var job = new JobDescription("test", typeof(TestJobWithService));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary <string, string>());
                var context    = new InvocationContext(invocation, queue: null);
                var slot       = new ContextSlot();

                TestJobWithService.SetContextSlot(slot);

                // Act
                await dispatcher.Dispatch(context);

                // Assert
                Assert.Same(expected, slot.Value);
            }
コード例 #2
0
ファイル: JobRunner.cs プロジェクト: WeilerWebServices/NuGet
        public JobRunner(JobDispatcher dispatcher, InvocationQueue queue, ConfigurationHub config, Clock clock, CloudBlobContainer logContainer)
            : this(config.GetSection <WorkConfiguration>().PollInterval)
        {
            Dispatcher = dispatcher;
            Queue      = queue;
            Clock      = clock;

            _logContainer = logContainer;
        }
コード例 #3
0
        public JobRunner(JobDispatcher dispatcher, InvocationQueue queue, ConfigurationHub config, Clock clock, CloudBlobContainer logContainer)
            : this(config.GetSection<WorkConfiguration>().PollInterval)
        {
            Dispatcher = dispatcher;
            Queue = queue;
            Clock = clock;

            _logContainer = logContainer;
        }
コード例 #4
0
            public async Task GivenNoJobWithName_ItThrowsUnknownJobException()
            {
                // Arrange
                var host = new TestServiceHost();
                host.Initialize();

                var dispatcher = new JobDispatcher(Enumerable.Empty<JobDescription>(), host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "flarg", "test", new Dictionary<string, string>());
                var context = new InvocationContext(invocation, queue: null);

                // Act/Assert
                var ex = await AssertEx.Throws<UnknownJobException>(() => dispatcher.Dispatch(context));
                Assert.Equal("flarg", ex.JobName);
            }
コード例 #5
0
            public async Task GivenNoJobWithName_ItThrowsUnknownJobException()
            {
                // Arrange
                var host = new TestServiceHost();

                host.Initialize();

                var dispatcher = new JobDispatcher(Enumerable.Empty <JobDescription>(), host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "flarg", "test", new Dictionary <string, string>());
                var context    = new InvocationContext(invocation, queue: null);

                // Act/Assert
                var ex = await AssertEx.Throws <UnknownJobException>(() => dispatcher.Dispatch(context));

                Assert.Equal("flarg", ex.JobName);
            }
コード例 #6
0
            public async Task GivenAContinuationRequest_ItCallsTheInvokeContinuationMethod()
            {
                // Arrange
                var host = new TestServiceHost();

                host.Initialize();

                var job = new JobDescription("test", typeof(TestAsyncJob));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary <string, string>(), isContinuation: true);
                var context    = new InvocationContext(invocation, queue: null);

                // Act
                var result = await dispatcher.Dispatch(context);

                // Assert
                Assert.Equal(ExecutionResult.Completed, result.Result);
            }
コード例 #7
0
            public async Task GivenJobWithName_ItInvokesTheJobAndReturnsTheResult()
            {
                // Arrange
                var host = new TestServiceHost();
                host.Initialize();

                var job = new JobDescription("test", typeof(TestJob));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary<string, string>());
                var context = new InvocationContext(invocation, queue: null);
                var expected = InvocationResult.Completed();
                TestJob.SetTestResult(expected);

                // Act
                var actual = await dispatcher.Dispatch(context);

                // Assert
                Assert.Same(expected, actual);
            }
コード例 #8
0
            public async Task GivenAContinuationRequestToANonAsyncJob_ItThrows()
            {
                // Arrange
                var host = new TestServiceHost();

                host.Initialize();

                var job = new JobDescription("test", typeof(TestJob));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary <string, string>(), isContinuation: true);
                var context    = new InvocationContext(invocation, queue: null);

                // Act/Assert
                var ex = await AssertEx.Throws <InvalidOperationException>(() => dispatcher.Dispatch(context));

                Assert.Equal(String.Format(
                                 Strings.JobDispatcher_AsyncContinuationOfNonAsyncJob,
                                 job.Name), ex.Message);
            }
コード例 #9
0
            public async Task GivenJobWithName_ItInvokesTheJobAndReturnsTheResult()
            {
                // Arrange
                var host = new TestServiceHost();

                host.Initialize();

                var job = new JobDescription("test", typeof(TestJob));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary <string, string>());
                var context    = new InvocationContext(invocation, queue: null);
                var expected   = InvocationResult.Completed();

                TestJob.SetTestResult(expected);

                // Act
                var actual = await dispatcher.Dispatch(context);

                // Assert
                Assert.Same(expected, actual);
            }
コード例 #10
0
            public async Task GivenJobWithConstructorArgs_ItResolvesThemFromTheContainer()
            {
                // Arrange
                var expected = new SomeService();
                var host = new TestServiceHost(
                    componentRegistrations: b => {
                        b.RegisterInstance(expected).As<SomeService>();
                    });
                host.Initialize();

                var job = new JobDescription("test", typeof(TestJobWithService));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary<string, string>());
                var context = new InvocationContext(invocation, queue: null);
                var slot = new ContextSlot();
                TestJobWithService.SetContextSlot(slot);
                
                // Act
                await dispatcher.Dispatch(context);
                
                // Assert
                Assert.Same(expected, slot.Value);
            }
コード例 #11
0
ファイル: JobRunner.cs プロジェクト: WeilerWebServices/NuGet
 public JobRunner(JobDispatcher dispatcher, InvocationQueue queue, ConfigurationHub config, Clock clock)
     : this(dispatcher, queue, config, clock, config.Storage.Primary == null ? null : config.Storage.Primary.CreateCloudBlobClient().GetContainerReference(WorkService.InvocationLogsContainerBaseName))
 {
 }
コード例 #12
0
            public async Task GivenAContinuationRequest_ItCallsTheInvokeContinuationMethod()
            {
                // Arrange
                var host = new TestServiceHost();
                host.Initialize();

                var job = new JobDescription("test", typeof(TestAsyncJob));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary<string, string>(), isContinuation: true);
                var context = new InvocationContext(invocation, queue: null);
                
                // Act
                var result = await dispatcher.Dispatch(context);

                // Assert
                Assert.Equal(ExecutionResult.Completed, result.Result);
            }
コード例 #13
0
            public async Task GivenAContinuationRequestToANonAsyncJob_ItThrows()
            {
                // Arrange
                var host = new TestServiceHost();
                 host.Initialize();

                var job = new JobDescription("test", typeof(TestJob));

                var dispatcher = new JobDispatcher(new[] { job }, host.Container);
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "Test", "test", new Dictionary<string, string>(), isContinuation: true);
                var context = new InvocationContext(invocation, queue: null);

                // Act/Assert
                var ex = await AssertEx.Throws<InvalidOperationException>(() => dispatcher.Dispatch(context));
                Assert.Equal(String.Format(
                    Strings.JobDispatcher_AsyncContinuationOfNonAsyncJob,
                    job.Name), ex.Message);
            }
コード例 #14
0
 public JobRunner(JobDispatcher dispatcher, InvocationQueue queue, ConfigurationHub config, Clock clock)
     : this(dispatcher, queue, config, clock, config.Storage.Primary == null ? null : config.Storage.Primary.CreateCloudBlobClient().GetContainerReference(WorkService.InvocationLogsContainerBaseName))
 {
 }