public void SetUp() { _constructionMock = MockRepository.GenerateStrictMock <IAspectConstruction> (); _methodCopyServiceMock = MockRepository.GenerateStrictMock <IMethodCopyService>(); _initializationExpressionHelper = new InitializationExpressionHelper(_methodCopyServiceMock); }
public Aspect( Type type, AspectScope scope, AspectActivation activation, IAspectConstruction construction, ICrosscutting crosscutting, IEnumerable <Advice> advices, IEnumerable <MemberImport> memberImports, IEnumerable <MemberIntroduction> memberIntroductions) { ArgumentUtility.CheckNotNull("type", type); ArgumentUtility.CheckNotNull("construction", construction); ArgumentUtility.CheckNotNull("crosscutting", crosscutting); ArgumentUtility.CheckNotNull("advices", advices); ArgumentUtility.CheckNotNull("memberImports", memberImports); ArgumentUtility.CheckNotNull("memberIntroductions", memberIntroductions); _type = type; _scope = scope; _activation = activation; _construction = construction; _crosscutting = crosscutting; _advices = advices; _memberImports = memberImports; _memberIntroductions = memberIntroductions; }
public static IAspectConstruction GetConstructionByType(Type constructionType) { var constructions = new IAspectConstruction[] { new AttributeConstruction(GetCustomAttributeData(typeof(DummyAspectAttribute))), new TypeConstruction(typeof(DummyAspectAttribute)) }; var aspectConstructionInfo = constructions.SingleOrDefault(x => x.GetType() == constructionType); Assertion.IsNotNull(constructionType); return(aspectConstructionInfo); }
public MemberInitExpression CreateAspectInitExpressions(IAspectConstruction construction) { ArgumentUtility.CheckNotNull("construction", construction); var constructorInfo = construction.ConstructorInfo; var constructorArguments = constructorInfo.GetParameters().Select(x => x.ParameterType).Zip( construction.ConstructorArguments, (type, value) => Expression.Constant(value, type)).Cast <Expression>(); var createExpression = Expression.New(constructorInfo, constructorArguments.ToArray()); var memberBindingExpressions = construction.NamedArguments.Select(GetMemberBindingExpression).Cast <MemberBinding>(); return(Expression.MemberInit(createExpression, memberBindingExpressions)); }
public static IAdviceBuilder GetAdviceBuilder( IAspectConstruction construction = null, MethodInfo method = null, AdviceExecution execution = AdviceExecution.Before, AdviceScope scope = AdviceScope.Instance) { construction = construction ?? GetConstruction(); method = method ?? GetMethodInfo(); return(new AdviceBuilder() .SetConstruction(construction) .SetMethod(method) .SetExecution(execution) .SetScope(scope)); }
private void CheckThrowForMissing( string missingMember, IAspectConstruction construction = null, MethodInfo method = null, AdviceExecution execution = AdviceExecution.Undefined, AdviceScope scope = AdviceScope.Undefined) { var builder = new AdviceBuilder() .SetConstruction(construction) .SetMethod(method) .SetExecution(execution) .SetScope(scope); var message = string.Format("Cannot build advice without having set its {0}.", missingMember); Assert.That(() => builder.Build(), Throws.InvalidOperationException.With.Message.EqualTo(message)); }
public static Advice GetAdvice( IAspectConstruction construction = null, MethodInfo method = null, string role = null, string name = null, AdviceExecution execution = AdviceExecution.Around, AdviceScope scope = AdviceScope.Static, int priority = 0, IEnumerable <IPointcut> pointcuts = null) { construction = construction ?? GetConstruction(); method = method ?? GetMethodInfo(); name = name ?? "name"; role = role ?? "role"; pointcuts = pointcuts ?? new IPointcut[0]; return(new Advice(construction, method, name, role, execution, scope, priority, pointcuts)); }
public static Aspect GetAspect( Type type = null, AspectScope scope = (AspectScope)0, AspectActivation activation = (AspectActivation)0, IAspectConstruction construction = null, ICrosscutting crosscutting = null, IEnumerable <Advice> advices = null, IEnumerable <MemberImport> imports = null, IEnumerable <MemberIntroduction> introductions = null) { type = type ?? typeof(UnspecifiedAspect); scope = GetAspectScope(scope); activation = GetAspectActivation(activation); construction = construction ?? GetConstruction(); crosscutting = crosscutting ?? GetCrosscutting(); advices = advices ?? GetMultiple(() => GetAdvice()); imports = imports ?? new MemberImport[0]; introductions = introductions ?? new MemberIntroduction[0]; return(new Aspect(type, scope, activation, construction, crosscutting, advices, imports, introductions)); }
private Aspect Build(Type type, IAspectInfo info, IAspectConstruction construction, IPointcut pointcut, int priority = 0) { var scope = info.Scope; var activation = info.Activation; var role = info.Role; var orderings = new List <IOrdering>(); var crosscutting = new Crosscutting(pointcut, orderings, priority, type, role); orderings.AddRange(_orderingBuilder.BuildOrderings(crosscutting, type)); var advices = new List <Advice>(); var introductions = new List <MemberIntroduction>(); var imports = new List <MemberImport>(); var aspect = new Aspect(type, scope, activation, construction, crosscutting, advices, imports, introductions); advices.AddRange(_adviceBuilder.GetAdvices(aspect)); imports.AddRange(_interTypeBuilder.AddMemberImports(aspect)); introductions.AddRange(_interTypeBuilder.AddMemberIntroductions(aspect)); return(aspect); }