private String GetCallStackFunction(int index)
        {
            StackFrame stackFrame = stackTrace.GetFrame(index);

            if (stackFrame == null)
            {
                return(null);
            }

            return(MethodSignatureTranslator.GetFormalMethodString(stackFrame.GetMethod()));
        }
Example #2
0
        private String GetCallStackFunction(int index)
        {
            StackFrame stackFrame = stackTrace.GetFrame(index);

            if (stackFrame == null)
            {
                return(null);
            }
            MethodBase mb = stackFrame.GetMethod();

            ParameterInfo[] paras       = mb.GetParameters();
            System.String   callingFunc = stackFrame.GetMethod().ToString();

            string signatureBeforeFunName = MethodSignatureTranslator.GetTypeString(mb.DeclaringType);

            System.String[] temps = callingFunc.Split('(');
            if (temps.Length < 2)
            {
                //error handling
            }
            temps = temps[0].Split(' ');
            if (temps.Length < 2)
            {
                //error handling
            }
            temps[0] = temps[1];

            temps[0] = temps[0].Replace('[', '<');
            temps[0] = temps[0].Replace(']', '>');
            temps[0] = temps[0].Insert(0, signatureBeforeFunName + ".");
            temps[0] = temps[0].Insert(temps[0].Length, "(");

            foreach (ParameterInfo p in paras)
            {
                String typeString = MethodSignatureTranslator.GetTypeString(p.ParameterType);

                temps[0] = temps[0].Insert(temps[0].Length, typeString);
                temps[0] = temps[0].Insert(temps[0].Length, ",");
            }
            if (paras != null && paras.Length > 0)
            {
                temps[0] = temps[0].Remove(temps[0].Length - 1);
            }
            temps[0]    = temps[0].Insert(temps[0].Length, ")");
            callingFunc = temps[0];
            return(callingFunc);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of FaultRule class with the specified method, condition and fault.
 /// </summary>
 /// <param name="method">The signature of the method where the fault should be injected.</param>
 /// <param name="condition">The condition that defines when the fault should occur.</param>
 /// <param name="fault">The fault to be injected.</param>
 public FaultRule(MethodBase method, ICondition condition, IFault fault)
     : this(MethodSignatureTranslator.GetCSharpMethodString(method), condition, fault)
 {
     //  Nothing
 }
Example #4
0
        private static bool CheckReturnType(Type returnTypeOfTrappedMethod, Object returnValue, String currentFunction)
        {
            //
            // If the return type is <T> or List<T>, we simply omit it.
            //
            if (returnTypeOfTrappedMethod.IsGenericParameter || returnTypeOfTrappedMethod.ContainsGenericParameters)
            {
                return(true);
            }

            if (returnTypeOfTrappedMethod != typeof(void))
            {
                if (returnValue == null && returnTypeOfTrappedMethod.IsValueType == true)
                {
                    throw new FaultInjectionException(string.Format(CultureInfo.InvariantCulture.NumberFormat, FaultDispatcherMessages.ReturnValueTypeNullError, MethodSignatureTranslator.GetTypeString(returnTypeOfTrappedMethod)));
                }
                else if (returnValue != null &&
                         returnTypeOfTrappedMethod.IsInstanceOfType(returnValue) == false)
                {
                    throw new FaultInjectionException(string.Format(CultureInfo.InvariantCulture.NumberFormat, FaultDispatcherMessages.ReturnTypeMismatchError, MethodSignatureTranslator.GetTypeString(returnTypeOfTrappedMethod), MethodSignatureTranslator.GetTypeString(returnValue.GetType())));
                }
            }
            return(true);
        }
Example #5
0
 /// <summary>
 /// A built-in condition which triggers a fault if the current call stack contains a specified method.
 /// </summary>
 /// <param name="method">A method in the stack below the target method.
 /// </param>
 public static ICondition TriggerIfStackContains(MethodBase method)
 {
     return(new TriggerIfStackContains(MethodSignatureTranslator.GetCSharpMethodString(method)));
 }
Example #6
0
 /// <summary>
 /// A built-in condition which triggers a fault if the faulted method is called by a specified method.</summary>
 /// <param name="caller">The target method's caller.
 /// </param>
 public static ICondition TriggerIfCalledBy(MethodBase caller)
 {
     return(new TriggerIfCalledBy(MethodSignatureTranslator.GetCSharpMethodString(caller)));
 }
Example #7
0
 public static ICondition TriggerOnNthCallBy(int n, MethodBase caller)
 {
     return(new TriggerOnNthCallBy(n, MethodSignatureTranslator.GetCSharpMethodString(caller)));
 }