Exemplo n.º 1
0
        /// <summary>
        /// Метод расширения для <see cref="Moq"/>, который отключает проверку параметров для Callback-функций (вариант с возвращаемым значением).
        /// </summary>
        /// <param name="mock">
        /// <see cref="Moq"/>, для которого нужно отключить проверку параметров.
        /// </param>
        /// <returns>
        /// Для поддержки цепочечных вызовов, возвращаем <paramref name="mock"/>.
        /// </returns>
        public static IThrowsResult IgnoreRefMatching(this IThrowsResult mock)
        {
            try
            {
                FieldInfo matcherField = typeof(Mock).GetTypeInfo().Assembly.GetType("Moq.MethodCall").GetField("argumentMatchers", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance);

                IList     argumentMatchers = (IList)matcherField.GetValue(mock);
                Type      refMatcherType   = typeof(Mock).GetTypeInfo().Assembly.GetType("Moq.Matchers.RefMatcher");
                FieldInfo equalField       = refMatcherType.GetField("equals", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance);

                foreach (object matcher in argumentMatchers)
                {
                    if (matcher.GetType() == refMatcherType)
                    {
                        equalField.SetValue(matcher, new Func <object, bool>(o => true));
                    }
                }

                return(mock);
            }
            catch (NullReferenceException)
            {
                return(mock);
            }
        }
Exemplo n.º 2
0
 public MoqThrowsResultWrapper(
     LambdaExpression expression, 
     IThrowsResult throwsResult, 
     IVerifiedMock testeroidsMock)
 {
     this.Expression = expression;
     this.wrappedThrowsResult = throwsResult;
     this.TesteroidsMock = testeroidsMock;
 }
Exemplo n.º 3
0
 public MoqThrowsResultWrapper(
     LambdaExpression expression,
     IThrowsResult throwsResult,
     IVerifiedMock testeroidsMock)
 {
     this.Expression          = expression;
     this.wrappedThrowsResult = throwsResult;
     this.TesteroidsMock      = testeroidsMock;
 }
Exemplo n.º 4
0
 public IThrowsResult WrapThrowsForVerification(IThrowsResult wrap)
 {
     return(new VerifiableThrowsResult(wrap, this));
 }