public async Task WhenConstructorCallsVirtualMethodThenReturnsError(string code) { var references = new[] { MetadataReference.CreateFromFile(typeof(IAvailability).Assembly.Location) }; var solution = CreateSolution(references, code); var results = await _inspector.Inspect(solution); CollectionAssert.IsNotEmpty(results); }
public static async Task<IEnumerable<EvaluationResult>> PerformInspection(string code, Type evaluatorType) { var inspector = new NodeReviewer(new[] { (ICodeEvaluation)Activator.CreateInstance(evaluatorType) }, Enumerable.Empty<ISymbolEvaluation>()); var tree = CSharpSyntaxTree.ParseText("namespace TestSpace { public class ParseClass { " + code + " } }", CSharpParseOptions.Default, string.Empty, Encoding.Unicode, CancellationToken.None); return await inspector.Inspect(string.Empty, string.Empty, tree.GetRoot(), null, null); }
public async Task WhenLockingOnWeakIdentityObjectThenReturnsFinding(string code) { var solution = CreateSolution(code); var finding = await _inspector.Inspect(solution); Assert.NotEmpty(finding); }
public static async Task <IEnumerable <EvaluationResult> > PerformInspection(string code, Type evaluatorType) { var inspector = new NodeReviewer(new[] { (ICodeEvaluation)Activator.CreateInstance(evaluatorType) }, Enumerable.Empty <ISymbolEvaluation>()); var tree = CSharpSyntaxTree.ParseText("namespace TestSpace { public class ParseClass { " + code + " } }"); return(await inspector.Inspect(string.Empty, string.Empty, tree.GetRoot(), null, null)); }
public async Task WhenClassContainsEmptyFinalizerThenReturnsError(string code) { var solution = CreateSolution(code); var results = await _inspector.Inspect(solution); Assert.NotEmpty(results); }
public async Task WhenMethodContainsHiddenDependencyThenReturnsError(string code) { var references = new[] { MetadataReference.CreateFromFile(typeof(IAvailability).Assembly.Location) }; var solution = CreateSolution(references, code); var results = await _inspector.Inspect(solution); Assert.NotEmpty(results); }
public static Task<IEnumerable<EvaluationResult>> PerformSolutionInspection(string code, Type evaluatorType) { var inspector = new NodeReviewer(new[] { (ICodeEvaluation)Activator.CreateInstance(evaluatorType) }, Enumerable.Empty<ISymbolEvaluation>()); code = "namespace TestSpace { public class ParseClass { " + code + " } }"; var solution = CreateSolution(code); var task = inspector.Inspect(solution); return task; }
public static Task <IEnumerable <EvaluationResult> > PerformSolutionInspection(string code, Type evaluatorType) { var inspector = new NodeReviewer(new[] { (ICodeEvaluation)Activator.CreateInstance(evaluatorType) }, Enumerable.Empty <ISymbolEvaluation>()); code = "namespace TestSpace { public class ParseClass { " + code + " } }"; var solution = CreateSolution(code); var task = inspector.Inspect(solution); return(task); }
public async Task WhenInspectingCommentsThenDetectsSuspiciousLanguage(string comment) { var method = CSharpSyntaxTree.ParseText( $@"public void SomeMethod() {{ {comment} }}"); var root = method.GetRoot(); var task = await _reviewer.Inspect(string.Empty, string.Empty, root, null, null); Assert.NotEmpty(task); }
private async Task <int> PerformReview() { using (var workspace = MSBuildWorkspace.Create()) { var path = @"..\..\..\archimetrics.sln".GetLowerCaseFullPath(); var solution = await workspace.OpenSolutionAsync(path).ConfigureAwait(false); var results = await _reviewer.Inspect(solution).ConfigureAwait(false); var amount = results.AsArray(); return(amount.Length); } }
public async Task WhenTypeIsDeclaredOutsideNamespaceThenReturnsError() { const string Code = @"public class MyClass { public string Value { get; set; } }"; var solution = CreateSolution(Code); var results = await _inspector.Inspect(solution); CollectionAssert.IsNotEmpty(results); }
public async Task WhenEvaluatingCodeThenCallsCodeEvaluation() { var classDeclaration = SyntaxFactory.ClassDeclaration( SyntaxFactory.List <AttributeListSyntax>(), SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)), SyntaxFactory.Identifier("MyClass"), SyntaxFactory.TypeParameterList(), SyntaxFactory.BaseList(), SyntaxFactory.List <TypeParameterConstraintClauseSyntax>(), SyntaxFactory.List <MemberDeclarationSyntax>()); await _reviewer.Inspect("name", string.Empty, classDeclaration, null, null).ConfigureAwait(false); _mockCodeEvaluation.Verify(x => x.Evaluate(classDeclaration)); }
public async Task WhenClassContainsEmptyFinalizerThenReturnsError(string code) { var references = new[] { MetadataReference.CreateFromAssembly(typeof(IAvailability).Assembly), MetadataReference.CreateFromAssembly(typeof(object).Assembly), MetadataReference.CreateFromAssembly(typeof(Debug).Assembly) }; var solution = CreateSolution(references, code); var results = await _inspector.Inspect(solution); CollectionAssert.IsNotEmpty(results); }
public async Task WhenExceptionsAreDefinedThenHandlesCommentsInAutoGeneratedCode() { var tree = CSharpSyntaxTree.ParseText(@"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace CodeConvertServiceClient.Properties { using System; /// <summary> /// A strongly-typed resource class, for looking up localized strings, etc. /// </summary> // This class was auto-generated by the StronglyTypedResourceBuilder // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""System.Resources.Tools.StronglyTypedResourceBuilder"", ""4.0.0.0"")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(""Microsoft.Performance"", ""CA1811:AvoidUncalledPrivateCode"")] internal Resources() { } } } "); var root = tree.GetRoot(); var result = await _inspector.Inspect(string.Empty, string.Empty, root, null, null); CollectionAssert.IsEmpty(result, "This comment should not violate the comment rule."); }