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); }
/// <summary> /// Returns a file system implementation, which is assigned /// to the <see cref="TestContext.FileSystem"/> property. /// </summary> /// <param name="localTestFolder">The temporary test folder that is /// used by the context. This is actually just the <see cref="TestContext.LocalTestRoot"/> /// reference.</param> protected override IFileSystemProvider InitFileSystem(DirectoryInfo localTestFolder) { ServiceFileSystem = GetServiceProvider(); var settings = new VfsServiceSettings(); ServiceHost = new TestServiceHost { Configuration = new TestConfiguration(ServiceFileSystem, settings) }; ServiceBaseUri = "http://localhost:33456/"; ServiceHost.Initialize(new[] { ServiceBaseUri }, "/", null); ServiceHost.StartListening(); // //TODO remove debug code // ServiceBaseUri = "http://127.0.0.1:56789/"; return new FileSystemFacade(ServiceBaseUri); }
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); }
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); }
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); }
public void Init() { ServiceFileSystem = GetServiceProvider(); ServiceSettings = CustomizeSettings(new VfsServiceSettings()); ServiceHost = new TestServiceHost {Configuration = new TestConfiguration(ServiceFileSystem, ServiceSettings)}; ServiceBaseUri = "http://localhost:33456/"; ServiceHost.Initialize(new[] { ServiceBaseUri }, "/", null); ServiceHost.StartListening(); // //TODO remove debug code // ServiceBaseUri = "http://127.0.0.1:56789/"; ClientFileSystem = new FileSystemFacade(ServiceBaseUri); //get root folders ClientRoot = VirtualFolder.CreateRootFolder(ClientFileSystem); ServiceRoot = VirtualFolder.CreateRootFolder(ServiceFileSystem); InitInternal(); }
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); }