public override async Task Process(Message message)
        {
            string specificationId = message.UserProperties["specificationId"].ToString();

            SpecificationProviders specificationProviders = message.GetPayloadAsInstanceOf <SpecificationProviders>();

            IEnumerable <ProviderResult> providerResults = await _resultsRepositoryPolicy
                                                           .ExecuteAsync(() => _resultsRepository.GetProviderResultsBySpecificationIdAndProviders(specificationProviders.Providers, specificationId)
                                                                         );

            if (providerResults.Any())
            {
                _logger.Information($"Removing {specificationProviders.Providers.Count()} from calculation results for specification {specificationId}");

                await _resultsRepositoryPolicy
                .ExecuteAsync(() => _resultsRepository.DeleteCurrentProviderResults(providerResults)
                              );

                SearchResults <ProviderCalculationResultsIndex> indexItems = await _resultsSearchRepositoryPolicy
                                                                             .ExecuteAsync(() => _calculationProviderResultsSearchRepository.Search(string.Empty,
                                                                                                                                                    new SearchParameters
                {
                    Top        = providerResults.Count(),
                    SearchMode = SearchMode.Any,
                    Filter     = $"specificationId eq '{specificationId}' and (" + string.Join(" or ", providerResults.Select(m => $"providerId eq '{m.Provider.Id}'")) + ")",
                    QueryType  = QueryType.Full
                }
                                                                                                                                                    )
                                                                                           );

                await _resultsSearchRepositoryPolicy.ExecuteAsync(() => _calculationProviderResultsSearchRepository.Remove(indexItems?.Results.Select(m => m.Result)));
            }
        }
        public async Task CleanupTestResultsForSpecificationProviders(Message message)
        {
            string specificationId = message.UserProperties["specificationId"].ToString();

            SpecificationProviders specificationProviders = message.GetPayloadAsInstanceOf <SpecificationProviders>();

            IEnumerable <TestScenarioResult> testScenarioResults = await _testResultsPolicy
                                                                   .ExecuteAsync(() => _testResultsRepository.GetCurrentTestResults(specificationProviders.Providers, specificationId)
                                                                                 );

            if (testScenarioResults.Any())
            {
                _logger.Information($"Removing {specificationProviders.Providers.Count()} from test results for specification {specificationId}");

                await _testResultsPolicy.ExecuteAsync(() =>
                                                      _testResultsRepository.DeleteCurrentTestScenarioTestResults(testScenarioResults));

                SearchResults <TestScenarioResultIndex> indexItems = await _testResultsSearchPolicy
                                                                     .ExecuteAsync(() => _searchRepository.Search(string.Empty,
                                                                                                                  new SearchParameters
                {
                    Top        = testScenarioResults.Count(),
                    SearchMode = SearchMode.Any,
                    Filter     = $"specificationId eq '{specificationId}' and (" + string.Join(" or ", testScenarioResults.Select(m => $"providerId eq '{m.Provider.Id}'")) + ")",
                    QueryType  = QueryType.Full
                }
                                                                                                                  )
                                                                                   );

                await _testResultsSearchPolicy.ExecuteAsync(() => _searchRepository.Remove(indexItems?.Results.Select(m => m.Result)));
            }
        }
Exemple #3
0
        private async Task SendProviderSourceDatasetCleanupMessageToTopic(string specificationId, string topicName, IEnumerable <ProviderSourceDataset> providers)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));
            Guard.ArgumentNotNull(providers, nameof(providers));

            SpecificationProviders specificationProviders = new SpecificationProviders {
                SpecificationId = specificationId, Providers = providers.Select(x => x.ProviderId)
            };

            Dictionary <string, string> properties = new Dictionary <string, string>
            {
                { "specificationId", specificationId },
                { "sfa-correlationId", Guid.NewGuid().ToString() }
            };

            await _messengerService.SendToTopic(topicName, specificationProviders, properties, true);
        }
Exemple #4
0
        public async Task CleanupTestResultsForSpecificationProviders_GivenCurrentTestResults_ThenCallsDelete()
        {
            //Arrange
            TestScenarioResult testScenarioResult = CreateTestScenarioResult();

            ITestResultsRepository testResultsRepository = CreateTestResultsRepository();

            testResultsRepository
            .GetCurrentTestResults(Arg.Any <IEnumerable <string> >(), Arg.Is <string>(testScenarioResult.Specification.Id))
            .Returns(new TestScenarioResult[] { testScenarioResult });

            TestResultsService service = CreateTestResultsService(testResultsRepository: testResultsRepository);

            SpecificationProviders specificationProviders = new SpecificationProviders {
                SpecificationId = testScenarioResult.Specification.Id, Providers = new string[] { testScenarioResult.Provider.Id }
            };

            Dictionary <string, string> properties = new Dictionary <string, string>
            {
                { "specificationId", testScenarioResult.Specification.Id },
                { "sfa-correlationId", Guid.NewGuid().ToString() }
            };

            Message message = new Message {
                Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(specificationProviders))
            };

            message.UserProperties["specificationId"] = testScenarioResult.Specification.Id;

            //Act
            await service.CleanupTestResultsForSpecificationProviders(message);

            //Assert
            await testResultsRepository
            .Received(1)
            .DeleteCurrentTestScenarioTestResults(Arg.Is <IEnumerable <TestScenarioResult> >(x => x.First().Provider.Id == testScenarioResult.Provider.Id));
        }