public void ShouldReplaceTokensInInstanceName() { string doSomethingInstanceName = "Method DoSomething"; string doSomethingElseInstanceName = "Method DoSomethingElse"; ResetCounters(PerformanceCounterCallHandler.TotalInstanceName); ResetCounters(doSomethingInstanceName); ResetCounters(doSomethingElseInstanceName); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPerfMonPolicies()); callHandler.InstanceName = "Method {method}"; MonitorTarget target = factory.Create <MonitorTarget>(); Assert.AreEqual(0L, GetTotalCallCount()); Assert.AreEqual(0L, GetNumberOfCallsCount(doSomethingInstanceName)); Assert.AreEqual(0L, GetNumberOfCallsCount(doSomethingElseInstanceName)); target.DoSomething(); target.DoSomethingElse(); target.DoSomething(); target.DoSomething(); target.DoSomethingElse(); target.DoSomething(); Assert.AreEqual(6L, GetTotalCallCount()); Assert.AreEqual(4L, GetNumberOfCallsCount(doSomethingInstanceName)); Assert.AreEqual(2L, GetNumberOfCallsCount(doSomethingElseInstanceName)); }
private RemotingPolicyInjector GetFactoryWithPolicies() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); return(factory); }
public void CanInterceptOnFormsClass() { CallCountHandler countHandler = new CallCountHandler(); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPolicySet(countHandler)); IMyForm magicForm = factory.Create<MyForm, IMyForm>(); }
public void CanInterceptOnFormsClass() { CallCountHandler countHandler = new CallCountHandler(); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPolicySet(countHandler)); IMyForm magicForm = factory.Create <MyForm, IMyForm>(); }
public void ShouldBeAbleToCacheNullReturnValues() { RemotingPolicyInjector factory = new RemotingPolicyInjector(GetCachingPolicies()); CachingTarget target = factory.Create <CachingTarget>(); string result = target.SometimesReturnsNull(false); string result2 = target.SometimesReturnsNull(true); }
public void ShouldNotInterceptAnyMethodsOnClassThatHasNoPolicyAttribute() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); CriticalFakeDal dal = factory.Create <CriticalFakeDal>(); Assert.IsFalse(RemotingServices.IsTransparentProxy(dal)); }
public void CanCastToMBROBaseClass() { RemotingPolicyInjector factory = new RemotingPolicyInjector(new PolicySet(GetCallCountingPolicy())); IDal dal = factory.Create <MockDal, IDal>(); Assert.IsNotNull(dal as IMonitor); Assert.IsNotNull(dal as MockDal); }
public void ShouldCreateRawObjectWhenNoPolicyPresent() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); MockDal dal = factory.Create <MockDal>(); Assert.IsNotNull(dal); Assert.IsTrue(dal is MockDal); Assert.IsFalse(RemotingServices.IsTransparentProxy(dal)); }
public void ShouldBeAbleToSwallowExceptionFromPropertySet() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddExceptionPolicy(factory, "Swallow Exceptions", new TypeMatchingRule("TargetType")); TargetType target = factory.Create <TargetType>(); target.MyProperty = 5; }
public void ShouldRethrowFromNoOpPolicy() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddExceptionPolicy(factory, "No-Op Policy", new TypeMatchingRule("TargetType")); TargetType target = factory.Create <TargetType>(); target.ThrowFromFunctionWithReturnValue(); }
public void ShouldTranslateException() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddExceptionPolicy(factory, "Translate Exceptions", new TypeMatchingRule("TargetType")); TargetType target = factory.Create <TargetType>(); target.WillThrowException(); }
public void ShouldThrowWhenSwallowingExceptionFromPropertyGet() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddExceptionPolicy(factory, "Swallow Exceptions", new TypeMatchingRule("TargetType")); TargetType target = factory.Create <TargetType>(); int foo = target.MyProperty; }
public void CannotCastToNonMBROBaseClass() { RemotingPolicyInjector factory = new RemotingPolicyInjector(new PolicySet(GetCallCountingPolicy())); IDal dal = factory.Create <InterfacesOnlyDal, IDal>(); Assert.IsNotNull(dal as IMonitor); Assert.IsNull(dal as InterfacesOnlyDal); }
public void ShouldRecordOneCallInstance() { ResetCounters(); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPerfMonPolicies()); MonitorTarget target = factory.Create <MonitorTarget>(); Assert.AreEqual(0L, GetNumberOfCallsCount(TestInstanceName)); target.DoSomething(); Assert.AreEqual(1L, GetNumberOfCallsCount(TestInstanceName)); }
public void ShouldRecordOneCallTotal() { ResetCounters(); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPerfMonPolicies()); MonitorTarget target = factory.Create <MonitorTarget>(); Assert.AreEqual(0L, GetTotalCallCount()); target.DoSomething(); Assert.AreEqual(1L, GetTotalCallCount()); }
public void ShouldThrowWhenSwallowingExceptionFromNonVoidMethod() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddExceptionPolicy(factory, "Swallow Exceptions", new TypeMatchingRule("TargetType")); TargetType target = factory.Create <TargetType>(); target.ThrowFromFunctionWithReturnValue(); Assert.Fail("An exception should have been thrown"); }
public void ShouldThrowCorrectException() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddNoopPolicy(factory, new TypeMatchingRule("TargetType")); TargetType target = factory.Create <TargetType>(); target.WillThrowException(); }
public void ShouldRequireInteceptionForTypeMatchingPolicy() { RemotingPolicyInjector factory = GetFactoryWithPolicies(); bool shouldInterceptMockDal = factory.TypeRequiresInterception(typeof(MockDal)); bool shouldInterceptString = factory.TypeRequiresInterception(typeof(string)); Assert.IsTrue(shouldInterceptMockDal); Assert.IsFalse(shouldInterceptString); }
public void ShouldCallHandlersWhenCallingMethods() { RemotingPolicyInjector factory = GetFactoryWithPolicies(); MockDal dal = factory.Create <MockDal>(); Assert.AreEqual(0, countHandler.CallCount); dal.DoSomething("43"); dal.DoSomething("63"); dal.DoSomething("Hike!"); Assert.AreEqual(3, countHandler.CallCount); }
public void ShouldCallProperHandlersInThePresenceOfOverloadedMethods() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddOverloadsPolicy(factory); MockDalWithOverloads dal = factory.Create <MockDalWithOverloads>(); Assert.AreEqual(42, dal.DoSomething("not intercepted")); Assert.IsNull(dal.DoSomething(42)); }
public void ShouldNotCacheVoidMethods() { RemotingPolicyInjector factory = new RemotingPolicyInjector(GetCachingPolicies()); CachingTarget target = factory.Create <CachingTarget>(); Assert.AreEqual(0, target.Count); target.IncrementCount(); Assert.AreEqual(1, target.Count); target.IncrementCount(); Assert.AreEqual(2, target.Count); }
public void HandlerCanShortcutMethodExecution() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); factory.Policies.Add(GetShortcutPolicy()); MockDal dal = factory.Create <MockDal>(); Assert.AreEqual(42, dal.DoSomething("should return 42")); Assert.AreEqual(-1, dal.DoSomething("shortcut")); }
public void ShouldInterceptInterfaceImplementationMethods() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); IDal dal = factory.Create <MockDal, IDal>(); Assert.AreEqual(0, countHandler.CallCount); dal.Deposit(200); Assert.AreEqual(1, countHandler.CallCount); }
public void ShouldNotUpdateExceptionsPerSecondByDefault() { ResetCounters(); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPerfMonPolicies()); MonitorTarget target = factory.Create <MonitorTarget>(); Assert.AreEqual(0L, GetExceptionsPerSecondCount(TestInstanceName)); CauseExceptions(target); Assert.AreEqual(0L, GetExceptionsPerSecondCount(TestInstanceName)); }
public void ShouldNotBeAbleToCastToUnimplementedInterfaces() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); IDal dal = factory.Create <MockDal, IDal>(); ICallHandler ch = dal as ICallHandler; Assert.IsNull(ch); }
public void CanCastAcrossInterfaces() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); IDal dal = factory.Create <MockDal, IDal>(); IMonitor monitor = dal as IMonitor; Assert.IsNotNull(monitor); }
public void ShouldDefaultToDisableExceptionCounter() { ResetCounters(); RemotingPolicyInjector factory = new RemotingPolicyInjector(GetPerfMonPolicies()); MonitorTarget target = factory.Create <MonitorTarget>(); Assert.AreEqual(0L, GetNumberOfExceptionsCount(TestInstanceName)); CauseExceptions(target); Assert.AreEqual(0L, GetNumberOfExceptionsCount(TestInstanceName)); }
public void CanCastToImplementedInterfaces() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); MockDal dal = factory.Create <MockDal>(); IDal iDal = dal as IDal; Assert.IsNotNull(iDal); }
public void CanRewrapAnInterceptedObject() { RemotingPolicyInjector factory = new RemotingPolicyInjector(new PolicySet(GetCallCountingPolicy())); IDal dal = factory.Create <MockDal, IDal>(); object dalTarget = ((InterceptingRealProxy)RemotingServices.GetRealProxy(dal)).Target; IMonitor monitor = factory.Wrap <IMonitor>(dal); object monitorTarget = ((InterceptingRealProxy)RemotingServices.GetRealProxy(monitor)).Target; Assert.AreSame(dalTarget, monitorTarget); }
public void ShouldNotInterceptMethodsThatHaveNoPolicyAttribute() { RemotingPolicyInjector factory = new RemotingPolicyInjector(); AddCallCountingDalPolicy(factory); MockDal dal = factory.Create <MockDal>(); Assert.IsTrue(RemotingServices.IsTransparentProxy(dal)); Assert.AreEqual(0, countHandler.CallCount); dal.SomethingCritical(); Assert.AreEqual(0, countHandler.CallCount); }
public void ShouldAddInterceptionAccordingToPolicy() { RemotingPolicyInjector factory = GetFactoryWithPolicies(); MockDal dal = factory.Create <MockDal>(); Assert.IsTrue(dal is MockDal); Assert.IsTrue(RemotingServices.IsTransparentProxy(dal)); object realProxy = RemotingServices.GetRealProxy(dal); Assert.IsNotNull(realProxy); Assert.IsTrue(realProxy is InterceptingRealProxy); }