public void InterfacePropertiesWithSetters_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA1100InterfacePropertiesShouldBeRead_OnlyAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, String.Format(Resources.AA1100InterfacePropertiesShouldBeReadOnlyMessageFormat, "Property2", "IContainsSetters"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(9, 26, 29))); var expected2 = new DiagnosticResult(commonExpected, String.Format(Resources.AA1100InterfacePropertiesShouldBeReadOnlyMessageFormat, "Property3", "IContainsSetters"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(11, 30, 33))); var expected3 = new DiagnosticResult(commonExpected, String.Format(Resources.AA1100InterfacePropertiesShouldBeReadOnlyMessageFormat, "Property4", "IContainsSetters"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(12, 26, 29))); DiagnosticVerifier.VerifyDiagnostics<AA1100InterfacePropertiesShouldBeRead_OnlyAnalyzer>( @"..\..\CodeUnderTest\CodeToTestInterfacePropertySetters.cs", expected1, expected2, expected3); }
public void ThrowingNotSupported_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA2001DoNotUseNotSupportedExceptionAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2001DoNotUseNotSupportedExceptionMessageFormat), Option<DiagnosticLocation>.Some(new DiagnosticLocation(47, 23, 44))); var expected2 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2001DoNotUseNotSupportedExceptionMessageFormat), Option<DiagnosticLocation>.Some(new DiagnosticLocation(52, 19, 22))); var expected3 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2001DoNotUseNotSupportedExceptionMessageFormat), Option<DiagnosticLocation>.Some(new DiagnosticLocation(58, 19, 21))); var expected4 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2001DoNotUseNotSupportedExceptionMessageFormat), Option<DiagnosticLocation>.Some(new DiagnosticLocation(63, 19, 26))); DiagnosticVerifier.VerifyDiagnostics<AA2001DoNotUseNotSupportedExceptionAnalyzer>( @"..\..\CodeUnderTest\CodeToTestLSPViolatingExceptions.cs", expected1, expected2, expected3, expected4); }
public void MethodsWithRefOrOutParams_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA2104FileMustOnlyContainOneTypeDefinitionAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2104FileMustOnlyContainOneTypeDefinitionMessageFormat, "Class1"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(3, 18, 24))); var expected2 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2104FileMustOnlyContainOneTypeDefinitionMessageFormat, "Struct2"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(11, 21, 28))); var expected3 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2104FileMustOnlyContainOneTypeDefinitionMessageFormat, "Interface3"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(19, 22, 32))); var expected4 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2104FileMustOnlyContainOneTypeDefinitionMessageFormat, "Enum3"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(21, 19, 24))); DiagnosticVerifier.VerifyDiagnostics<AA2104FileMustOnlyContainOneTypeDefinitionAnalyzer>( TestFiles.CodeToTestFileMustOnlyContainOneTypeDefinition, expected1, expected2, expected3, expected4); }
public void NonPrivateInnerTypes_YieldDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA1102InnerTypesMustBePrivateAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, String.Format(Resources.AA1102InnerTypesMustBePrivateMessageFormat, "Interface1"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(7, 28, 38))); var expected2 = new DiagnosticResult(commonExpected, String.Format(Resources.AA1102InnerTypesMustBePrivateMessageFormat, "Enum1"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(8, 21, 26))); var expected3 = new DiagnosticResult(commonExpected, String.Format(Resources.AA1102InnerTypesMustBePrivateMessageFormat, "Class2"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(9, 22, 28))); DiagnosticVerifier.VerifyDiagnostics<AA1102InnerTypesMustBePrivateAnalyzer>( @"..\..\CodeUnderTest\CodeToTestInnerTypesMustBePrivate.cs", expected1, expected2, expected3); }
public void BasicReassignmentsWithIncorrectlyIngoredVariables_YieldsDiagnostics() { var analyzer = new AA1301VariablesShouldBeAssignedOnceOnlyAnalyzer(); var analyzerCommonExpected = new DiagnosticResultCommonProperties(analyzer); var analyzerSuppressionCommonExpected = new DiagnosticResultCommonProperties(analyzer.GetNamedItemSuppresionAttributeDetails()[0]); var expected1 = new DiagnosticResult(analyzerSuppressionCommonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlySuppresionMisuseMessageFormat, "y"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(11, 26, 29))); var expected2 = new DiagnosticResult(analyzerSuppressionCommonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlySuppresionMisuseMessageFormat, "z"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(11, 31, 34))); var expected3 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(16, 13, 18))); var expected4 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(17, 13, 19))); var expected5 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "x"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(21, 17, 24))); var expected6 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(23, 17, 31))); DiagnosticVerifier.VerifyDiagnostics<AA1301VariablesShouldBeAssignedOnceOnlyAnalyzer>( @"..\..\CodeUnderTest\CodeToTestVariableReassignment.cs", expected1, expected2, expected3, expected4, expected5, expected6); }
public void TwoStaticMethodsWithNoParamsOneWithAttribute_YieldsOneDiagnostic() { var commonExpected = new DiagnosticResultCommonProperties(new AA1001StaticMethodsShouldHaveAtLeastOneParameterAnalyzer()); var expected = new DiagnosticResult(commonExpected, String.Format(Resources.AA1001StaticMethodsShouldHaveAtLeastOneParameterMessageFormat, "ReturnTrue"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(8, 28, 38))); DiagnosticVerifier.VerifyDiagnostics<AA1001StaticMethodsShouldHaveAtLeastOneParameterAnalyzer>( TestFiles.CodeToTestAtLeastOneParameterAnalyzerRespectsAttributes, expected); }
public void BasicReassignmentsWithIncorrectlyIngoredParameters_YieldsDiagnostics() { var analyzer = new AA1300ParametersShouldNotBeModifiedAnalyzer(); var analyzerCommonExpected = new DiagnosticResultCommonProperties(analyzer); var analyzerSuppressionCommonExpected = new DiagnosticResultCommonProperties(analyzer.GetNamedItemSuppresionAttributeDetails()[0]); var expected1 = new DiagnosticResult(analyzerSuppressionCommonExpected, Format(Resources.AA1300ParametersShouldNotBeModifiedSuppresionMisuseMessageFormat, "y"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(10, 27, 30))); var expected2 = new DiagnosticResult(analyzerSuppressionCommonExpected, Format(Resources.AA1300ParametersShouldNotBeModifiedSuppresionMisuseMessageFormat, "z"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(10, 32, 35))); var expected3 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1300ParametersShouldNotBeModifiedMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(13, 13, 18))); var expected4 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1300ParametersShouldNotBeModifiedMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(14, 13, 19))); var expected5 = new DiagnosticResult(analyzerCommonExpected, Format(Resources.AA1300ParametersShouldNotBeModifiedMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(20, 17, 31))); DiagnosticVerifier.VerifyDiagnostics<AA1300ParametersShouldNotBeModifiedAnalyzer>( @"..\..\CodeUnderTest\CodeToTestParameterReassignment.cs", expected1, expected2, expected3, expected4, expected5); }
public void CodeWithFourVoidMethodsTwoWithIgnoreRuleAttributes_YieldsTwoDiagnostic() { var commonExpected = new DiagnosticResultCommonProperties(new AA1000StaticMethodsShouldNotBeVoidAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1000StaticMethodsShouldNotBeVoidMessageFormat, "DoNothing1"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(8, 28, 38))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1000StaticMethodsShouldNotBeVoidMessageFormat, "DoNothing4"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(17, 28, 38))); DiagnosticVerifier.VerifyDiagnostics<AA1000StaticMethodsShouldNotBeVoidAnalyzer>( TestFiles.CodeToTestStaticVoidAnalyzerRespectsAttributes, expected1, expected2); }
public void CodeWithTwoVoidMethods_YieldsTwoDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA1000StaticMethodsShouldNotBeVoidAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1000StaticMethodsShouldNotBeVoidMessageFormat, "DoNothing"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(5, 28, 37))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1000StaticMethodsShouldNotBeVoidMessageFormat, "StillDoNothing"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(8, 28, 42))); DiagnosticVerifier.VerifyDiagnostics<AA1000StaticMethodsShouldNotBeVoidAnalyzer>( TestFiles.CodeToTestStaticVoidAnalyzer, expected1, expected2); }
public void InterfacePropertiesWithSetters_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA1200AvoidUsingStaticFieldsAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1200AvoidUsingStaticFieldsMessageFormat, "A2", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(8, 27, 29))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1200AvoidUsingStaticFieldsMessageFormat, "B2", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(12, 28, 30))); var expected3 = new DiagnosticResult(commonExpected, Format(Resources.AA1200AvoidUsingStaticFieldsMessageFormat, "C2", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(16, 29, 31))); var expected4 = new DiagnosticResult(commonExpected, Format(Resources.AA1200AvoidUsingStaticFieldsMessageFormat, "D2", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(20, 30, 32))); DiagnosticVerifier.VerifyDiagnostics<AA1200AvoidUsingStaticFieldsAnalyzer>( @"..\..\CodeUnderTest\CodeToTestAvoidUsingStaticFieldsAndProperties.cs", expected1, expected2, expected3, expected4); }
public void InterfacePropertiesWithSetters_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA1201AvoidUsingStaticPropertiesAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1201AvoidUsingStaticPropertiesMessageFormat, "PropA1", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(33, 27, 33))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1201AvoidUsingStaticPropertiesMessageFormat, "PropB1", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(34, 29, 35))); var expected3 = new DiagnosticResult(commonExpected, Format(Resources.AA1201AvoidUsingStaticPropertiesMessageFormat, "PropC1", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(35, 28, 34))); var expected4 = new DiagnosticResult(commonExpected, Format(Resources.AA1201AvoidUsingStaticPropertiesMessageFormat, "PropD1", "CodeToTestAvoidUsingStaticFieldsAndProperties"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(36, 30, 36))); DiagnosticVerifier.VerifyDiagnostics<AA1201AvoidUsingStaticPropertiesAnalyzer>( @"..\..\CodeUnderTest\CodeToTestAvoidUsingStaticFieldsAndProperties.cs", expected1, expected2, expected3, expected4); }
public void ClassPropertiesWithSetters_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA1101ClassPropertiesShouldBePubliclyRead_OnlyAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1101ClassPropertiesShouldBePubliclyReadOnlyMessageFormat, "Property2", "ContainsSetters"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(10, 38, 41))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1101ClassPropertiesShouldBePubliclyReadOnlyMessageFormat, "Property7", "ContainsSetters"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(20, 13, 16))); DiagnosticVerifier.VerifyDiagnostics<AA1101ClassPropertiesShouldBePubliclyRead_OnlyAnalyzer>( @"..\..\CodeUnderTest\CodeToTestClassPropertySetters.cs", expected1, expected2); }
public void MethodsWithAnd_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA2103MethodShouldNotContainAndAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA2103MethodShouldNotContainAndMessageFormat, "DoSomethingAndSomethingElse"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(7, 28, 55))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA2103MethodShouldNotContainAndMessageFormat, "DoSomethingAndSomethingElse"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(14, 28, 55))); var expected3 = new DiagnosticResult(commonExpected, Format(Resources.AA2103MethodShouldNotContainAndMessageFormat, "AThingAndAnotherThing"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(16, 21, 42))); var expected4 = new DiagnosticResult(commonExpected, Format(Resources.AA2103MethodShouldNotContainAndMessageFormat, "AndAndAnd"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(20, 25, 34))); var expected5 = new DiagnosticResult(commonExpected, Format(Resources.AA2103MethodShouldNotContainAndMessageFormat, "AThingAndAnotherThing"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(27, 14, 35))); DiagnosticVerifier.VerifyDiagnostics<AA2103MethodShouldNotContainAndAnalyzer>( TestFiles.CodeToTestMethodsWithAnd, expected1, expected2, expected3, expected4, expected5); }
public void MethodsWithRefOrOutParams_YieldsDiagnostics() { var commonExpected = new DiagnosticResultCommonProperties(new AA2100MethodParametersMustNotBeRefOrOutAnalyzer()); var expected1 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2100MethodParametersMustNotBeRefOrOutMessageFormat, "p", "UsesRefParameter", "ref"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(11, 45, 54))); var expected2 = new DiagnosticResult(commonExpected, String.Format(Resources.AA2100MethodParametersMustNotBeRefOrOutMessageFormat, "p", "UsesOutParameter", "out"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(17, 45, 54))); DiagnosticVerifier.VerifyDiagnostics<AA2100MethodParametersMustNotBeRefOrOutAnalyzer>( TestFiles.CodeToTestDetectingOutAndRefParameters, expected1, expected2); }
public void NonSimpleIntReassignments_YieldsDiagnostics() { var analyzer = new AA1301VariablesShouldBeAssignedOnceOnlyAnalyzer(); var commonExpected = new DiagnosticResultCommonProperties(analyzer); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(12, 13, 19))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(13, 13, 19))); var expected3 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(14, 13, 19))); var expected4 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(15, 13, 19))); var expected5 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(16, 13, 19))); var expected6 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(17, 13, 20))); var expected7 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(18, 13, 20))); var expected8 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(19, 13, 16))); var expected9 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(20, 13, 16))); var expected10 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(21, 13, 16))); var expected11 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "a"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(22, 13, 16))); DiagnosticVerifier.VerifyDiagnostics<AA1301VariablesShouldBeAssignedOnceOnlyAnalyzer>( @"..\..\CodeUnderTest\CodeToTestNonSimpleIntVariableReassignments.cs", expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9, expected10, expected11); }
public void BooleanReassignments_YieldsDiagnostics() { var analyzer = new AA1301VariablesShouldBeAssignedOnceOnlyAnalyzer(); var commonExpected = new DiagnosticResultCommonProperties(analyzer); var expected1 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(11, 13, 22))); var expected2 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(12, 13, 23))); var expected3 = new DiagnosticResult(commonExpected, Format(Resources.AA1301VariablesShouldBeAssignedOnceOnlyMessageFormat, "b"), Option<DiagnosticLocation>.Some(new DiagnosticLocation(13, 13, 23))); DiagnosticVerifier.VerifyDiagnostics<AA1301VariablesShouldBeAssignedOnceOnlyAnalyzer>( @"..\..\CodeUnderTest\CodeToTestBooleanVariableReassignments.cs", expected1, expected2, expected3); }