Build() 공개 메소드

public Build ( ) : AspectEngine
리턴 AspectEngine
예제 #1
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 );
		}
예제 #2
0
		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();
		}
예제 #3
0
		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 );
		}
예제 #4
0
		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 );
		}
예제 #5
0
		public void InterceptAll()
		{
			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();
			WrapAndInvokeEverything(engine);
		}
예제 #6
0
		public void InterceptAllMethods()
		{
			String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " + 
				" " + 
				" aspect MyAspect for ComplexClass " + 
				"   " + 
				"   pointcut method(*)" + 
				"     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
		}
		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);
		}
예제 #8
0
		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();			
		}
예제 #9
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 );
		}
예제 #10
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);
		}
예제 #11
0
		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 );
		}
예제 #12
0
		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);
		}
예제 #13
0
		public void InterceptAllDoSomethingMethodsWithAnIntAndAnIntArguments()
		{
			String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " + 
				" " + 
				" aspect MyAspect for ComplexClass " + 
				"   " + 
				"   pointcut method(* DoSomething(int, int))" + 
				"     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" + 
				"   end" + 
				"   " + 
				" end ";

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

			String[] messages = LogInvocationInterceptor.Messages;
			Assert.AreEqual( 0, messages.Length );
		}