Exemplo n.º 1
0
        public void BuildUsingLanguageWithDifferingKeys()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " interceptors [" +
                              " \"interceptor\" : DummyInterceptor " +
                              " ]" +
                              " mixins [" +
                              " \"mixin\" : DummyMixin " +
                              " ]" +
                              " " +
                              " aspect McBrother for DummyCustomer " +
                              "   include \"mixin\"" +
                              "   " +
                              "   pointcut method(*)" +
                              "     advice(\"interceptor\")" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);

            AspectEngine engine = builder.Build();

            AssertEngineConfiguration(engine);
        }
Exemplo n.º 2
0
        public void BuildUsingAppDomainConfiguration()
        {
            AppDomainConfigurationBuilder builder = new AppDomainConfigurationBuilder();
            AspectEngine engine = builder.Build();

            AssertEngineConfiguration(engine);
        }
Exemplo n.º 3
0
        public void BuildUsingXmlWithLanguageInCData()
        {
            String xmlContents = "<configuration>" +
                                 " <![CDATA[" +
                                 " import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                                 " interceptors [" +
                                 " \"key\" : DummyInterceptor " +
                                 " ]" +
                                 " mixins [" +
                                 " \"key\" : DummyMixin " +
                                 " ]" +
                                 " " +
                                 " aspect McBrother for DummyCustomer " +
                                 "   include \"key\"" +
                                 "   " +
                                 "   pointcut method(*)" +
                                 "     advice(\"key\")" +
                                 "   end" +
                                 "   " +
                                 " end " +
                                 " ]]>" +
                                 "</configuration>";
            XmlEngineBuilder builder = new XmlEngineBuilder(xmlContents);
            AspectEngine     engine  = builder.Build();

            AssertEngineConfiguration(engine);
        }
Exemplo n.º 4
0
        public void InterceptWithComplexSignatures()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut method(* Do.*(*))" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              "   pointcut propertyread(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              "   pointcut propertywrite(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            WrapAndInvokeEverything(engine);
        }
Exemplo n.º 5
0
        public void ClassWithConstructorArguments()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            ComplexClass instance = null;

            instance = engine.WrapClass(typeof(ComplexClass), "Eric Cartman") as ComplexClass;
            Assert.AreEqual("Eric Cartman", instance.Name);
            Assert.IsFalse(instance.Started);
            InvokeAndAssert(instance);

            instance = engine.WrapClass(typeof(ComplexClass), "Kenny McKormick", true) as ComplexClass;
            Assert.AreEqual("Kenny McKormick", instance.Name);
            Assert.IsTrue(instance.Started);
            InvokeAndAssert(instance);

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(20, messages.Length);
        }
        public void ImplementLoggerProperty()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for Author " +
                              "   " +
                              "   include Loggeable" +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(LogInvocationsInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            Author author = engine.WrapClass(typeof(Author)) as Author;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ILoggeable);

            Assert.AreEqual(0, author.BooksPublished);
            author.MoreOneBook();
            Assert.AreEqual(1, author.BooksPublished);

            ILoggeable log      = author as ILoggeable;
            String     messages = log.GetLogMessages();

            // TODO: Correct compare
            Assert.AreEqual("Invoking get_BooksPublished;Invoking MoreOneBook;Invoking get_BooksPublished;", messages);
        }
Exemplo n.º 7
0
        public void ClassWithConstructorArgumentsAndNoAspects()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " interceptors [" +
                              " \"key\" : DummyInterceptor " +
                              " ]" +
                              " mixins [" +
                              " \"key\" : DummyMixin " +
                              " ]" +
                              " " +
                              " aspect McBrother for DummyCustomer " +
                              "   include \"key\"" +
                              "   " +
                              "   pointcut method(*)" +
                              "     advice(\"key\")" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            ComplexClass instance = null;

            instance = engine.WrapClass(typeof(ComplexClass), "Eric Cartman") as ComplexClass;
            Assert.AreEqual("Eric Cartman", instance.Name);
            Assert.IsFalse(instance.Started);
        }
Exemplo n.º 8
0
        public void InterfaceWrap()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for [ assignableFrom(IPartiallyComplex) ] " +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            IPartiallyComplex instance = null;

            instance = engine.WrapInterface(typeof(IPartiallyComplex), new ComplexClass()) as IPartiallyComplex;

            instance.DoNothing();
            instance.DoSomething();

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(2, messages.Length);
        }
        public void MakeAuthorAPersonAndACustomer()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for Author " +
                              "   " +
                              "   include DummyCustomer" +
                              "   include DummyPerson" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            Author author = engine.WrapClass(typeof(Author)) as Author;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ICustomer);
            Assert.IsNotNull(author as IPerson);

            ICustomer customer = author as ICustomer;

            customer.CustomerId = 10;
            Assert.AreEqual(10, customer.CustomerId);

            IPerson person = author as IPerson;

            person.Name = "Billy Paul McKinsky";
            Assert.AreEqual(10, customer.CustomerId);

            Assert.AreEqual(0, author.BooksPublished);
            author.MoreOneBook();
            Assert.AreEqual(1, author.BooksPublished);
        }
        public IInvocationDispatcher Create(AspectDefinition aspect, AspectEngine engine)
        {
            IInvocationDispatcher dispatcher = new DefaultInvocationDispatcher(aspect);

            dispatcher.Init(engine);
            return(dispatcher);
        }
		private static void MixinAndInterceptorExecution()
		{
			Console.Out.WriteLine( " o0o Within security checking o0o " );

			// For the sake of readability we're keep the aspect code here:
			String contents = 
				" import AspectSharp.Example.Aop.Interceptors " + 
				" import AspectSharp.Example.Aop.Mixins " + 
				" " +
				" aspect sample for [ AspectSharp.Example.ContentProviders ] " + 
				"   include SecurityMixin " + 
				"   " + 
				"   pointcut method(* RetrieveContent())" + 
				"     advice(SecurityCheckInterceptor)" + 
				"   end" + 
				"   " + 
				" end ";

			AspectLanguageEngineBuilder builder = new AspectLanguageEngineBuilder( contents );
			AspectEngine engine = builder.Build();

			RequestPipeline pipeline = new RequestPipeline();
			pipeline.Context["username"] = "******";
			pipeline.AddContentProvider( engine.WrapClass( typeof(StaticContentProvider) ) as IContentProvider );
			pipeline.AddContentProvider( engine.WrapClass( typeof(DynamicContentProvider) ) as IContentProvider );
			pipeline.View = new PlainTextView();
			pipeline.ProcessRequest( Console.Out );

			Console.Out.WriteLine();
		}
		private static void HashtableTest()
		{
			Console.Out.WriteLine( " o0o Changing default hashtable value o0o " );

			// For the sake of readability we're keep the aspect code here:
			String contents = 
				" import System.Collections " + 
				" " +
				" aspect sample for Hashtable " + 
				"   " + 
				"   pointcut propertyread(* Item(*))" + 
				"     advice(HashcodeDefaultValueInterceptor)" + 
				"   end" + 
				"   " + 
				" end ";

			AspectLanguageEngineBuilder builder = new AspectLanguageEngineBuilder( contents );
			AspectEngine engine = builder.Build();

			IDictionary myHashTable = engine.WrapClass( typeof(Hashtable) ) as IDictionary;

			String value = myHashTable["item"] as String;
			Console.Out.WriteLine( "Default value is {0}", value );

			Console.Out.WriteLine();			
		}
Exemplo n.º 13
0
        private static void AssertEngineConfiguration(AspectEngine engine)
        {
            Assert.IsNotNull(engine);
            Assert.IsNotNull(engine.Configuration);
            Assert.AreEqual(1, engine.Configuration.Imports.Count);
            Assert.AreEqual(1, engine.Configuration.Mixins.Count);
            Assert.AreEqual(1, engine.Configuration.Interceptors.Count);
            Assert.AreEqual(1, engine.Configuration.Aspects.Count);

            AspectDefinition aspect = engine.Configuration.Aspects[0];

            Assert.AreEqual("McBrother", aspect.Name);
            Assert.AreEqual(typeof(DummyCustomer), aspect.TargetType.SingleType.ResolvedType);

            Assert.AreEqual(1, aspect.Mixins.Count);
            MixinDefinition mixin = aspect.Mixins[0];

            Assert.AreEqual(typeof(DummyMixin), mixin.TypeReference.ResolvedType);

            Assert.AreEqual(1, aspect.PointCuts.Count);
            PointCutDefinition pointcut = aspect.PointCuts[0];

            Assert.AreEqual(AllMethodSignature.Instance, pointcut.Method);

            Assert.AreEqual(1, pointcut.Advices.Count);
            InterceptorDefinition advice = pointcut.Advices[0];

            Assert.AreEqual(typeof(DummyInterceptor), advice.TypeReference.ResolvedType);
        }
        static void Main(string[] args)
        {
            String weavingRules =
                " import AOPServices.Aspects " +
                " " +
                " aspect AuthorizationAspect for [ AOPServices.Services ] " +
                "   " +
                "   pointcut method(* Start())" +
                "     advice(AuthorizationAdvice)" +
                "   end" +
                "   " +
                "   pointcut method(* Stop())" +
                "     advice(AuthorizationAdvice)" +
                "   end" +
                "   " +
                " end ";

            AspectLanguageEngineBuilder builder = new AspectLanguageEngineBuilder(weavingRules);
            AspectEngine engine = builder.Build();

            NASDAQHeartBeatService nasdaqService = engine.WrapClass(typeof(NASDAQHeartBeatService)) as NASDAQHeartBeatService;

            nasdaqService.Start();
            Console.ReadLine();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Constructs a DefaultProxyFactory
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="dispatcherFactory"></param>
        public DefaultProxyFactory(AspectEngine engine, IInvocationDispatcherFactory dispatcherFactory)
        {
            AssertUtil.ArgumentNotNull(engine, "engine");
            AssertUtil.ArgumentNotNull(dispatcherFactory, "dispatcherFactory");

            _engine            = engine;
            _dispatcherFactory = dispatcherFactory;
        }
Exemplo n.º 16
0
		/// <summary>
		/// Constructs a DefaultProxyFactory
		/// </summary>
		/// <param name="engine"></param>
		/// <param name="dispatcherFactory"></param>
		public DefaultProxyFactory(AspectEngine engine, IInvocationDispatcherFactory dispatcherFactory)
		{
			AssertUtil.ArgumentNotNull(engine, "engine");
			AssertUtil.ArgumentNotNull(dispatcherFactory, "dispatcherFactory");

			_engine = engine;
			_dispatcherFactory = dispatcherFactory;
		}
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            //Reading the config from an application configuration file.
            AppDomainConfigurationBuilder builder = new AppDomainConfigurationBuilder();

            //Creating the AspectEngine, based on the configuration.
            _engine = builder.Build();

            ClassInvocation();

            Console.WriteLine(" ");
            Console.WriteLine(" ");

            InterfaceInvocation();

            Console.WriteLine("\r\nPress any key to exit.");
            Console.ReadLine();
        }
Exemplo n.º 18
0
		static void Main(string[] args)
		{
			//Reading the config from an application configuration file.
			AppDomainConfigurationBuilder builder = new AppDomainConfigurationBuilder();

			//Creating the AspectEngine, based on the configuration.
			_engine = builder.Build();

			ClassInvocation();

			Console.WriteLine(" ");
			Console.WriteLine(" ");

			InterfaceInvocation();

			Console.WriteLine("\r\nPress any key to exit." );
			Console.ReadLine();
		}
        private static void WrapAndInvokeEverything(AspectEngine engine)
        {
            ComplexClass instance = engine.WrapClass(typeof(ComplexClass)) as ComplexClass;

            instance.DoNothing();
            instance.DoSomething();
            int arg = 1;

            instance.DoSomething(arg);
            instance.DoSomething(arg, "hiya");

            //TODO: Intercept by ref calls.
            //Assert.AreEqual(arg, instance.Pong(ref arg));

            instance.Name = "John Johnson";
            Assert.AreEqual("John Johnson", instance.Name);
            instance.Started = true;
            Assert.IsTrue(instance.Started);
        }
        public void MixinProxyAware()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for LogEnabledAuthor " +
                              "   " +
                              "   include LogFactoryMixin" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            LogEnabledAuthor author = engine.WrapClass(typeof(LogEnabledAuthor)) as LogEnabledAuthor;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ILogEnabled);
            Assert.IsNotNull(author.Logger);
        }
        public void InterceptAllDoSMethods()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut method(* DoS.*(*))" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            WrapAndInvokeEverything(engine);

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(3, messages.Length);
        }
        public void InterceptAllProperties()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut property(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            WrapAndInvokeEverything(engine);

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(4, messages.Length);
            // TODO: Assert messages in correct order
        }
Exemplo n.º 23
0
        public void BuildUsingCode()
        {
            CodeEngineBuilder   builder = new CodeEngineBuilder();
            EngineConfiguration conf    = builder.GetConfiguration();

            ImportDirective import = new ImportDirective(LexicalInfo.Empty, "AspectSharp.Tests.Classes");

            import.AssemblyReference = new AssemblyReference(LexicalInfo.Empty, "AspectSharp.Tests");
            conf.Imports.Add(import);

            conf.Mixins.Add("key", LexicalInfo.Empty).TypeReference       = new TypeReference(LexicalInfo.Empty, "DummyMixin");
            conf.Interceptors.Add("key", LexicalInfo.Empty).TypeReference = new TypeReference(LexicalInfo.Empty, "DummyInterceptor");

            AspectDefinition aspect = new AspectDefinition(LexicalInfo.Empty, "McBrother");

            aspect.TargetType            = new TargetTypeDefinition();
            aspect.TargetType.SingleType = new TypeReference(LexicalInfo.Empty, "DummyCustomer");
            conf.Aspects.Add(aspect);

            MixinDefinition mixin = new MixinDefinition(LexicalInfo.Empty);

            mixin.TypeReference = new TypeReference(LexicalInfo.Empty, "key", TargetTypeEnum.Link);
            aspect.Mixins.Add(mixin);

            PointCutDefinition pointcut = new PointCutDefinition(LexicalInfo.Empty, PointCutFlags.Method);

            pointcut.Method = AllMethodSignature.Instance;

            InterceptorDefinition interceptor = new InterceptorDefinition(LexicalInfo.Empty);

            interceptor.TypeReference = new TypeReference(LexicalInfo.Empty, "key", TargetTypeEnum.Link);
            pointcut.Advices.Add(interceptor);

            aspect.PointCuts.Add(pointcut);

            AspectEngine engine = builder.Build();

            AssertEngineConfiguration(engine);
        }
Exemplo n.º 24
0
        public void XmlWithMoreComplexMethodSignature()
        {
            String xmlContents = "<configuration>" +
                                 "<import namespace=\"AspectSharp.Tests.Classes\" assembly=\"AspectSharp.Tests\" />" +
                                 "<mixins>" +
                                 "<mixin key=\"key\" type=\"DummyMixin\" refTypeEnum=\"Type\" />" +
                                 "</mixins><interceptors>" +
                                 "<interceptor key=\"key\" type=\"DummyInterceptor\" refTypeEnum=\"Type\" />" +
                                 "</interceptors>" +
                                 "<aspect name=\"McBrother\"><for>" +
                                 "<singletype type=\"DummyCustomer\" refTypeEnum=\"Type\" />" +
                                 "</for>" +
                                 "<mixin type=\"key\" refTypeEnum=\"Link\" />" +
                                 "<pointcut symbol=\"Method\"><signature>(void Name(*))</signature>" +
                                 "<interceptor type=\"key\" refTypeEnum=\"Link\" />" +
                                 "</pointcut>" +
                                 "</aspect>" +
                                 "</configuration>";
            XmlEngineBuilder builder = new XmlEngineBuilder(xmlContents);
            AspectEngine     engine  = builder.Build();

            Assert.IsNotNull(engine);
            Assert.IsNotNull(engine.Configuration);

            AspectDefinition aspect = engine.Configuration.Aspects[0];

            Assert.AreEqual(1, aspect.Mixins.Count);

            PointCutDefinition pointcut = aspect.PointCuts[0];

            Assert.IsTrue(pointcut.Method.AllArguments);
            Assert.AreEqual("void", pointcut.Method.RetType);
            Assert.AreEqual("Name", pointcut.Method.MethodName);

            Assert.AreEqual(1, pointcut.Advices.Count);
            InterceptorDefinition advice = pointcut.Advices[0];

            Assert.AreEqual(typeof(DummyInterceptor), advice.TypeReference.ResolvedType);
        }
Exemplo n.º 25
0
		private static void WrapAndInvokeEverything(AspectEngine engine)
		{
			long begin = DateTime.Now.Ticks;

			ComplexClass instance = engine.WrapClass(typeof(ComplexClass)) as ComplexClass;

			for(int i=0; i < 10000; i++)
			{
				instance.DoNothing();
				instance.DoSomething();
				instance.DoSomething(1);
				instance.DoSomething(1, "hiya");
				instance.Name = "John Johnson";
				Assert.AreEqual( "John Johnson", instance.Name );
				instance.Started = true;
				Assert.IsTrue( instance.Started );
			}

			long end = DateTime.Now.Ticks;
			long result = (end - begin) / 1000;
			System.Console.WriteLine( "Execution took " + (result).ToString() + " ms " );
		}
Exemplo n.º 26
0
        public void BuildUsingXml()
        {
            String xmlContents = "<configuration>" +
                                 "<import namespace=\"AspectSharp.Tests.Classes\" assembly=\"AspectSharp.Tests\" />" +
                                 "<mixins>" +
                                 "<mixin key=\"key\" type=\"DummyMixin\" refTypeEnum=\"Type\" />" +
                                 "</mixins><interceptors>" +
                                 "<interceptor key=\"key\" type=\"DummyInterceptor\" refTypeEnum=\"Type\" />" +
                                 "</interceptors>" +
                                 "<aspect name=\"McBrother\"><for>" +
                                 "<singletype type=\"DummyCustomer\" refTypeEnum=\"Type\" />" +
                                 "</for>" +
                                 "<mixin type=\"key\" refTypeEnum=\"Link\" />" +
                                 "<pointcut symbol=\"Method\"><signature>(*)</signature>" +
                                 "<interceptor type=\"key\" refTypeEnum=\"Link\" />" +
                                 "</pointcut>" +
                                 "</aspect>" +
                                 "</configuration>";
            XmlEngineBuilder builder = new XmlEngineBuilder(xmlContents);
            AspectEngine     engine  = builder.Build();

            AssertEngineConfiguration(engine);
        }
Exemplo n.º 27
0
        private static void WrapAndInvokeEverything(AspectEngine engine)
        {
            long begin = DateTime.Now.Ticks;

            ComplexClass instance = engine.WrapClass(typeof(ComplexClass)) as ComplexClass;

            for (int i = 0; i < 10000; i++)
            {
                instance.DoNothing();
                instance.DoSomething();
                instance.DoSomething(1);
                instance.DoSomething(1, "hiya");
                instance.Name = "John Johnson";
                Assert.AreEqual("John Johnson", instance.Name);
                instance.Started = true;
                Assert.IsTrue(instance.Started);
            }

            long end    = DateTime.Now.Ticks;
            long result = (end - begin) / 1000;

            System.Console.WriteLine("Execution took " + (result).ToString() + " ms ");
        }
        public void MixinMethodsMustBeIntercepted()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for Author " +
                              "   " +
                              "   include Loggeable" +
                              "   include DummyPerson" +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(LogInvocationsInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            Author author = engine.WrapClass(typeof(Author)) as Author;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ILoggeable);
            Assert.IsNotNull(author as IPerson);

            IPerson person = author as IPerson;

            person.Name = "McBilly";
            Assert.AreEqual("McBilly", person.Name);

            ILoggeable log = author as ILoggeable;

            log.Log("Test");
            String messages = log.GetLogMessages();

            Assert.AreEqual("Invoking set_Name;Invoking get_Name;Test;", messages);
        }
Exemplo n.º 29
0
		public IInvocationDispatcher Create(AspectDefinition aspect, AspectEngine engine)
		{
			IInvocationDispatcher dispatcher = new DefaultInvocationDispatcher(aspect);
			dispatcher.Init(engine);
			return dispatcher;
		}
		private static void AssertEngineConfiguration(AspectEngine engine)
		{
			Assert.IsNotNull(engine);
			Assert.IsNotNull(engine.Configuration);
			Assert.AreEqual(1, engine.Configuration.Imports.Count);
			Assert.AreEqual(1, engine.Configuration.Mixins.Count);
			Assert.AreEqual(1, engine.Configuration.Interceptors.Count);
			Assert.AreEqual(1, engine.Configuration.Aspects.Count);

			AspectDefinition aspect = engine.Configuration.Aspects[0];
			Assert.AreEqual("McBrother", aspect.Name);
			Assert.AreEqual( typeof(DummyCustomer), aspect.TargetType.SingleType.ResolvedType );
			
			Assert.AreEqual(1, aspect.Mixins.Count);
			MixinDefinition mixin = aspect.Mixins[0];
			Assert.AreEqual( typeof(DummyMixin), mixin.TypeReference.ResolvedType );

			Assert.AreEqual(1, aspect.PointCuts.Count);
			PointCutDefinition pointcut = aspect.PointCuts[0];
			Assert.AreEqual(AllMethodSignature.Instance, pointcut.Method );

			Assert.AreEqual(1, pointcut.Advices.Count);
			InterceptorDefinition advice = pointcut.Advices[0];
			Assert.AreEqual( typeof(DummyInterceptor), advice.TypeReference.ResolvedType );
		}
Exemplo n.º 31
0
		private static void WrapAndInvokeEverything(AspectEngine engine)
		{
			ComplexClass instance = engine.WrapClass(typeof(ComplexClass)) as ComplexClass;
			instance.DoNothing();
			instance.DoSomething();
			int arg = 1;

			instance.DoSomething(arg);
			instance.DoSomething(arg, "hiya");

			//TODO: Intercept by ref calls.
			//Assert.AreEqual(arg, instance.Pong(ref arg));
			
			instance.Name = "John Johnson";
			Assert.AreEqual( "John Johnson", instance.Name );
			instance.Started = true;
			Assert.IsTrue( instance.Started );
		}
Exemplo n.º 32
0
		public void Init(AspectEngine engine)
		{
		}
Exemplo n.º 33
0
		/// <summary>
		/// Constructs a DefaultProxyFactory
		/// </summary>
		/// <param name="engine"></param>
		public DefaultProxyFactory(AspectEngine engine) : this(engine, new DefaultDispatcherFactory())
		{
		}
Exemplo n.º 34
0
 /// <summary>
 /// Constructs a DefaultProxyFactory
 /// </summary>
 /// <param name="engine"></param>
 public DefaultProxyFactory(AspectEngine engine) : this(engine, new DefaultDispatcherFactory())
 {
 }
Exemplo n.º 35
0
 public AopInterceptor(AspectEngine engine, IKernel kernel)
 {
     _engine = engine;
     _kernel = kernel;
 }
Exemplo n.º 36
0
 private PlugInDynamicProxy()
 {
     builder = new AspectLanguageEngineBuilder(string.Empty);
     engine  = builder.Build();
 }