public void TestOverrideReturnValue() { //Create and mock the interceptor. MockRepository mock = new MockRepository(); IAspect hmock = mock.StrictMock <IAspect>(); Expect.Call(hmock.PreCall(null)) .Return(MethodVoteOptions.Continue) .IgnoreArguments(); hmock.PostCall(null, null); LastCall.Callback(delegate(CastleIInvocation ii, AspectReturnValue retval) { retval.WrappedReturnValue = "1234567890"; return(retval.Original.Equals("12")); }); mock.ReplayAll(); using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample2.config")) { //Set the mock into the kernel. container.Kernel.RemoveComponent("interceptor"); container.Kernel.AddComponentInstance("interceptor", hmock); ISomething something = container.Resolve <ISomething>(); String retvalue = something.OtherMethod("1", "2"); Assert.That(retvalue, Is.EqualTo("1234567890")); } mock.VerifyAll(); }
public void TestIgnoreExeptionReturnValue() { //Create and mock the interceptor. MockRepository mock = new MockRepository(); IAspect hmock = mock.StrictMock <IAspect>(); Expect.Call(hmock.PreCall(null)) .Return(MethodVoteOptions.Continue) .IgnoreArguments(); Expect.Call(() => hmock.PostCall(null, null)) .IgnoreArguments(); Expect.Call(() => hmock.OnException(null, null, null)) .Callback(delegate(CastleIInvocation ii, Exception e, AspectExceptionAction action) { action.IgnoreException = true; return(true); }); mock.ReplayAll(); using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample2.config")) { //Set the mock into the kernel. container.Kernel.RemoveComponent("interceptor"); container.Kernel.AddComponentInstance("interceptor", hmock); ISomething something = container.Resolve <ISomething>("throwclass"); String retvalue = something.OtherMethod("1", "2"); Assert.That(retvalue, Is.Null); //Default value is returned } mock.VerifyAll(); }
public void TestMultiplePointCut() { //Create and mock the interceptor. MockRepository mock = new MockRepository(); IAspect hmock = mock.CreateMock <IAspect>(); Expect.Call(hmock.PreCall(null)) .Repeat.Twice() .Return(MethodVoteOptions.Continue) .IgnoreArguments(); Expect.Call(() => hmock.PostCall(null, null)) .Repeat.Twice() .IgnoreArguments(); mock.ReplayAll(); using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample3.config")) { //Set the mock into the kernel. container.Kernel.RemoveComponent("interceptor"); container.Kernel.AddComponentInstance("interceptor", hmock); ISomething something = container.Resolve <ISomething>(); something.AMethod("TEST"); something.OtherMethod("1", "2"); } mock.VerifyAll(); }
public void TestTestContainerAop() { MockRepository mock = new MockRepository(); IAspect hmock = mock.CreateMock <IAspect>(); hmock.PostCall(null, null); LastCall.IgnoreArguments(); hmock.PreCall(null); LastCall.Return(MethodVoteOptions.Continue) .IgnoreArguments(); mock.ReplayAll(); TestContainer container = new TestContainer(@"Concrete\Castle\AOP\HelperClasses\ConfigSample1.config"); container.Kernel.RemoveComponent("interceptor"); container.Kernel.AddComponentInstance("interceptor", hmock); container.Resolve <ISomething>().AMethod("test"); mock.VerifyAll(); }
public void TestBasicInterceptionTest() { //Create and mock the interceptor. MockRepository mock = new MockRepository(); IAspect hmock = mock.CreateMock <IAspect>(); hmock.PostCall(null, null); LastCall.IgnoreArguments(); hmock.PreCall(null); LastCall.Return(MethodVoteOptions.Continue) .IgnoreArguments(); mock.ReplayAll(); using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample1.config")) { container.Kernel.RemoveComponent("interceptor"); container.Kernel.AddComponentInstance("interceptor", hmock); container.Resolve <ISomething>().OtherMethod("test1", "test2"); //This is not intercepted, so the interceptor will be not called. container.Resolve <ISomething>().AMethod("test2"); } mock.VerifyAll(); }