public void createGamblerServerInterface() { // create an instance of the service Service = new MyGamblerService(gambler); // start a JSON-RPC server; all methods tagged with the [JsonRpcMethod] attribute // will be invokable remotely; all requests as well as all responses will be // passed on to the interceptor; please note that the server will // automatically expose an additional method to control how requests will be // processed; // pass a simple interceptor, which simply prints all intercepted requests // and responses // This creates an Interceptor that has the two functions interceptRequest and interceptResponse //Follwoing the code for an Interceptor which simply prints all intercepted requests // and responses, just for illustration purposes Interceptor interceptor = new SampleInterceptor(); gamblerSocketListener = null; try { // launch a socket listener accepting and handling JSON-RPC requests gamblerSocketListener = new SocketListener(gambler.PortNo, interceptor); } catch (IOException e) { Console.WriteLine(e.ToString()); } if (gamblerSocketListener != null) { socketListeningThread = new Thread(new ThreadStart(gamblerSocketListener.start)); socketListeningThread.IsBackground = true; socketListeningThread.Start(); } }
public void ShouldNotInvokeMethodBodyReplacementIfInterceptionIsDisabled() { var sampleInterceptor = new SampleInterceptor(); var sampleProvider = new SampleMethodReplacementProvider(sampleInterceptor); Action <object> condition = (instance) => { Assert.IsNotNull(instance); Assert.IsTrue(instance is IModifiableType); var modifiableType = (IModifiableType)instance; modifiableType.MethodBodyReplacementProvider = sampleProvider; modifiableType.IsInterceptionDisabled = true; instance.Invoke("DoSomething"); }; Test(condition); Assert.IsFalse(sampleInterceptor.HasBeenInvoked); }
public void ShouldNotInvokeClassMethodReplacementProviderIfInterceptionIsDisabled() { var sampleInterceptor = new SampleInterceptor(); var sampleProvider = new SampleMethodReplacementProvider(sampleInterceptor); MethodBodyReplacementProviderRegistry.SetProvider(sampleProvider); Action <object> condition = instance => { Assert.NotNull(instance); var modified = (IModifiableType)instance; modified.IsInterceptionDisabled = true; instance.Invoke("DoSomething"); Assert.False(sampleInterceptor.HasBeenInvoked); }; Test(condition); }