public bool TestGenerics <T>(T repository, LoggedCall call) where T : class
        {
            var t          = repository.GetType();
            var targetType = typeof(T);

            var recorder = Mimic.Record(repository);

            var method = targetType.GetMethod(call.MethodName, call.Parameters.Select(p => Type.GetType(p.ParameterExpectedType)).ToArray());

            try
            {
                method.Invoke(recorder, call.Parameters.Select(arg => arg.Value).ToArray());
            }
            catch (TargetException e)
            {
                throw new ObjectIsNotOfExpectedTypeException(t, targetType);
            }
            catch (TargetInvocationException e)
            {
                // this is already logged by proxy recorder
            }

            var callReturnValue = call.ReturnValue;
            var recordedCall    = Mimic.GetHistory(recorder).Calls[0];

            var isEqual = (recordedCall.ThrownExceptionType == null && String.IsNullOrWhiteSpace(call.ThrownExceptionType)) &&
                          comparer.Equals(recordedCall.ReturnValue, callReturnValue)
                          ||
                          (!String.IsNullOrWhiteSpace(call.ThrownExceptionType) &&
                           recordedCall.ThrownExceptionType == call.ThrownExceptionType);

            VerificationLog.Add(new BehaviourLogItem()
            {
                Pass       = isEqual,
                Call       = call,
                ActualCall = recordedCall
            });

            return(isEqual);
        }
示例#2
0
 internal static bool Equals(LoggedCall a, LoggedCall b)
 {
     return(a.MethodName == b.MethodName && IsMatchingParams(a.Parameters, b.Parameters));
 }