Skip to content

Commit

Permalink
Method and Ctor Parameters - Ce
Browse files Browse the repository at this point in the history
  • Loading branch information
ElemarJR committed May 1, 2012
1 parent 4393d6e commit 0b08c89
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/FluentCodeMetrics.Core/CeExtensions.cs
Expand Up @@ -32,7 +32,17 @@ public static int ComputeCe(this Type that)
where method.ReturnType != typeof(void)
select method.ReturnType;

var methodParameterTypes = from method in that.GetMethods(flags)
from parameter in method.GetParameters()
select parameter.ParameterType;

var ctorParameterTypes = from ctor in that.GetConstructors(flags)
from parameter in ctor.GetParameters()
select parameter.ParameterType;

return new[] { that.BaseType }
.Union(ctorParameterTypes)
.Union(methodParameterTypes)
.Union(fieldTypes)
.Union(propertyTypes)
.Union(methodReturnTypes)
Expand Down
6 changes: 3 additions & 3 deletions src/FluentCodeMetrics.Specs/EfferentCoupling.feature
Expand Up @@ -21,10 +21,10 @@ Funcionalidade: Calcular Acoplamento Eferente (Ce)
Exemplos:
| tipo | ce |
| Samples.EmptyClass | 5 |
| Samples.OneArgCtor | 6 |
| Samples.OneArgVoidMethod | 6 |
| Samples.SingleArgCtor | 6 |
| Samples.SingleArgVoidMethod | 6 |
| Samples.FeeMethod | 6 |
| Samples.DateTimeArgDateTimeMethod | 7 |
| Samples.DateTimeArgDateTimeMethod | 6 |
| Samples.SingleProperty | 6 |
| Samples.SingleField | 6 |
| Samples.OneException | 6 |
Expand Down
6 changes: 3 additions & 3 deletions src/FluentCodeMetrics.Specs/EfferentCoupling.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/FluentCodeMetrics.Specs/Samples.cs
Expand Up @@ -13,15 +13,15 @@ public class EmptyClass
{
}

class OneArgCtor
public class SingleArgCtor
{
// ReSharper disable UnusedParameter.Local
public OneArgCtor(Fee arg)
public SingleArgCtor(Fee arg)
// ReSharper restore UnusedParameter.Local
{}
}

class SingleArgVoidMethod
public class SingleArgVoidMethod
{
public void Foo(Fee arg)
{}
Expand Down
28 changes: 28 additions & 0 deletions src/FluentCodeMetrics.Tests/CeExtensionsTests.cs
Expand Up @@ -64,6 +64,34 @@ public void GetReferencedTypes_FeeMethod()
typeof(Type)
);
}

[Test]
public void GetReferencedTypes_SingleArgVoidMethod()
{
typeof(SingleArgVoidMethod).GetReferencedTypes()
.Should().Have.SameSequenceAs(
typeof(object),
typeof(Fee), // argument type
typeof(string),
typeof(bool),
typeof(int),
typeof(Type)
);
}

[Test]
public void GetReferencedTypes_SingleArgCtor()
{
typeof(SingleArgCtor).GetReferencedTypes()
.Should().Have.SameSequenceAs(
typeof(object),
typeof(Fee), // argument type
typeof(string),
typeof(bool),
typeof(int),
typeof(Type)
);
}
}
// ReSharper restore InconsistentNaming
}

0 comments on commit 0b08c89

Please sign in to comment.