Exemple #1
0
        public async Task Should_RetrieveAnalysis_When_NewAnalysisAdded()
        {
            var guid = Guid.NewGuid();

            var newAnalysis = new DiffAnalysis()
            {
                Id = guid
            };

            _analysisRepo.Add(newAnalysis);
            await _analysisRepo.SaveAll();

            var analysis = await _analysisRepo.GetAnalysis(guid);

            Assert.IsNotNull(analysis);
        }
 /// <summary>
 /// Add a diff analysis to the DB context
 /// </summary>
 /// <param name="analysis">The diff analysis to be added</param>
 public void Add(DiffAnalysis analysis)
 {
     _context.DiffAnalysis.Add(analysis);
 }
Exemple #3
0
        private async Task HandleIngestionInput(AddDiffInputMessage input)
        {
            _logger.LogInformation($"Processing Input: {input.Id}");

            using (var scope = _scopeFactory.CreateScope())
            {
                var analysisRepo = scope.ServiceProvider.GetRequiredService <IDiffAnalysisRepository>();
                //var mapper = scope.ServiceProvider.GetRequiredService<IMapper>();

                var analysis = await analysisRepo.GetAnalysis(input.Id);

                var persistChanges = false;

                //If analysis doesnt exists in the DB
                if (analysis == null)
                {
                    _logger.LogInformation($"Analysis Not Found: {input.Id}");

                    analysis = new DiffAnalysis()
                    {
                        Id = input.Id
                    };
                    analysisRepo.Add(analysis);
                    persistChanges = true;
                }

                // if analysis already analyzed we discard the input
                if (analysis.Analyzed)
                {
                    _logger.LogInformation($"Analysis already analyzed: {input.Id}. Discarding...");
                    return;
                }

                // If input is left argument and doesnt already exist
                if (input.IsLeft && analysis.Left == null)
                {
                    _logger.LogInformation($"Persisting Left Argument: {input.Id}");

                    analysis.Left  = input.Input;
                    persistChanges = true;
                }

                // If input is right argument and doesnt already exist
                if (!input.IsLeft && analysis.Right == null)
                {
                    _logger.LogInformation($"Persisting Right Argument: {input.Id}");

                    analysis.Right = input.Input;
                    persistChanges = true;
                }

                if (persistChanges)
                {
                    await analysisRepo.SaveAll();
                }

                // if we have both left and right arguments we publish a perform Diff Analysis message
                if (analysis.Left != null && analysis.Right != null)
                {
                    _logger.LogInformation($"Analysis ready to be analyzed: {input.Id}. Publishing PerformDiffAnalysisMessage to bus.");

                    var message = new PerformDiffAnalysisMessage(analysis.Id);
                    await _serviceBus.PublishAsync(message);
                }
            }
        }