private void ProcessAnalyzer(DiagnosticAnalyzer analyzer, SqaleModel root)
        {
            foreach (DiagnosticDescriptor diagnostic in analyzer.SupportedDiagnostics)
            {
                SqaleDescriptor sqaleDescriptor = new SqaleDescriptor
                {
                    Remediation = new SqaleRemediation
                    {
                        RuleKey = diagnostic.Id
                    },
                    SubCharacteristic = "MAINTAINABILITY_COMPLIANCE"
                };

                sqaleDescriptor.Remediation.Properties.AddRange(new[]
                {
                    new SqaleRemediationProperty
                    {
                        Key  = "remediationFunction",
                        Text = "CONSTANT_ISSUE"
                    },
                    new SqaleRemediationProperty
                    {
                        Key   = "offset",
                        Value = this.remediationConstantValue,
                        Text  = string.Empty
                    }
                });

                root.Sqale.Add(sqaleDescriptor);
            }
        }
Exemplo n.º 2
0
        public void Generate_ValidSqaleFileSpecified_TemplateFileNotCreated()
        {
            // Arrange
            string outputDir = TestUtils.CreateTestDirectory(this.TestContext, ".out");

            RemoteRepoBuilder       remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext);
            AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder);

            CreatePackageInFakeRemoteRepo(remoteRepoBuilder, "dummy.id", "1.1");

            // Create a dummy sqale file
            string     dummySqaleFilePath = Path.Combine(outputDir, "inputSqale.xml");
            SqaleModel dummySqale         = new SqaleModel();

            Serializer.SaveModel(dummySqale, dummySqaleFilePath);

            ProcessedArgs args = CreateArgs("dummy.id", "1.1", "cs", dummySqaleFilePath, false, false, outputDir);

            // Act
            bool result = apg.Generate(args);

            // Assert
            Assert.IsTrue(result, "Expecting generation to have succeeded");
            AssertSqaleTemplateDoesNotExist(outputDir);
        }
        /// <summary>
        /// Generates a SQALE file with fixed remediation costs for the specified analyzers
        /// </summary>
        private void GenerateFixedSqaleFile(IEnumerable <DiagnosticAnalyzer> analyzers, string outputFilePath)
        {
            this.logger.LogInfo(UIResources.APG_GeneratingConstantSqaleFile);

            HardcodedConstantSqaleGenerator generator = new HardcodedConstantSqaleGenerator();

            SqaleModel sqale = generator.GenerateSqaleData(analyzers, DefaultRemediationCost);

            Serializer.SaveModel(sqale, outputFilePath);
            this.logger.LogDebug(UIResources.APG_SqaleGeneratedToFile, outputFilePath);
        }
        public SqaleModel GenerateSqaleData(IEnumerable <DiagnosticAnalyzer> analyzers, string remediationValue)
        {
            if (analyzers == null)
            {
                throw new ArgumentNullException("analyzers");
            }

            Debug.Assert(remediationValue.EndsWith("min"), "Expecting a remediation value in the form '15min'");
            this.remediationConstantValue = remediationValue;

            SqaleModel root = new SqaleModel();

            foreach (DiagnosticAnalyzer analyzer in analyzers)
            {
                ProcessAnalyzer(analyzer, root);
            }

            return(root);
        }