Skip to content

Commit

Permalink
Add test cases also for C#
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Apr 11, 2022
1 parent 4c64f75 commit bd51ce7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public class SymbolReferenceAnalyzerTest
public void Verify_Method_PreciseLocation_CS(ProjectType projectType) =>
Verify("Method.cs", projectType, references =>
{
references.Select(x => x.Declaration.StartLine).Should().BeEquivalentTo(1, 3, 5); // class 'Sample' on line 1, method 'Method' on line 3, method 'Go' on line 5
references.Select(x => x.Declaration.StartLine).Should().BeEquivalentTo(1, 3, 5, 7); // class 'Sample' on line 1, method 'Method' on line 3, method 'method' on line 5 and method 'Go' on line 7
var methodDeclaration = references.Single(x => x.Declaration.StartLine == 3);
methodDeclaration.Declaration.Should().BeEquivalentTo(new TextRange { StartLine = 3, EndLine = 3, StartOffset = 16, EndOffset = 22 });
methodDeclaration.Reference.Should().HaveCount(1);
methodDeclaration.Reference.Single().Should().BeEquivalentTo(new TextRange { StartLine = 6, EndLine = 6, StartOffset = 8, EndOffset = 14 });
methodDeclaration.Reference.Single().Should().BeEquivalentTo(new TextRange { StartLine = 9, EndLine = 9, StartOffset = 8, EndOffset = 14 });
});

[DataTestMethod]
Expand All @@ -65,7 +65,7 @@ public void Verify_Method_PreciseLocation_VB(ProjectType projectType) =>
procedureDeclaration.Declaration.Should().BeEquivalentTo(new TextRange { StartLine = 3, EndLine = 3, StartOffset = 15, EndOffset = 21 });
procedureDeclaration.Reference.Should().HaveCount(2);
procedureDeclaration.Reference[0].Should().BeEquivalentTo(new TextRange { StartLine = 11, EndLine = 11, StartOffset = 8, EndOffset = 14 });
procedureDeclaration.Reference[1].Should().BeEquivalentTo(new TextRange { StartLine = 11, EndLine = 11, StartOffset = 8, EndOffset = 14 });
procedureDeclaration.Reference[1].Should().BeEquivalentTo(new TextRange { StartLine = 13, EndLine = 13, StartOffset = 8, EndOffset = 14 });

var functionDeclaration = references.Single(x => x.Declaration.StartLine == 6);
functionDeclaration.Declaration.Should().BeEquivalentTo(new TextRange { StartLine = 6, EndLine = 6, StartOffset = 13, EndOffset = 23 });
Expand Down Expand Up @@ -125,7 +125,7 @@ public void Verify_LocalFunction_CS(ProjectType projectType) =>
[DataRow(ProjectType.Product)]
[DataRow(ProjectType.Test)]
public void Verify_Method_CS(ProjectType projectType) =>
Verify("Method.cs", projectType, 3, 3, 6);
Verify("Method.cs", projectType, 4, 3, 9);

[DataTestMethod]
[DataRow(ProjectType.Product)]
Expand Down Expand Up @@ -155,7 +155,7 @@ public void Verify_Parameter_VB(ProjectType projectType) =>
[DataRow(ProjectType.Product)]
[DataRow(ProjectType.Test)]
public void Verify_Property_CS(ProjectType projectType) =>
Verify("Property.cs", projectType, 4, 3, 7, 8);
Verify("Property.cs", projectType, 5, 3, 9, 10);

[DataTestMethod]
[DataRow(ProjectType.Product)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
public void Method() { }

public void Go() =>
public void method() { }

public void Go()
{
Method();
method();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
{
public int Property { get; set; }

public int property { get; set; }

public void Go()
{
var x = Property;
Property = 42;
property = 24;
}
}

0 comments on commit bd51ce7

Please sign in to comment.