Browse Source

Use method element helper in CodeCoverageMethod.

pull/17/merge
Matt Ward 13 years ago
parent
commit
6ebf4233a6
  1. 40
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethod.cs
  2. 13
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageProperty.cs
  3. 8
      src/AddIns/Analysis/CodeCoverage/Test/Coverage/CodeCoverageResultsPropertyFlagsTestFixture.cs
  4. 2
      src/AddIns/Analysis/CodeCoverage/Test/Coverage/CodeCoverageResultsTestFixture.cs

40
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethod.cs

@ -16,7 +16,6 @@ namespace ICSharpCode.CodeCoverage @@ -16,7 +16,6 @@ namespace ICSharpCode.CodeCoverage
string className = String.Empty;
string fullClassName = String.Empty;
string classNamespace = String.Empty;
int methodBodySize;
MethodAttributes methodAttributes;
List<CodeCoverageSequencePoint> sequencePoints = new List<CodeCoverageSequencePoint>();
@ -41,39 +40,14 @@ namespace ICSharpCode.CodeCoverage @@ -41,39 +40,14 @@ namespace ICSharpCode.CodeCoverage
}
public CodeCoverageMethod(string className, XElement reader)
: this(GetMethodName(reader), className, GetMethodAttributes(reader))
: this(className, new CodeCoverageMethodElement(reader))
{
ReadMethodBodySize(reader);
XAttribute isGetter = reader.Attribute("isGetter");
XAttribute isSetter = reader.Attribute("isSetter");
if (isGetter != null && isSetter != null && IsPropertyMethodName()) {
try {
IsProperty = Convert.ToBoolean(isGetter.Value) || Convert.ToBoolean(isSetter.Value);
} catch (FormatException) {
IsProperty = false;
}
}
else {
IsProperty = false;
}
}
static string GetMethodName(XElement reader)
{
return reader.Element("Name").Value;
}
static MethodAttributes GetMethodAttributes(XElement reader)
public CodeCoverageMethod(string className, CodeCoverageMethodElement element)
: this(element.MethodName, className, MethodAttributes.Public)
{
return MethodAttributes.Public;
}
void ReadMethodBodySize(XElement reader)
{
//string bodySizeAsString = reader.GetAttribute("bodysize");
//if (bodySizeAsString != null) {
// methodBodySize = Int32.Parse(bodySizeAsString);
//}
IsProperty = element.IsProperty && IsPropertyMethodName();
}
/// <summary>
@ -88,7 +62,7 @@ namespace ICSharpCode.CodeCoverage @@ -88,7 +62,7 @@ namespace ICSharpCode.CodeCoverage
bool IsPropertyMethodName()
{
return name.Contains("::get_") || name.Contains("::set_");
return name.Contains("get_") || name.Contains("set_");
}
public string Name {
@ -164,10 +138,6 @@ namespace ICSharpCode.CodeCoverage @@ -164,10 +138,6 @@ namespace ICSharpCode.CodeCoverage
public int GetUnvisitedCodeLength()
{
if (sequencePoints.Count == 0) {
return methodBodySize;
}
int total = 0;
foreach (CodeCoverageSequencePoint sequencePoint in sequencePoints) {
if (sequencePoint.VisitCount == 0) {

13
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageProperty.cs

@ -67,26 +67,19 @@ namespace ICSharpCode.CodeCoverage @@ -67,26 +67,19 @@ namespace ICSharpCode.CodeCoverage
public static string GetPropertyName(CodeCoverageMethod method)
{
if (IsGetter(method) || IsSetter(method)) {
return GetMethodName(method).Substring(6);
return method.Name.Substring(4);
}
return String.Empty;
}
static string GetMethodName(CodeCoverageMethod method)
{
int startIndex = method.Name.IndexOf("::");
int endIndex = method.Name.IndexOf('(', startIndex);
return method.Name.Substring(startIndex, endIndex - startIndex);
}
public static bool IsGetter(CodeCoverageMethod method)
{
return method.Name.Contains("::get_");
return method.Name.Contains("get_");
}
public static bool IsSetter(CodeCoverageMethod method)
{
return method.Name.Contains("::set_");
return method.Name.Contains("set_");
}
}
}

8
src/AddIns/Analysis/CodeCoverage/Test/Coverage/CodeCoverageResultsPropertyFlagsTestFixture.cs

@ -95,7 +95,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage @@ -95,7 +95,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage
public void MethodName_GetterMethod_ReturnsExpectedGetterName()
{
string name = GetterMethod.Name;
string expectedName = "System.Int32 MyTests.MyClass1::get_Count())";
string expectedName = "get_Count";
Assert.AreEqual(expectedName, name);
}
@ -114,7 +114,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage @@ -114,7 +114,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage
public void MethodName_NameOfMethodWithPropertyFlagsButInvalidName_ReturnsMethodName()
{
string name = MethodWithPropertyFlagsButInvalidName.Name;
string expectedName = "System.Void MyTests.Tests.MyClass::PropertyFlagsButJustAMethod()";
string expectedName = "PropertyFlagsButJustAMethod";
Assert.AreEqual(expectedName, name);
}
@ -126,7 +126,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage @@ -126,7 +126,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage
public void MethodName_SetterMethod_ReturnsSetterMethodName()
{
string name = SetterMethod.Name;
string expectedName = "System.Void MyTests.MyClass1::set_Count(System.Int32)";
string expectedName = "set_Count";
Assert.AreEqual(expectedName, name);
}
@ -145,7 +145,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage @@ -145,7 +145,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage
public void MethodName_OrdinaryMethod_ReturnsMethodName()
{
string name = OrdinaryMethod.Name;
string expectedName = "System.Void MyTests.MyClass1::get_NotAProperty())";
string expectedName = "get_NotAProperty";
Assert.AreEqual(expectedName, name);
}

2
src/AddIns/Analysis/CodeCoverage/Test/Coverage/CodeCoverageResultsTestFixture.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage @@ -73,7 +73,7 @@ namespace ICSharpCode.CodeCoverage.Tests.Coverage
public void MethodName_ModuleHasOneMethod_ReturnsExpectedMethodName()
{
string name = FirstModuleFirstMethod.Name;
string expectedName = "System.Void Foo.Tests.FooTestFixture::SimpleTest()";
string expectedName = "SimpleTest";
Assert.AreEqual(expectedName, name);
}

Loading…
Cancel
Save