public void MemberBasedBindingOfTypeDependencies() { IModule module = new InlineModule( m => m.Bind(typeof(ObjectWithMethodInterceptor)).ToSelf(), m => m.Intercept(When.Request.Method.Name.StartsWith("F")).With<CountInterceptor>() ); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get<ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Foo"), new object[0], Type.EmptyTypes ); ICollection<IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request); Assert.That(interceptors.Count, Is.EqualTo(2)); IEnumerator<IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); } }
public void StaticInterceptorsAreRegisteredFromAttributesDefinedOnMethods() { var module = new InlineModule(m => m.Bind<ObjectWithMethodInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get<ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Foo"), new object[0], Type.EmptyTypes ); ICollection<IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request); IEnumerator<IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(interceptors.Count, Is.EqualTo(1)); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); } }
public void StaticInterceptorsAreRegisteredFromAttributesDefinedOnClasses() { var module = new InlineModule(m => m.Bind <ObjectWithClassInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect <IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get <ObjectWithClassInterceptor>(); IContext context1 = kernel.Components.ContextFactory.Create(typeof(ObjectWithClassInterceptor)); IRequest request1 = new StandardRequest( context1, obj, typeof(ObjectWithClassInterceptor).GetMethod("Foo"), new object[0], Type.EmptyTypes ); var registry = kernel.Components.AdviceRegistry; ICollection <IInterceptor> interceptors1 = registry.GetInterceptors(request1); Assert.That(interceptors1.Count, Is.EqualTo(1)); IContext context2 = kernel.Components.ContextFactory.Create(typeof(ObjectWithClassInterceptor)); IRequest request2 = new StandardRequest( context2, obj, typeof(ObjectWithClassInterceptor).GetMethod("Bar"), new object[0], Type.EmptyTypes ); ICollection <IInterceptor> interceptors2 = registry.GetInterceptors(request2); Assert.That(interceptors2.Count, Is.EqualTo(1)); } }
public void StaticInterceptorsAreRegisteredFromAttributesDefinedOnClasses() { var module = new InlineModule(m => m.Bind<ObjectWithClassInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get<ObjectWithClassInterceptor>(); IContext context1 = kernel.Components.ContextFactory.Create(typeof(ObjectWithClassInterceptor)); IRequest request1 = new StandardRequest( context1, obj, typeof(ObjectWithClassInterceptor).GetMethod("Foo"), new object[0], Type.EmptyTypes ); var registry = kernel.Components.AdviceRegistry; ICollection<IInterceptor> interceptors1 = registry.GetInterceptors(request1); Assert.That(interceptors1.Count, Is.EqualTo(1)); IContext context2 = kernel.Components.ContextFactory.Create(typeof(ObjectWithClassInterceptor)); IRequest request2 = new StandardRequest( context2, obj, typeof(ObjectWithClassInterceptor).GetMethod("Bar"), new object[0], Type.EmptyTypes ); ICollection<IInterceptor> interceptors2 = registry.GetInterceptors(request2); Assert.That(interceptors2.Count, Is.EqualTo(1)); } }
public void ExoticDynamicInterceptionScenario() { int argument = 42; var module = new InlineModule( m => m.Bind(typeof(ObjectWithMethodInterceptor)).ToSelf(), m => m.Intercept(When.Request.Method.ReturnType.EqualTo(typeof(void))).With <CountInterceptor>(), m => m.Intercept(When.Request.Arguments.Contains(argument)).With <CountInterceptor>() ); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect <IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get <ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Baz"), new object[] { argument }, Type.EmptyTypes ); ICollection <IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request); Assert.That(interceptors.Count, Is.EqualTo(2)); IEnumerator <IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); } }
public void DynamicInterceptorsCanBeRegistered() { var module = new InlineModule(m => m.Bind <ObjectWithMethodInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect <IProxyFactory>(new DummyProxyFactory()); var factory = kernel.Components.AdviceFactory; var registry = kernel.Components.AdviceRegistry; IAdvice advice = factory.Create(new PredicateCondition <IRequest>(r => r.Method.Name.Equals("Bar"))); advice.Callback = r => r.Kernel.Get <FlagInterceptor>(); registry.Register(advice); var obj = kernel.Get <ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Bar"), new object[0], Type.EmptyTypes ); ICollection <IInterceptor> interceptors = registry.GetInterceptors(request); IEnumerator <IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(interceptors.Count, Is.EqualTo(1)); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(FlagInterceptor))); } }
public RequestResponseHandler() { _requestId = new RequestId(); _requests = new Awaiter <IRequest, BaseCommand>(); _getResponseIdentifier = new EnumLookup <BaseCommand.Type, Func <BaseCommand, IRequest> >(cmd => throw new Exception($"CommandType '{cmd.CommandType}' not supported as request/response type")); _getResponseIdentifier.Set(BaseCommand.Type.Connected, cmd => new ConnectRequest()); _getResponseIdentifier.Set(BaseCommand.Type.SendError, cmd => new SendRequest(cmd.SendError.ProducerId, cmd.SendError.SequenceId)); _getResponseIdentifier.Set(BaseCommand.Type.SendReceipt, cmd => new SendRequest(cmd.SendReceipt.ProducerId, cmd.SendReceipt.SequenceId)); _getResponseIdentifier.Set(BaseCommand.Type.ProducerSuccess, cmd => StandardRequest.WithRequestId(cmd.ProducerSuccess.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.CloseConsumer, cmd => StandardRequest.WithConsumerId(cmd.CloseConsumer.RequestId, cmd.CloseConsumer.ConsumerId)); _getResponseIdentifier.Set(BaseCommand.Type.CloseProducer, cmd => StandardRequest.WithProducerId(cmd.CloseProducer.RequestId, cmd.CloseProducer.ProducerId)); _getResponseIdentifier.Set(BaseCommand.Type.LookupResponse, cmd => StandardRequest.WithRequestId(cmd.LookupTopicResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.PartitionedMetadataResponse, cmd => StandardRequest.WithRequestId(cmd.PartitionMetadataResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.GetLastMessageIdResponse, cmd => StandardRequest.WithRequestId(cmd.GetLastMessageIdResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.GetOrCreateSchemaResponse, cmd => StandardRequest.WithRequestId(cmd.GetOrCreateSchemaResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.Success, cmd => StandardRequest.WithRequestId(cmd.Success.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.Error, cmd => !_requestId.IsPastInitialId() ? new ConnectRequest() : StandardRequest.WithRequestId(cmd.Error.RequestId)); }
public Task <BaseCommand> Outgoing(CommandGetLastMessageId command) { command.RequestId = _requestId.FetchNext(); return(_requests.CreateTask(StandardRequest.WithRequestId(command.RequestId))); }
public Task <BaseCommand> Outgoing(CommandSeek command) { command.RequestId = _requestId.FetchNext(); return(_requests.CreateTask(StandardRequest.WithConsumerId(command.RequestId, command.ConsumerId, BaseCommand.Type.Seek))); }
public Task <BaseCommand> Outgoing(CommandPartitionedTopicMetadata command) { command.RequestId = _requestId.FetchNext(); return(_requests.CreateTask(StandardRequest.WithRequestId(command.RequestId))); }
public Task <BaseCommand> Outgoing(CommandLookupTopic command) { command.RequestId = _requestId.FetchNext(); return(_requests.CreateTask(StandardRequest.WithRequestId(command.RequestId))); }
public void ExoticDynamicInterceptionScenario() { int argument = 42; var module = new InlineModule( m => m.Bind(typeof(ObjectWithMethodInterceptor)).ToSelf(), m => m.Intercept(When.Request.Method.ReturnType.EqualTo(typeof(void))).With<CountInterceptor>(), m => m.Intercept(When.Request.Arguments.Contains(argument)).With<CountInterceptor>() ); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get<ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Baz"), new object[] { argument }, Type.EmptyTypes ); ICollection<IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request); Assert.That(interceptors.Count, Is.EqualTo(2)); IEnumerator<IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); } }
public void Exists() { var req = new StandardRequest(); }
public void StandardRequestInheritsRequestBase() { var request = new StandardRequest(); Assert.IsAssignableFrom <StandardRequestBase>(request); }
public void InterceptorsAreReturnedInAscendingOrder() { var module = new InlineModule(m => m.Bind<ObjectWithMethodInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory()); var factory = kernel.Components.AdviceFactory; var registry = kernel.Components.AdviceRegistry; IAdvice advice = factory.Create(new PredicateCondition<IRequest>(r => r.Method.Name.Equals("Foo"))); advice.Callback = r => r.Kernel.Get<FlagInterceptor>(); advice.Order = -1; registry.Register(advice); var obj = kernel.Get<ObjectWithMethodInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithMethodInterceptor).GetMethod("Foo"), new object[0], Type.EmptyTypes ); ICollection<IInterceptor> interceptors = registry.GetInterceptors(request); Assert.That(interceptors.Count, Is.EqualTo(2)); IEnumerator<IInterceptor> enumerator = interceptors.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(FlagInterceptor))); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor))); } }
public void StaticInterceptorsNotRegisteredForMethodsDecoratedWithDoNotInterceptAttribute() { var module = new InlineModule(m => m.Bind<ObjectWithClassInterceptor>().ToSelf()); using (var kernel = new StandardKernel(module)) { kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory()); var obj = kernel.Get<ObjectWithClassInterceptor>(); IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithClassInterceptor)); IRequest request = new StandardRequest( context, obj, typeof(ObjectWithClassInterceptor).GetMethod("Baz"), new object[0], Type.EmptyTypes ); ICollection<IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request); Assert.That(interceptors.Count, Is.EqualTo(0)); } }