private static IEnumerable<MethodCommandTypeTuple> GetSelfHandlerMethods(Type type, 
            Type[] commandTypes, MethodParameterInjector injector)
        {
            if (!commandTypes.Contains(type)) yield break;

            var methods = type.GetMethods().Where(m => m.GetCustomAttribute<CommandHandlerAttribute>() != null);
            var enumerator = methods.GetEnumerator();
            try
            {
                if (!enumerator.MoveNext())
                    yield break;
                else
                {
                    var method = enumerator.Current;
                    if (method.GetParameters().Any(p => !injector.CanSupply(p.ParameterType)))
                        throw new CommandHandlerMethodHasUnsupportedParameter(type, method);

                    yield return new MethodCommandTypeTuple { Method = method, CommandType = type, HandlerType = type};
                }

                if (enumerator.MoveNext())
                    throw new CommandsMayOnlyDeclareOneHandlerMethod(type);
            }
            finally
            {
                enumerator.Dispose();
            }
        }
 private static bool IsValidCommandHandler(Type commandType, MethodInfo method, ParameterInfo[] parameters, MethodParameterInjector injector)
 {
     if (method.DeclaringType != null && method.DeclaringType.GetProperties().Any(p => IsPropertyAccessor(method, p)))
         return false;
     return parameters.Any(p => p.ParameterType == commandType)
            && parameters.All(p => p.ParameterType == commandType || injector.CanSupply(p.ParameterType));
 }
 public void CanSupplyReturnsTrueForTypesWithSpecifiedInstances()
 {
     var injector = new MethodParameterInjector(new object[]{"string", 5}, new [] {new KeyValuePair<Type, object>(typeof(ITestInterface), new TestImpl()) });
     Assert.That(injector.CanSupply(typeof(ITestInterface)), Is.True);
 }
 public void CanSupplyReturnsTrueForTypeThatCanBeProvided()
 {
     var injector = new MethodParameterInjector(new object[]{"string", 5, this});
     Assert.That(injector.CanSupply(GetType()), Is.True);
 }
 public void CanSupplyReturnsFalseForTypeThatCannotBeProvided()
 {
     var injector = new MethodParameterInjector(new object[]{"string", 5});
     Assert.That(injector.CanSupply(GetType()), Is.False);
 }