private async Task <TResult> CallAsync <TResult>(Type programType, string methodName, Action <TaskCompletionSource <TResult> > setTaskSource) { IDictionary <string, object> arguments = null; return(await FunctionalTest.CallAsync <TResult>(b => ConfigureStorage(b), programType, programType.GetMethod(methodName), arguments, setTaskSource)); }
private static async Task <TResult> CallAsync <TResult>(StorageAccount account, Type programType, string methodName, Action <TaskCompletionSource <TResult> > setTaskSource) { IDictionary <string, object> arguments = null; return(await FunctionalTest.CallAsync <TResult>(account, programType, programType.GetMethod(methodName), arguments, setTaskSource)); }
private async Task <Exception> RunTriggerFailureAsync <TResult>(Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { return(await FunctionalTest.RunTriggerFailureAsync <TResult>(b => { b.AddAzureStorageQueues(); b.UseQueueService(queueServiceClient); }, programType, setTaskSource)); }
private async Task <TResult> RunTriggerAsync <TResult>(Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { return(await FunctionalTest.RunTriggerAsync <TResult>(b => { b.AddAzureStorageBlobs(); b.UseStorageServices(blobServiceClient, queueServiceClient); }, programType, setTaskSource)); }
// Stops running the host as soon as the program marks the task as completed. private static TResult RunTrigger <TResult>(IStorageAccount account, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource, Action <Task> setStartTask, Action <JobHost> callback) { TaskCompletionSource <object> startTaskSource = new TaskCompletionSource <object>(); setStartTask.Invoke(startTaskSource.Task); // Arrange try { TaskCompletionSource <TResult> taskSource = new TaskCompletionSource <TResult>(); IServiceProvider serviceProvider = FunctionalTest.CreateServiceProviderForManualCompletion <TResult>( account, programType, taskSource); Task <TResult> task = taskSource.Task; setTaskSource.Invoke(taskSource); try { // Arrange using (JobHost host = new JobHost(serviceProvider)) { host.Start(); callback.Invoke(host); startTaskSource.TrySetResult(null); // Act bool completed = task.WaitUntilCompleted(3 * 1000); // Assert Assert.True(completed); // Give a nicer test failure message for faulted tasks. if (task.Status == TaskStatus.Faulted) { task.GetAwaiter().GetResult(); } Assert.Equal(TaskStatus.RanToCompletion, task.Status); return(task.Result); } } finally { setTaskSource.Invoke(null); } } finally { setStartTask.Invoke(null); } }
// Stops running the host as soon as the program marks the task as completed. private static TResult RunTrigger <TResult>(IStorageAccount account, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource, Action <Task> setStartTask, Action <JobHost> callback) { TaskCompletionSource <object> startTaskSource = new TaskCompletionSource <object>(); setStartTask.Invoke(startTaskSource.Task); // Arrange try { TaskCompletionSource <TResult> taskSource = new TaskCompletionSource <TResult>(); var serviceProvider = FunctionalTest.CreateConfigurationForManualCompletion <TResult>( account, programType, taskSource); Task <TResult> task = taskSource.Task; setTaskSource.Invoke(taskSource); try { // Arrange JobHost host = serviceProvider.GetJobHost(); host.Start(); callback.Invoke(host); startTaskSource.TrySetResult(null); int secondsToWait = 5; // Act bool completed = task.WaitUntilCompleted(secondsToWait * 1000); // Assert Assert.True(completed, $"Host did not shut down in {secondsToWait} seconds."); // Give a nicer test failure message for faulted tasks. if (task.Status == TaskStatus.Faulted) { task.GetAwaiter().GetResult(); } Assert.Equal(TaskStatus.RanToCompletion, task.Status); return(task.Result); } finally { setTaskSource.Invoke(null); } } finally { setStartTask.Invoke(null); } }
private async Task <TResult> CallQueueTriggerAsync <TResult>(object message, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { var method = programType.GetMethod("Run"); Assert.NotNull(method); var result = await FunctionalTest.CallAsync <TResult>(account, programType, method, new Dictionary <string, object> { { "message", message } }, setTaskSource); return(result); }
private static TResult CallQueueTrigger <TResult>(object message, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { var account = new XFakeStorageAccount(); var method = programType.GetMethod("Run"); Assert.NotNull(method); var result = FunctionalTest.Call <TResult>(account, programType, method, new Dictionary <string, object> { { "message", message } }, setTaskSource); return(result); }
private async Task RunTrigger(Type programType) { await FunctionalTest.RunTriggerAsync(b => { b.Services.AddAzureClients(builder => { builder.ConfigureDefaults(options => options.Transport = AzuriteNUnitFixture.Instance.GetTransport()); }); b.AddAzureStorageBlobs(); b.AddAzureStorageQueues(); }, programType, settings : new Dictionary <string, string>() { // This takes precedence over env variables. { "ConnectionStrings:AzureWebJobsStorage", AzuriteNUnitFixture.Instance.GetAzureAccount().ConnectionString } }); }
public void CloudStorageAccount_CanCall() { // Arrange CloudStorageAccount realAccount = CloudStorageAccount.DevelopmentStorageAccount; StorageAccount account = StorageAccount.New(realAccount); // Act var t = typeof(CloudStorageAccountProgram); var result = FunctionalTest.Call <CloudStorageAccount>( account, t, t.GetMethod(nameof(CloudStorageAccountProgram.BindToCloudStorageAccount)), null, // args (s) => CloudStorageAccountProgram.TaskSource = s); // Assert Assert.NotNull(result); Assert.Same(realAccount, result); }
private static TResult CallQueueTrigger <TResult>(object message, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { // Arrange TaskCompletionSource <TResult> functionTaskSource = new TaskCompletionSource <TResult>(); IServiceProvider serviceProvider = FunctionalTest.CreateServiceProviderForManualCompletion <TResult>( CreateFakeStorageAccount(), programType, functionTaskSource); Task <TResult> functionTask = functionTaskSource.Task; setTaskSource.Invoke(functionTaskSource); Task callTask; bool completed; using (JobHost host = new JobHost(serviceProvider)) { try { callTask = host.CallAsync(programType.GetMethod("Run"), new { message = message }); // Act completed = Task.WhenAll(callTask, functionTask).WaitUntilCompleted(3 * 1000); } finally { setTaskSource.Invoke(null); } } // Assert Assert.True(completed); // Give a nicer test failure message for faulted tasks. if (functionTask.Status == TaskStatus.Faulted) { functionTask.GetAwaiter().GetResult(); } Assert.Equal(TaskStatus.RanToCompletion, functionTask.Status); Assert.Equal(TaskStatus.RanToCompletion, callTask.Status); return(functionTask.Result); }
public void Queue_IfNameIsInvalid_ThrowsDuringIndexing() { IStorageAccount account = CreateFakeStorageAccount(); TaskCompletionSource <object> backgroundTaskSource = new TaskCompletionSource <object>(); IServiceProvider serviceProvider = FunctionalTest.CreateServiceProviderForCallFailure(account, typeof(InvalidQueueNameProgram), backgroundTaskSource); using (JobHost host = new JobHost(serviceProvider)) { // Act & Assert FunctionIndexingException exception = Assert.Throws <FunctionIndexingException>(() => host.Start()); Assert.Equal("Error indexing method 'InvalidQueueNameProgram.Invalid'", exception.Message); Exception innerException = exception.InnerException; Assert.IsType <ArgumentException>(innerException); ArgumentException argumentException = (ArgumentException)innerException; Assert.Equal("name", argumentException.ParamName); string expectedMessage = String.Format(CultureInfo.InvariantCulture, "The dash (-) character may not be the first or last letter - \"-illegalname-\"{0}Parameter " + "name: name", Environment.NewLine); Assert.Equal(expectedMessage, innerException.Message); Assert.Equal(TaskStatus.WaitingForActivation, backgroundTaskSource.Task.Status); } }
private static async Task <TResult> RunTriggerAsync <TResult>(StorageAccount account, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource, IEnumerable <string> ignoreFailureFunctions) { return(await FunctionalTest.RunTriggerAsync <TResult>(account, programType, setTaskSource, ignoreFailureFunctions)); }
private static void RunTrigger(StorageAccount account, Type programType) { FunctionalTest.RunTrigger(account, programType); }
private static Exception RunTriggerFailure(StorageAccount account, Type programType) { return(FunctionalTest.RunTriggerFailure <bool>(account, programType, (tcs) => { /* do nothing */ })); }
private static async Task <Exception> RunTriggerFailureAsync(StorageAccount account, Type programType) { return(await FunctionalTest.RunTriggerFailureAsync <bool>(account, programType, (tcs) => { /* do nothing */ })); }
private async Task CallAsync(Type programType, string methodName, IDictionary <string, object> arguments, params Type[] customExtensions) { await FunctionalTest.CallAsync(b => ConfigureStorage(b), programType, programType.GetMethod(methodName), arguments, customExtensions); }
private async Task CallAsync(Type programType, string methodName, params Type[] customExtensions) { await FunctionalTest.CallAsync(b => ConfigureStorage(b), programType, programType.GetMethod(methodName), null, customExtensions); }
private static async Task CallAsync(StorageAccount account, Type programType, string methodName, params Type[] customExtensions) { await FunctionalTest.CallAsync(account, programType, programType.GetMethod(methodName), null, customExtensions); }
private static Exception RunTriggerFailure <TResult>(IStorageAccount account, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { return(FunctionalTest.RunTriggerFailure <TResult>(account, programType, setTaskSource)); }
private static Exception RunTriggerFailure(IStorageAccount account, Type programType) { return(FunctionalTest.RunTriggerFailure(account, programType)); }
private async Task <Exception> RunTriggerFailureAsync <TResult>(Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { return(await FunctionalTest.RunTriggerFailureAsync <TResult>(b => ConfigureQueues(b), programType, setTaskSource)); }
private static async Task RunTrigger(StorageAccount account, Type programType) { await FunctionalTest.RunTriggerAsync(account, programType); }
private static async Task CallAsync(StorageAccount account, Type programType, string methodName, IDictionary <string, object> arguments, params Type[] customExtensions) { await FunctionalTest.CallAsync(account, programType, programType.GetMethod(methodName), arguments, customExtensions); }
private static async Task <Exception> RunTriggerFailureAsync <TResult>(StorageAccount account, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource) { return(await FunctionalTest.RunTriggerFailureAsync <TResult>(account, programType, setTaskSource)); }
private static void RunTrigger(IStorageAccount account, Type programType, IExtensionRegistry extensions = null) { FunctionalTest.RunTrigger(account, programType, extensions); }
private static async Task <Exception> CallFailureAsync(StorageAccount account, Type programType, string methodName) { return(await FunctionalTest.CallFailureAsync(account, programType, programType.GetMethod(methodName), null)); }
private async Task <Exception> CallFailureAsync(Type programType, string methodName) { return(await FunctionalTest.CallFailureAsync(b => ConfigureStorage(b), programType, programType.GetMethod(methodName), null)); }
private static TResult RunTrigger <TResult>(IStorageAccount account, Type programType, Action <TaskCompletionSource <TResult> > setTaskSource, IJobActivator activator) { return(FunctionalTest.RunTrigger <TResult>(account, programType, activator, setTaskSource)); }
private async Task <TResult> RunTriggerAsync <TResult>(Type programType, Action <TaskCompletionSource <TResult> > setTaskSource, IEnumerable <string> ignoreFailureFunctions) { return(await FunctionalTest.RunTriggerAsync <TResult>(b => ConfigureQueues(b), programType, setTaskSource, ignoreFailureFunctions)); }