public static void AnalyzeShouldReturnAllAnalysisIssues() { const string relativeSolutionPath = @"..\.."; var projectPath = Path.GetFullPath(relativeSolutionPath); if (projectPath == null) { throw new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, "Unable to retrieve project directory off relative path: {0}", relativeSolutionPath)); } var styleCop = new CodeAnalyzer(projectPath); var violations = styleCop.Analyze(Path.Combine(Directory.GetCurrentDirectory(), @"Resources\TestClass.cs")).ToList(); Assert.That( violations[0].Message, Is.EqualTo("An opening curly bracket must not be followed by a blank line.")); Assert.That(violations[0].RuleId, Is.EqualTo("SA1505")); Assert.That( violations[1].Message, Is.EqualTo("A closing curly bracket must not be preceded by a blank line.")); Assert.That(violations[1].RuleId, Is.EqualTo("SA1508")); Assert.That( violations[2].Message, Is.EqualTo("Statements or elements wrapped in curly brackets must be followed by a blank line.")); Assert.That(violations[2].RuleId, Is.EqualTo("SA1513")); Assert.That( violations[3].Message, Is.EqualTo("All using directives must be placed inside of the namespace.")); Assert.That(violations[3].RuleId, Is.EqualTo("SA1200")); Assert.That( violations[4].Message, Is.EqualTo("All using directives must be placed inside of the namespace.")); Assert.That(violations[4].RuleId, Is.EqualTo("SA1200")); Assert.That( violations[5].Message, Is.EqualTo("All using directives must be placed inside of the namespace.")); Assert.That(violations[5].RuleId, Is.EqualTo("SA1200")); Assert.That( violations[6].Message, Is.EqualTo("All using directives must be placed inside of the namespace.")); Assert.That(violations[6].RuleId, Is.EqualTo("SA1200")); Assert.That( violations[7].Message, Is.EqualTo("All using directives must be placed inside of the namespace.")); Assert.That(violations[7].RuleId, Is.EqualTo("SA1200")); Assert.That( violations[8].Message, Is.EqualTo( "The comment must start with a single space. To ignore this error when commenting out a line of code, begin the comment with '////' rather than '//'.")); Assert.That(violations[8].RuleId, Is.EqualTo("SA1005")); }
public async Task ResultJsonCheckTest() { var codeAnalyzer = new CodeAnalyzer(); var result = await codeAnalyzer.Analyze(sourceFile, CancellationToken.None); // check json parsing var expectedResult = File.ReadLines("Resources/Astar.json").First(); Assert.True(result.ToString() == expectedResult, "Wrong json format"); }
public async Task ComplexityMathTest() { var codeAnalyzer = new CodeAnalyzer(); var result = await codeAnalyzer.Analyze(sourceFile, CancellationToken.None); Assert.True(result.LineComplexities.ToArray().Length == result.NrMethods, "Line complexity doesn't match"); Assert.True(result.Complexity == result.LineComplexities.Max(x => x.Value), "Complexity is not calculated correctly"); }
public async Task ResultCheckTest() { var codeAnalyzer = new CodeAnalyzer(); var result = await codeAnalyzer.Analyze(sourceFile, CancellationToken.None); // check if every field is correct Assert.Equal(sourceFile, result.Filename); Assert.Equal(131, result.Loc); Assert.Equal(4, result.Cloc); Assert.Equal(8, result.NrMethods); Assert.Equal(2, result.NrClasses); Assert.Equal(10, result.Complexity); }