public void TestClassShouldHaveTestMethod_NUnit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestClassShouldHaveTestMethod.NUnit.cs", new TestClassShouldHaveTestMethod(), null, AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion)); }
public void ExpectedExceptionAttributeShouldNotBeUsed_MsTest(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\ExpectedExceptionAttributeShouldNotBeUsed.MsTest.cs", new ExpectedExceptionAttributeShouldNotBeUsed(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", testFwkVersion)); }
public void Controller_Methods_Are_EntryPoints(string aspNetMvcVersion) { const string code = @" public class Foo : System.Web.Mvc.Controller { public void PublicFoo() { } } public class Controller { public void PublicBar() { } } public class MyController : Controller { public void PublicDiz() { } } "; var compilation = TestHelper.Compile(code, references: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", aspNetMvcVersion)); var publicFoo = compilation.GetMethodSymbol("PublicFoo"); var publicBar = compilation.GetMethodSymbol("PublicBar"); var publicDiz = compilation.GetMethodSymbol("PublicDiz"); TaintAnalysisEntryPointDetector.IsEntryPoint(publicFoo).Should().Be(true); TaintAnalysisEntryPointDetector.IsEntryPoint(publicBar).Should().Be(false); TaintAnalysisEntryPointDetector.IsEntryPoint(publicDiz).Should().Be(false); }
public void TestClassShouldHaveTestMethod_MSTest(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestClassShouldHaveTestMethod.MsTest.cs", new TestClassShouldHaveTestMethod(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", testFwkVersion)); }
public void AssertionArgsShouldBePassedInCorrectOrder_MsTest(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\AssertionArgsShouldBePassedInCorrectOrder.MsTest.cs", new AssertionArgsShouldBePassedInCorrectOrder(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", testFwkVersion)); }
public void DoNotUseLiteralBoolInAssertions_NUnit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\DoNotUseLiteralBoolInAssertions.NUnit.cs", new DoNotUseLiteralBoolInAssertions(), null, AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion)); }
public void Public_Controller_Methods_Are_EntryPoints(string aspNetMvcVersion) { const string code = @" public class Foo : System.Web.Mvc.Controller { public void PublicFoo() { } protected void ProtectedFoo() { } internal void InternalFoo() { } private void PrivateFoo() { } private class Bar : System.Web.Mvb.Controller { public void InnerFoo() { } } } "; var compilation = TestHelper.Compile(code, references: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", aspNetMvcVersion)); var publicFoo = compilation.GetMethodSymbol("PublicFoo"); var protectedFoo = compilation.GetMethodSymbol("ProtectedFoo"); var internalFoo = compilation.GetMethodSymbol("InternalFoo"); var privateFoo = compilation.GetMethodSymbol("PrivateFoo"); var innerFoo = compilation.GetMethodSymbol("InnerFoo"); TaintAnalysisEntryPointDetector.IsEntryPoint(publicFoo).Should().Be(true); TaintAnalysisEntryPointDetector.IsEntryPoint(protectedFoo).Should().Be(false); TaintAnalysisEntryPointDetector.IsEntryPoint(internalFoo).Should().Be(false); TaintAnalysisEntryPointDetector.IsEntryPoint(privateFoo).Should().Be(false); TaintAnalysisEntryPointDetector.IsEntryPoint(innerFoo).Should().Be(false); }
public void DoNotUseLiteralBoolInAssertions_MsTest(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\DoNotUseLiteralBoolInAssertions.MsTest.cs", new DoNotUseLiteralBoolInAssertions(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", testFwkVersion)); }
public void MethodShouldBeNameAccordingToSynchronicity(string tasksVersion) { Verifier.VerifyAnalyzer(@"TestCases\MethodShouldBeNameAccordingToSynchronicity.cs", new MethodShouldBeNameAccordingToSynchronicity(), null, AssemblyReference.FromNuGet("System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Extensions", tasksVersion)); }
public void ExpectedExceptionAttributeShouldNotBeUsed_NUnit_NoIssue(string testFwkVersion) { Verifier.VerifyNoIssueReported(@"TestCases\ExpectedExceptionAttributeShouldNotBeUsed.NUnit.cs", new ExpectedExceptionAttributeShouldNotBeUsed(), null, AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion)); }
public void AssertionArgsShouldBePassedInCorrectOrder_NUnit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\AssertionArgsShouldBePassedInCorrectOrder.NUnit.cs", new AssertionArgsShouldBePassedInCorrectOrder(), null, AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion)); }
public void TestMethodShouldHaveCorrectSignature_Xunit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldHaveCorrectSignature.Xunit.cs", new TestMethodShouldHaveCorrectSignature(), null, AssemblyReference.FromNuGet("xunit.assert.dll", "xunit.assert", testFwkVersion), AssemblyReference.FromNuGet("xunit.core.dll", "xunit.extensibility.core", testFwkVersion)); }
public void TestMethodShouldNotBeIgnored_NUnit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldNotBeIgnored.NUnit.cs", new TestMethodShouldNotBeIgnored(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", "1.1.11"), AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion)); }
public void DoNotUseLiteralBoolInAssertions_Xunit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\DoNotUseLiteralBoolInAssertions.Xunit.cs", new DoNotUseLiteralBoolInAssertions(), null, AssemblyReference.FromNuGet("xunit.assert.dll", "xunit.assert", testFwkVersion), AssemblyReference.FromNuGet("xunit.core.dll", "xunit.extensibility.core", testFwkVersion)); }
public static UCFG GetUcfgForMethod(string code, string methodName) { (var method, var semanticModel) = TestHelper.Compile(code, references: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", "3.0.20105.1")) .GetMethod(methodName); return(BuildUcfg(method.Body, method, semanticModel.GetDeclaredSymbol(method), semanticModel)); }
public void AssertionArgsShouldBePassedInCorrectOrder_XUnit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\AssertionArgsShouldBePassedInCorrectOrder.Xunit.cs", new AssertionArgsShouldBePassedInCorrectOrder(), null, AssemblyReference.FromNuGet("xunit.assert.dll", "xunit.assert", testFwkVersion), AssemblyReference.FromNuGet("xunit.core.dll", "xunit.extensibility.core", testFwkVersion)); }
public void MethodShouldBeNameAccordingToSynchronicity_NUnit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\MethodShouldBeNameAccordingToSynchronicity.NUnit.cs", new MethodShouldBeNameAccordingToSynchronicity(), null, AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion), AssemblyReference.FromNuGet("System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Extensions", "4.0.0")); }
public void MethodShouldBeNameAccordingToSynchronicity_MsTest(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\MethodShouldBeNameAccordingToSynchronicity.MsTest.cs", new MethodShouldBeNameAccordingToSynchronicity(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", testFwkVersion), AssemblyReference.FromNuGet("System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Extensions", "4.0.0")); }
public void MethodShouldBeNameAccordingToSynchronicity_Xunit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\MethodShouldBeNameAccordingToSynchronicity.Xunit.cs", new MethodShouldBeNameAccordingToSynchronicity(), null, AssemblyReference.FromNuGet("xunit.assert.dll", "xunit.assert", testFwkVersion), AssemblyReference.FromNuGet("xunit.core.dll", "xunit.extensibility.core", testFwkVersion), AssemblyReference.FromNuGet("System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Extensions", "4.0.0")); }
public void TestMethodShouldNotBeIgnored_Xunit(string testFwkVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldNotBeIgnored.Xunit.cs", new TestMethodShouldNotBeIgnored(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", "1.1.11"), AssemblyReference.FromNuGet("xunit.assert.dll", "xunit.assert", testFwkVersion), AssemblyReference.FromNuGet("xunit.core.dll", "xunit.extensibility.core", testFwkVersion)); }
public void TestMethodShouldContainAssertion_NUnit(string testFwkVersion, string fluentVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.NUnit.cs", new TestMethodShouldContainAssertion(), null, AssemblyReference.FromNuGet("nunit.framework.dll", "NUnit", testFwkVersion), AssemblyReference.FromNuGet("FluentAssertions.dll", "FluentAssertions", fluentVersion), AssemblyReference.FromNuGet("FluentAssertions.Core.dll", "FluentAssertions", fluentVersion)); }
public void TestMethodShouldContainAssertion_MSTest(string testFwkVersion, string fluentVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.MsTest.cs", new TestMethodShouldContainAssertion(), null, AssemblyReference.FromNuGet("Microsoft.VisualStudio.TestPlatform.TestFramework.dll", "MSTest.TestFramework", testFwkVersion), AssemblyReference.FromNuGet("FluentAssertions.dll", "FluentAssertions", fluentVersion), AssemblyReference.FromNuGet("FluentAssertions.Core.dll", "FluentAssertions", fluentVersion)); }
public void TestMethodShouldContainAssertion_Xunit(string testFwkVersion, string fluentVersion) { Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.Xunit.cs", new TestMethodShouldContainAssertion(), null, AssemblyReference.FromNuGet("xunit.assert.dll", "xunit.assert", testFwkVersion), AssemblyReference.FromNuGet("xunit.core.dll", "xunit.extensibility.core", testFwkVersion), AssemblyReference.FromNuGet("FluentAssertions.dll", "FluentAssertions", fluentVersion), AssemblyReference.FromNuGet("FluentAssertions.Core.dll", "FluentAssertions", fluentVersion)); }
public static UCFG GetUcfgForPropertyGetter(string code, string propertyName) { (var property, var semanticModel) = TestHelper.Compile(code, references: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", "3.0.20105.1")) .GetProperty(propertyName); var getterSymbol = semanticModel.GetDeclaredSymbol(property).GetMethod; var getterNode = (AccessorDeclarationSyntax)getterSymbol.DeclaringSyntaxReferences.First().GetSyntax(); return(BuildUcfg(getterNode.Body, getterNode, getterSymbol, semanticModel)); }
public static UCFG GetUcfgForConstructor(string code, string ctorName) { var(syntaxTree, semanticModel) = TestHelper.Compile(code, references: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", "3.0.20105.1")); var ctor = syntaxTree.GetRoot() .DescendantNodes() .OfType <ConstructorDeclarationSyntax>() .First(m => m.Identifier.ValueText == ctorName); return(BuildUcfg(ctor.Body, ctor, semanticModel.GetDeclaredSymbol(ctor), semanticModel)); }
public void Methods_In_Classes_With_ControllerAttribute_Are_EntryPoints(string aspNetMvcVersion) { const string code = @" // The Attribute suffix is required because we don't have a reference // to ASP.NET Core and we cannot do type checking in the test project. // We will need to convert this test project to .NET Core to do that. [Microsoft.AspNetCore.Mvc.ControllerAttribute] public class Foo { public void PublicFoo() { } } "; var compilation = TestHelper.Compile(code, references: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", aspNetMvcVersion)); var publicFoo = compilation.GetMethodSymbol("PublicFoo"); TaintAnalysisEntryPointDetector.IsEntryPoint(publicFoo).Should().Be(true); }
public void HttpPostControllerActionShouldValidateInput(string aspNetMvcVersion) { Verifier.VerifyAnalyzer(@"TestCases\HttpPostControllerActionShouldValidateInput.cs", new HttpPostControllerActionShouldValidateInput(), additionalReferences: AssemblyReference.FromNuGet("System.Web.Mvc.dll", "Microsoft.AspNet.Mvc", aspNetMvcVersion)); }
public void PublicMutableFieldsShouldNotBeReadonly() { Verifier.VerifyAnalyzer(@"TestCases\MutableFieldsShouldNotBePublicReadonly.cs", new MutableFieldsShouldNotBePublicReadonly(), additionalReferences: AssemblyReference.FromNuGet("System.Collections.Immutable.dll", "System.Collections.Immutable", "1.3.0")); }