public async Task QueueCsvGenerationMessages_GivenSpecificationSummariesFoundAndHasNewResults_CreatesNewMessage() { //Arrange IEnumerable <SpecificationSummary> specificationSummaries = new[] { new SpecificationSummary { Id = "spec-1" } }; ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); specificationsRepository .GetSpecificationSummaries() .Returns(specificationSummaries); ICalculationResultsRepository calculationResultsRepository = CreateResultsRepository(); calculationResultsRepository .CheckHasNewResultsForSpecificationIdAndTimePeriod( Arg.Is("spec-1"), Arg.Any <DateTimeOffset>(), Arg.Any <DateTimeOffset>()) .Returns(true); ILogger logger = CreateLogger(); IMessengerService messengerService = CreateMessengerService(); ResultsService resultsService = CreateResultsService( logger, specificationsRepository: specificationsRepository, resultsRepository: calculationResultsRepository, messengerService: messengerService); //Act await resultsService.QueueCsvGenerationMessages(); //Assert await messengerService .Received(1) .SendToQueue( Arg.Is(ServiceBusConstants.QueueNames.CalculationResultsCsvGeneration), Arg.Is(string.Empty), Arg.Is <Dictionary <string, string> >(m => m["specification-id"] == "spec-1"), Arg.Is(false)); logger .Received() .Information($"Found new calculation results for specification id 'spec-1'"); }
public async Task QueueCsvGenerationMessage(string specificationId) { bool hasNewResults = await _resultsRepositoryPolicy.ExecuteAsync( () => _resultsRepository.CheckHasNewResultsForSpecificationIdAndTimePeriod(specificationId, DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(1))); if (hasNewResults) { _logger.Information($"Found new calculation results for specification id '{specificationId}'"); await _messengerService.SendToQueue(ServiceBusConstants.QueueNames.CalculationResultsCsvGeneration, string.Empty, new Dictionary <string, string> { { "specification-id", specificationId } }); } }