Esempio n. 1
0
        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));
        }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
 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);
            }
        }
Esempio n. 6
0
        // 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);
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 9
0
 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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
 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));
 }
Esempio n. 14
0
 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 */ }));
 }
Esempio n. 16
0
 private static async Task <Exception> RunTriggerFailureAsync(StorageAccount account, Type programType)
 {
     return(await FunctionalTest.RunTriggerFailureAsync <bool>(account, programType, (tcs) => { /* do nothing */ }));
 }
Esempio n. 17
0
 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);
 }
Esempio n. 18
0
 private async Task CallAsync(Type programType, string methodName, params Type[] customExtensions)
 {
     await FunctionalTest.CallAsync(b => ConfigureStorage(b), programType, programType.GetMethod(methodName), null, customExtensions);
 }
Esempio n. 19
0
 private static async Task CallAsync(StorageAccount account, Type programType, string methodName, params Type[] customExtensions)
 {
     await FunctionalTest.CallAsync(account, programType, programType.GetMethod(methodName), null, customExtensions);
 }
Esempio n. 20
0
 private static Exception RunTriggerFailure <TResult>(IStorageAccount account, Type programType,
                                                      Action <TaskCompletionSource <TResult> > setTaskSource)
 {
     return(FunctionalTest.RunTriggerFailure <TResult>(account, programType, setTaskSource));
 }
Esempio n. 21
0
 private static Exception RunTriggerFailure(IStorageAccount account, Type programType)
 {
     return(FunctionalTest.RunTriggerFailure(account, programType));
 }
Esempio n. 22
0
 private async Task <Exception> RunTriggerFailureAsync <TResult>(Type programType,
                                                                 Action <TaskCompletionSource <TResult> > setTaskSource)
 {
     return(await FunctionalTest.RunTriggerFailureAsync <TResult>(b => ConfigureQueues(b), programType, setTaskSource));
 }
Esempio n. 23
0
 private static async Task RunTrigger(StorageAccount account, Type programType)
 {
     await FunctionalTest.RunTriggerAsync(account, programType);
 }
Esempio n. 24
0
 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);
 }
Esempio n. 25
0
 private static async Task <Exception> RunTriggerFailureAsync <TResult>(StorageAccount account, Type programType,
                                                                        Action <TaskCompletionSource <TResult> > setTaskSource)
 {
     return(await FunctionalTest.RunTriggerFailureAsync <TResult>(account, programType, setTaskSource));
 }
Esempio n. 26
0
 private static void RunTrigger(IStorageAccount account, Type programType, IExtensionRegistry extensions = null)
 {
     FunctionalTest.RunTrigger(account, programType, extensions);
 }
Esempio n. 27
0
 private static async Task <Exception> CallFailureAsync(StorageAccount account, Type programType, string methodName)
 {
     return(await FunctionalTest.CallFailureAsync(account, programType, programType.GetMethod(methodName), null));
 }
Esempio n. 28
0
 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));
 }
Esempio n. 30
0
 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));
 }