Exemple #1
0
        private void Verify(MemberInvocation memberInvocation)
        {
            var verified           = false;
            var candidateVerifiers = this.MemberInvocations.Where(v => v.Name == memberInvocation.Name && v.Parameters.Length == memberInvocation.Parameters.Length);

            foreach (var candidate in candidateVerifiers)
            {
                var allPropertiesAreEqual = true;
                for (var i = 0; i < candidate.Parameters.Length; i++)
                {
                    if (candidate.Parameters[i] != memberInvocation.Parameters[i])
                    {
                        allPropertiesAreEqual = false;
                        break;
                    }
                }

                if (allPropertiesAreEqual)
                {
                    verified = true;
                    break;
                }
            }

            Assert.True(verified, "Verifying '" + memberInvocation.Name + "' invocation");
        }
Exemple #2
0
        protected override bool OnInvokeMember <TResult>(MemberInvocation invocation, out TResult result)
        {
            var baseResult        = base.OnInvokeMember <TResult>(invocation, out result);
            var candidateHandlers = this.memberInvocationHandlers.Where(h => h.MethodName == invocation.Name && h.ParametersTypes.Length == invocation.Parameters.Length).Reverse();

            if (candidateHandlers.Any())
            {
                foreach (var candidate in candidateHandlers)
                {
                    var isOk = true;
                    for (var i = 0; i < invocation.Parameters.Length; i++)
                    {
                        if (!candidate.ParametersTypes[i].IsAssignableFrom(invocation.Parameters[i].GetType()))
                        {
                            isOk = false;
                            break;
                        }
                    }

                    if (isOk)
                    {
                        candidate.Execute(invocation.Parameters);
                        result = (TResult)candidate.Result;
                        return(true);
                    }
                }
            }

            return(baseResult);
        }
Exemple #3
0
        private bool TryInvokeGetProperty <TResult>(string propertyName, out TResult result)
        {
            var memberInvocation = new MemberInvocation {
                Name = FormatPropertyGetName(propertyName), Parameters = new object[0], IsGetter = true
            };

            return(this.TryInvokeMember(memberInvocation, out result));
        }
Exemple #4
0
        private bool TryInvokeMember <TResult>(string methodName, object[] args, out Task <TResult> result)
        {
            var memberInvocation = new MemberInvocation {
                Name = methodName, Parameters = args, IsMethod = true
            };

            return(this.TryInvokeMember(memberInvocation, out result));
        }
Exemple #5
0
        internal void CalledWith(int counter, string methodName, params object[] args)
        {
            var memberInvocation = new MemberInvocation {
                Name = methodName, Parameters = args, IsMethod = true
            };

            Assert.True(counter == this.memberInvocations.Count(m => memberInvocation.Equals(m)), "Checking '" + methodName + "' has been called " + counter + " times with parameters");
        }
Exemple #6
0
        internal void CalledWith(string methodName, params object[] args)
        {
            var memberInvocation = new MemberInvocation {
                Name = methodName, Parameters = args, IsMethod = true
            };

            Assert.True(this.memberInvocations.Any(m => memberInvocation.Equals(m)), "Checking '" + methodName + "' has been called with parameters");
        }
Exemple #7
0
        private bool TryInvokeSetProperty(string propertyName, object arg)
        {
            var memberInvocation = new MemberInvocation {
                Name = FormatPropertySetName(propertyName), Parameters = new object[] { arg }, IsSetter = true
            };
            bool result;

            return(this.TryInvokeMember(memberInvocation, out result));
        }
Exemple #8
0
        protected override bool OnInvokeMember <TResult>(MemberInvocation invocation, out Task <TResult> result)
        {
            var isOk = this.OnInvokeMember <Task <TResult> >(invocation, out result);

            if (result == null)
            {
                result = Task.FromResult(default(TResult));
            }

            return(isOk);
        }
Exemple #9
0
        private bool TryInvokeMember <TResult>(MemberInvocation memberInvocation, out Task <TResult> result)
        {
            var done = false;

            result = default(Task <TResult>);
            try
            {
                done = this.OnInvokeMember(memberInvocation, out result);
                if (done)
                {
                    this.memberInvocations.Add(memberInvocation);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Error invoking '{0}': {1}", memberInvocation.ToString(), ex.Message));
            }

            return(done);
        }
Exemple #10
0
 private void AddVerification(MemberInvocation memberInvocation)
 {
     this.memberInvocationVerifiers.Add(memberInvocation);
 }
Exemple #11
0
 protected virtual bool OnInvokeMember <TResult>(MemberInvocation invocation, out Task <TResult> result)
 {
     result = Task.FromResult(default(TResult));
     return(true);
 }
Exemple #12
0
 protected virtual bool OnInvokeMember <TResult>(MemberInvocation invocation, out TResult result)
 {
     result = default(TResult);
     return(true);
 }