示例#1
0
        public void CheckPasswordTest(string content0, string content1)
        {
            string testCode = string.Format(GetTemplate(), content0, content1);
            var    expected = DiagnosticResultHelper.CreateArray(DiagnosticIds.AvoidPasswordField);

            VerifyCSharpDiagnostic(testCode, expected);
        }
示例#2
0
        public void DereferenceNullAsExpressionFindingTest(string content1, string content2)
        {
            string testCode = string.Format(GetTemplate(), content1, content2);
            var    expected = DiagnosticResultHelper.CreateArray(DiagnosticIds.DereferenceNull);

            VerifyCSharpDiagnostic(testCode, expected);
        }
示例#3
0
        public void DereferenceNullAsExpressionWithNestedExpression()
        {
            string testCode = @"
class Foo 
{{
  public void Scan(MethodDefinition method, MethodData data)
		{

Instruction i = method.Body.Instructions[0];
			
				switch (i.OpCode.Code)
				{
					case Code.Call:
					case Code.Calli:
					case Code.Callvirt:
						MethodReference mr = i.Operand as MethodReference;

						MethodDefinition md = mr.Resolve();

						Scan(md, _locks[md]);


						break;
					default:
						break;
				}
			
		}
}}
";
            var    expected = DiagnosticResultHelper.CreateArray(DiagnosticIds.DereferenceNull);

            VerifyCSharpDiagnostic(testCode, expected);
        }
        public void TestMethodsMustReturnVoid(bool isAsync, string returnType, bool isError)
        {
            string code = $@"using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class Tests
{{
	[TestMethod]
	public {(isAsync ? "async" : string.Empty)} {returnType} Foo() {{ throw new Exception(); }}
}}";

            VerifyCSharpDiagnostic(code, isError ? DiagnosticResultHelper.CreateArray(DiagnosticIds.TestMethodsMustHaveValidReturnType) : Array.Empty <DiagnosticResult>());
        }
        public void TestMethodsMustNotHaveDataRows(string arg, bool isError)
        {
            const string code = @"using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class Tests
{{
	{0}
	[TestMethod]
	public void Foo() {{ }}
}}";

            DiagnosticResult[] expected = Array.Empty <DiagnosticResult>();
            if (isError)
            {
                expected = DiagnosticResultHelper.CreateArray(DiagnosticIds.DataTestMethodsHaveDataRows);
            }

            VerifyCSharpDiagnostic(string.Format(code, arg), expected);
        }
示例#6
0
        public void DereferenceNullAsExpressionWhileCheckDereferenceTest()
        {
            string testCode = @"
class Foo 
{{
  public void Foo()
  {{
    string x = String.Empty;
    object obj = x;
    string y = obj as string;
    while (y.ToString().Contains(""x""))
    {{
       string t0 = y.ToString();
    }}
  }}
}}
";
            var    expected = DiagnosticResultHelper.CreateArray(DiagnosticIds.DereferenceNull);

            VerifyCSharpDiagnostic(testCode, expected);
        }