コード例 #1
0
        protected override Expression VisitNew(NewExpression node)
        {
            _structureService.VerifyType(node.Type, TypeVerifiers);
            _structureService.VerifyMember(
                node.Constructor,
                MemberVerifiers,
                MemberVerificationAspect.MemberType,
                MemberVerificationAspect.ConstructorAccessLevel);

            MemberInfo memberInfo = _structureService.TranslateMember(node.Constructor);

            return(Expression.New((ConstructorInfo)memberInfo, node.Arguments.Select(Visit)));
        }
コード例 #2
0
        public void VerifyMemberOverloadUsesSubsetOfAllTypeVerifiers()
        {
            PropertyInfo propertyToVerify = typeof(string).GetProperty("Length");

            IMemberVerifier verifier1 = Substitute.For <IMemberVerifier>();

            verifier1.Aspects.Returns(new[] { MemberVerificationAspect.PropertyType });
            IMemberVerifier verifier2 = Substitute.For <IMemberVerifier>();

            verifier2.Aspects.Returns(new[] { MemberVerificationAspect.PropertyIsStatic });
            IStructureService service = Substitute.For <IStructureService>();

            service.VerifyMember(propertyToVerify, new[] { verifier1, verifier2 }, MemberVerificationAspect.PropertyType);

            service.Received().VerifyMember(propertyToVerify, new[] { verifier1 });
        }
コード例 #3
0
        // Only uses a subset of the verifiers (keeps order)
        public static void VerifyMember(this IStructureService service, MemberInfo original, IMemberVerifier[] verifiers, params MemberVerificationAspect[] aspects)
        {
            List <IMemberVerifier> verifierSubset = new List <IMemberVerifier>();

            foreach (var aspect in aspects)
            {
                IEnumerable <IMemberVerifier> verifiersWithAspect = verifiers.Where(v => v.Aspects.Contains(aspect));

                // Each verifier is only added once as dublicates could potentially hurt performance,
                // because verifiers use reflection (which is slow) when verifying
                foreach (var verifier in verifiersWithAspect)
                {
                    if (!verifierSubset.Contains(verifier))
                    {
                        verifierSubset.Add(verifier);
                    }
                }
            }

            service.VerifyMember(original, verifierSubset.ToArray());
        }
コード例 #4
0
 public void AssertMember(MemberInfo memberInfo, params IMemberVerifier[] verifiers)
 {
     _executeAction += () => _structureService.VerifyMember(memberInfo, verifiers);
 }