public async Task TryQueueJobs_Called_ReturnsJobCreateResults() { IJobsApiClient jobsApiClient = Substitute.For <IJobsApiClient>(); JobManagementResiliencePolicies policies = new JobManagementResiliencePolicies { JobsApiClient = Policy.NoOpAsync() }; IMessengerService messengerService = Substitute.For <IMessengerService>(); ILogger logger = Substitute.For <ILogger>(); JobCreateModel createModelOne = new JobCreateModel(); JobCreateModel createModelTwo = new JobCreateModel(); JobCreateResult expectedCreateResultOne = new JobCreateResult(); JobCreateResult expectedCreateResultTwo = new JobCreateResult(); IEnumerable <JobCreateModel> createModels = new [] { createModelOne, createModelTwo }; jobsApiClient .TryCreateJobs(Arg.Is <IEnumerable <JobCreateModel> >(_ => _.SequenceEqual(createModels))) .Returns(new ApiResponse <IEnumerable <JobCreateResult> >(HttpStatusCode.OK, new[] { expectedCreateResultOne, expectedCreateResultTwo })); JobManagement jobManagement = new JobManagement(jobsApiClient, logger, policies, messengerService); //Act IEnumerable <JobCreateResult> actualResult = await jobManagement.TryQueueJobs(createModels); actualResult .Should() .BeEquivalentTo <JobCreateResult>(new [] { expectedCreateResultOne, expectedCreateResultTwo }); }
public async Task <IEnumerable <JobCreateResult> > TryQueueJobs(IEnumerable <JobCreateModel> jobCreateModels) { ApiResponse <IEnumerable <JobCreateResult> > apiResponse = await _jobsApiClientPolicy.ExecuteAsync(() => _jobsApiClient.TryCreateJobs(jobCreateModels)); if (apiResponse?.Content == null) { string message = "Failed to create jobs."; _logger.Error(message); throw new JobsNotCreatedException(message, jobCreateModels.Select(_ => _.JobDefinitionId).Distinct()); } return(apiResponse.Content); }