public async Task Trigger_CanBeInstanceMethod() { // Arrange string expectedGuid = Guid.NewGuid().ToString(); CloudQueueMessage expectedMessage = new CloudQueueMessage(expectedGuid); var account = new XFakeStorageAccount(); await account.AddQueueMessageAsync(expectedMessage, QueueName); var prog = new InstanceProgram(); IHost host = new HostBuilder() .ConfigureDefaultTestHost <InstanceProgram>(prog, builder => { builder.AddAzureStorage() .UseStorage(account); }) .Build(); // Act var jobHost = host.GetJobHost <InstanceProgram>(); var result = await jobHost.RunTriggerAsync <CloudQueueMessage>(); // Assert Assert.Equal(expectedGuid, result.AsString); }
public async Task Trigger_IfClassIsDisposable_Disposes() { // Arrange CloudQueueMessage expectedMessage = new CloudQueueMessage("ignore"); var account = new XFakeStorageAccount(); await account.AddQueueMessageAsync(expectedMessage, QueueName); IHost host = new HostBuilder() .ConfigureDefaultTestHost <DisposeInstanceProgram>(builder => { builder.UseStorage(account); }) .Build(); // Act & Assert var jobHost = host.GetJobHost <DisposeInstanceProgram>(); var result = await jobHost.RunTriggerAsync <object>(DisposeInstanceProgram.TaskSource); }
public async Task Trigger_IfClassConstructorHasDependencies_CanUseCustomJobActivator() { // Arrange const string expectedResult = "abc"; Mock <IFactory <string> > resultFactoryMock = new Mock <IFactory <string> >(MockBehavior.Strict); resultFactoryMock.Setup(f => f.Create()).Returns(expectedResult); IFactory <string> resultFactory = resultFactoryMock.Object; Mock <IJobActivator> activatorMock = new Mock <IJobActivator>(MockBehavior.Strict); activatorMock.Setup(a => a.CreateInstance <InstanceCustomActivatorProgram>()) .Returns(() => new InstanceCustomActivatorProgram(resultFactory)); IJobActivator activator = activatorMock.Object; CloudQueueMessage message = new CloudQueueMessage("ignore"); var account = new XFakeStorageAccount(); await account.AddQueueMessageAsync(message, QueueName); IHost host = new HostBuilder() .ConfigureDefaultTestHost <InstanceCustomActivatorProgram>(builder => { builder.UseStorage(account); }, null, activator) .Build(); // Act var jobHost = host.GetJobHost <InstanceCustomActivatorProgram>(); Assert.NotNull(jobHost); var result = await jobHost.RunTriggerAsync <string>(InstanceCustomActivatorProgram.TaskSource); // Assert Assert.Same(expectedResult, result); }