public async Task ReceivedApiCalls_GetsAllRecordedApiCalls() { ApiBuilder apiBuilder = new ApiBuilder(Substitute.For <ISimulation>()) .AddHandler("GET /api/v2/books", _ => throw new Exception()); var apiSimulator = new ApiSimulator(apiBuilder); try { await apiSimulator.StartAsync(); var port = apiSimulator.Port; using var httpClient = new HttpClient(); var task1 = Task.Run(async() => { var request = new HttpRequestMessage(HttpMethod.Get, $"http://localhost:{port}/api/v2/books"); await httpClient.SendAsync(request); }); var task2 = Task.Run(async() => { var request = new HttpRequestMessage(HttpMethod.Patch, $"http://localhost:{port}/api/v2/books/32") { Content = new StringContent("{\"title\":\"abc\"}", Encoding.UTF8, "application/json") }; await httpClient.SendAsync(request); }); await Task.WhenAll(task1, task2); } finally { await apiSimulator.StopAsync(); } System.Collections.Generic.IReadOnlyCollection <ApiCall> apiCalls = apiSimulator.ReceivedApiCalls; ApiCall getCall = apiCalls.FirstOrDefault(call => call.Action == "GET /api/v2/books"); apiCalls.ShouldSatisfyAllConditions( () => getCall.ShouldNotBeNull(), () => getCall.Exception.ShouldNotBeNull(), () => apiCalls.Count.ShouldBe(2), () => apiCalls .Single(call => call.Action == "PATCH /api/v2/books/32") .ShouldNotBeNull() ); }
public async Task ForceRun <T, D>(string key, string group) where T : IBlackPearlJob <D> where D : class, new() { if (scheduler == null) { return; } var jobKey = new JobKey(key, group); bool jobExists = await scheduler.CheckExists(jobKey); if (!jobExists) { return; } System.Collections.Generic.IReadOnlyCollection <ITrigger> trigger = await scheduler.GetTriggersOfJob(jobKey); await scheduler.TriggerJob(jobKey, trigger?.FirstOrDefault()?.JobDataMap); }