I am working on updating our project from .Net 2 to .Net4.5, at the same time I click as many links as I can on NuGet and making sure that the versions are current.
I had a problem getting one of the tests to run
Test classes:
public class Person { public static int PersonBaseMethodHitCount { get; set; } public virtual void BaseMethod() { PersonBaseMethodHitCount = PersonBaseMethodHitCount + 1; } public static int PersonSomeMethodToBeOverriddenHitCount { get; set; } public virtual void SomeMethodToBeOverridden() { PersonSomeMethodToBeOverriddenHitCount = PersonSomeMethodToBeOverriddenHitCount + 1; } } public class Employee : Person { public static int EmployeeSomeMethodToBeOverriddenHitCount { get; set; } public override void SomeMethodToBeOverridden() { EmployeeSomeMethodToBeOverriddenHitCount = EmployeeSomeMethodToBeOverriddenHitCount + 1; } public static int EmployeeCannotInterceptHitCount { get; set; } public void CannotIntercept() { EmployeeCannotInterceptHitCount = EmployeeCannotInterceptHitCount + 1; } public virtual void MethodWithParameter( [SuppressMessage("a", "b"), InheritedAttribute, Noninherited]string foo) { } } public class MyInterceptor : IInterceptor { public static int HitCount { get; set; } public void Intercept(IInvocation invocation) { HitCount = HitCount + 1; invocation.Proceed(); } }
Test (there are no settings for this device):
var container = new WindsorContainer(); container.Register(Component.For<MyInterceptor>().ImplementedBy<MyInterceptor>()); container.Register( Component .For<Employee>() .ImplementedBy<Employee>() .Interceptors(InterceptorReference.ForType<MyInterceptor>()) .SelectedWith(new DerivedClassMethodsInterceptorSelector()).Anywhere); container.Register(Classes.FromAssembly(Assembly.GetExecutingAssembly()).Pick().WithService.FirstInterface()); var employee = container.Resolve<Employee>(); Person.PersonBaseMethodHitCount = 0; Person.PersonSomeMethodToBeOverriddenHitCount = 0; Employee.EmployeeCannotInterceptHitCount = 0; Employee.EmployeeSomeMethodToBeOverriddenHitCount = 0; MyInterceptor.HitCount = 0; employee.BaseMethod(); Assert.That(Person.PersonBaseMethodHitCount, Is.EqualTo(1));
I added a comment to indicate where the test fails.
As far as I can tell, the problem occurs in DerivedClassMethodsInterceptorSelector
Selection:
public class DerivedClassMethodsInterceptorSelector : IInterceptorSelector { public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { return method.DeclaringType != type ? new IInterceptor[0] : interceptors; } }
When it does type comparisons, the type variable is System.RuntimeType, but should be Employee (at least that's my understanding).
EDIT: This problem occurred when using Castle.Windsor and Castle.Core 3.2.1. After NuGet has installed the 3.1.0 package, the code works as expected.
I am inclined to think that this is a mistake, but I could just change the logic.