public async Task InvokeReconcile(string scope, string rule, string item) { // Arrange var client = new VstsRestClient(_config.Organization, _config.Token); var token = await SessionToken(client, "tas", _config.ExtensionName); var request = new DummyHttpRequest { Headers = { ["Authorization"] = $"Bearer {token}" } }; // Act await _host.Jobs.CallAsync(nameof(ReconcileFunction), new Dictionary <string, object> { ["request"] = request, ["organization"] = _config.Organization, ["project"] = _config.ProjectId, ["scope"] = scope, ["ruleName"] = rule, ["item"] = item }).ConfigureAwait(false); // Assert await _host.Jobs .Ready() .ThrowIfFailed() .Purge().ConfigureAwait(false); }
public async Task Test1() { // Arrange var connectionString = _config["AzureWebJobsStorage"] ?? "UseDevelopmentStorage=true"; Environment.SetEnvironmentVariable("AzureWebJobsStorage", connectionString); Environment.SetEnvironmentVariable("AzureWebJobsSupportContactStorage", connectionString); Environment.SetEnvironmentVariable("SupportContactTableName", "SupportContacts"); _ = typeof(NotifySupportHttpClient).FullName; // make sure the type is loaded to be resolved as function object response = null; using var host = new HostBuilder() .ConfigureWebJobs(builder => builder .AddHttp(options => options.SetResponse = (r, o) => response = o) .AddDurableTask(options => options.NotificationUrl = new Uri("https://asdf")) // req'd for CreateCheckStatusResponse .AddAzureStorage() .AddAzureStorageCoreServices()) .Build(); await host.StartAsync(); var jobs = host.Services.GetService <IJobHost>(); // Act var request = new DummyHttpRequest("{ 'Message': '', 'Severity': 1 }") { ContentType = "application/octet-stream", Method = "POST" }; request.Headers["Content-Type"] = "application/json"; await jobs.CallAsync(nameof(NotifySupportHttpClient), new Dictionary <string, object> { ["message"] = request }); // Assert var message = Assert.IsType <HttpResponseMessage>(response); Assert.Equal(message.StatusCode, HttpStatusCode.Accepted); }