public IHttpHandler GetHttpHandler(RequestContext requestContext) { var factory = new PersistentConnectionFactory(_resolver); PersistentConnection connection = factory.CreateInstance(_handlerType); return(new AspNetHandler(_resolver, connection)); }
public IHttpHandler GetHttpHandler(RequestContext requestContext) { var factory = new PersistentConnectionFactory(_resolver); PersistentConnection connection = factory.CreateInstance(_handlerType); return new AspNetHandler(_resolver, connection); }
public bool TryGetConnection(string path, out PersistentConnection connection) { if (path == null) { throw new ArgumentNullException("path"); } connection = null; if (!String.IsNullOrEmpty(_hubPath) && path.StartsWith(_hubPath, StringComparison.OrdinalIgnoreCase)) { connection = new HubDispatcher(_hubPath); return(true); } foreach (var pair in _connectionMapping) { // If the url matches then create the connection type if (path.StartsWith(pair.Key, StringComparison.OrdinalIgnoreCase)) { var factory = new PersistentConnectionFactory(_resolver); connection = factory.CreateInstance(pair.Value); return(true); } } return(false); }
public void ThrowsIfTypeIsNotPersistentConnection() { // Arrange var resolver = new Mock <IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); // Act & Assert Assert.Throws <InvalidOperationException>(() => factory.CreateInstance(typeof(PersistentConnectionFactoryFacts))); }
public void ThrowsIfTypeIsNull() { // Arrange var resolver = new Mock <IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); // Act & Assert Assert.Throws <ArgumentNullException>(() => factory.CreateInstance(null)); }
public void ThrowsIfTypeIsNotPersistentConnection() { // Arrange var resolver = new Mock<IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); // Act & Assert Assert.Throws<InvalidOperationException>(() => factory.CreateInstance(typeof(PersistentConnectionFactoryFacts))); }
public void ThrowsIfTypeIsNull() { // Arrange var resolver = new Mock<IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); // Act & Assert Assert.Throws<ArgumentNullException>(() => factory.CreateInstance(null)); }
/// <summary> /// Sends all requests to a PersistentConnection type. RunSignalR should be used as the last item in a pipeline, or /// inside a Map statement. /// </summary> /// <typeparam name="T">PersistentConnection type to expose</typeparam> /// <param name="builder"></param> /// <param name="resolver">Used by components to acquire the services they depend on</param> /// <returns></returns> public static IAppBuilder RunSignalR <T>(this IAppBuilder builder, IDependencyResolver resolver) where T : PersistentConnection { return(builder.Use <AppDelegate>(_ => ExecuteConnection(env => { var factory = new PersistentConnectionFactory(resolver); var connection = factory.CreateInstance(typeof(T)); connection.Initialize(resolver); return connection; }))); }
public void CreatesInstanceIfTypeIsPersistentConnection() { // Arrange var resolver = new Mock<IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); // Act PersistentConnection connection = factory.CreateInstance(typeof(MyConnection)); // Assert Assert.NotNull(connection); }
public void CreatesInstanceIfTypeIsPersistentConnection() { // Arrange var resolver = new Mock <IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); // Act PersistentConnection connection = factory.CreateInstance(typeof(MyConnection)); // Assert Assert.NotNull(connection); }
public Task Invoke(IDictionary<string, object> environment) { var path = environment.Get<string>(OwinConstants.RequestPath); if (path == null || !path.StartsWith(_path, StringComparison.OrdinalIgnoreCase)) { return _app.Invoke(environment); } var connectionFactory = new PersistentConnectionFactory(_resolver); var connection = connectionFactory.CreateInstance(_connectionType); var handler = new CallHandler(_resolver, connection); return handler.Invoke(environment); }
public Task Invoke(IDictionary <string, object> environment) { var path = environment.Get <string>(OwinConstants.RequestPath); if (path == null || !path.StartsWith(_path, StringComparison.OrdinalIgnoreCase)) { return(_app.Invoke(environment)); } var connectionFactory = new PersistentConnectionFactory(_resolver); var connection = connectionFactory.CreateInstance(_connectionType); var handler = new CallHandler(_resolver, connection); return(handler.Invoke(environment)); }
public void UsesDependencyResolver() { // Arrange var resolver = new Mock<IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); var otherConnection = new MyOtherConnection(); resolver.Setup(m => m.GetService(typeof(MyConnection))) .Returns(otherConnection); // Act PersistentConnection connection = factory.CreateInstance(typeof(MyConnection)); // Assert Assert.NotNull(connection); Assert.Same(otherConnection, connection); }
public Task Invoke(IDictionary <string, object> environment) { var path = environment.Get <string>(OwinConstants.RequestPath); if (path == null || !PrefixMatcher.IsMatch(_path, path)) { return(_next(environment)); } var connectionFactory = new PersistentConnectionFactory(_configuration.Resolver); var connection = connectionFactory.CreateInstance(_connectionType); var handler = new CallHandler(_configuration, connection); return(handler.Invoke(environment)); }
public void UsesDependencyResolver() { // Arrange var resolver = new Mock <IDependencyResolver>(); var factory = new PersistentConnectionFactory(resolver.Object); var otherConnection = new MyOtherConnection(); resolver.Setup(m => m.GetService(typeof(MyConnection))) .Returns(otherConnection); // Act PersistentConnection connection = factory.CreateInstance(typeof(MyConnection)); // Assert Assert.NotNull(connection); Assert.Same(otherConnection, connection); }
public AdvancedBusEventHandlersTests() { advancedBusEventHandlers = new AdvancedBusEventHandlers( connected: (s, e) => connectedCalled = true, disconnected: (s, e) => disconnectedCalled = true, blocked: (s, e) => { blockedCalled = true; connectionBlockedEventArgs = e; }, unblocked: (s, e) => unBlockedCalled = true, messageReturned: (s, e) => { messageReturnedCalled = true; messageReturnedEventArgs = e; }); var connectionFactory = Substitute.For <IConnectionFactory>(); connectionFactory.Succeeded.Returns(true); connectionFactory.CreateConnection().Returns(Substitute.For <IConnection>()); connectionFactory.CurrentHost.Returns(new HostConfiguration()); connectionFactory.Configuration.Returns(new ConnectionConfiguration()); eventBus = new EventBus(); var logger = Substitute.For <IEasyNetQLogger>(); var persistentConnectionFactory = new PersistentConnectionFactory(logger, connectionFactory, eventBus); var advancedBus = new RabbitAdvancedBus( connectionFactory, Substitute.For <IConsumerFactory>(), logger, Substitute.For <IClientCommandDispatcherFactory>(), Substitute.For <IPublishConfirmationListener>(), eventBus, Substitute.For <IHandlerCollectionFactory>(), Substitute.For <IContainer>(), Substitute.For <ConnectionConfiguration>(), Substitute.For <IProduceConsumeInterceptor>(), Substitute.For <IMessageSerializationStrategy>(), Substitute.For <IConventions>(), advancedBusEventHandlers, persistentConnectionFactory); }
public void SetUp() { advancedBusEventHandlers = new AdvancedBusEventHandlers( connected: (s, e) => connectedCalled = true, disconnected: (s, e) => disconnectedCalled = true, blocked: (s, e) => { blockedCalled = true; connectionBlockedEventArgs = e; }, unblocked: (s, e) => unBlockedCalled = true, messageReturned: (s, e) => { messageReturnedCalled = true; messageReturnedEventArgs = e; }); var connectionFactory = MockRepository.GenerateStub <IConnectionFactory>(); connectionFactory.Stub(x => x.Succeeded).Return(true); connectionFactory.Stub(x => x.CreateConnection()).Return(MockRepository.GenerateStub <IConnection>()); connectionFactory.Stub(x => x.CurrentHost).Return(new HostConfiguration()); connectionFactory.Stub(x => x.Configuration).Return(new ConnectionConfiguration()); eventBus = new EventBus(); var logger = MockRepository.GenerateStub <IEasyNetQLogger>(); var persistentConnectionFactory = new PersistentConnectionFactory(logger, connectionFactory, eventBus); var advancedBus = new RabbitAdvancedBus( connectionFactory, MockRepository.GenerateStub <IConsumerFactory>(), logger, MockRepository.GenerateStub <IClientCommandDispatcherFactory>(), MockRepository.GenerateStub <IPublishConfirmationListener>(), eventBus, MockRepository.GenerateStub <IHandlerCollectionFactory>(), MockRepository.GenerateStub <IContainer>(), MockRepository.GenerateStub <ConnectionConfiguration>(), MockRepository.GenerateStub <IProduceConsumeInterceptor>(), MockRepository.GenerateStub <IMessageSerializationStrategy>(), MockRepository.GenerateStub <IConventions>(), advancedBusEventHandlers, persistentConnectionFactory); }
public override Task Invoke(IOwinContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (JsonUtility.TryRejectJSONPRequest(_configuration, context)) { return(TaskAsyncHelper.Empty); } var connectionFactory = new PersistentConnectionFactory(_configuration.Resolver); PersistentConnection connection = connectionFactory.CreateInstance(_connectionType); connection.Initialize(_configuration.Resolver); return(connection.ProcessRequest(context.Environment)); }
public void SetUp() { advancedBusEventHandlers = new AdvancedBusEventHandlers( connected: (s, e) => connectedCalled = true, disconnected: (s, e) => disconnectedCalled = true, blocked: (s, e) => { blockedCalled = true; connectionBlockedEventArgs = e; }, unblocked: (s, e) => unBlockedCalled = true, messageReturned: (s, e) => { messageReturnedCalled = true; messageReturnedEventArgs = e; }); var connectionFactory = MockRepository.GenerateStub<IConnectionFactory>(); connectionFactory.Stub(x => x.Succeeded).Return(true); connectionFactory.Stub(x => x.CreateConnection()).Return(MockRepository.GenerateStub<IConnection>()); connectionFactory.Stub(x => x.CurrentHost).Return(new HostConfiguration()); connectionFactory.Stub(x => x.Configuration).Return(new ConnectionConfiguration()); eventBus = new EventBus(); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); var persistentConnectionFactory = new PersistentConnectionFactory(logger, connectionFactory, eventBus); var advancedBus = new RabbitAdvancedBus( connectionFactory, MockRepository.GenerateStub<IConsumerFactory>(), logger, MockRepository.GenerateStub<IClientCommandDispatcherFactory>(), MockRepository.GenerateStub<IPublishConfirmationListener>(), eventBus, MockRepository.GenerateStub<IHandlerCollectionFactory>(), MockRepository.GenerateStub<IContainer>(), MockRepository.GenerateStub<ConnectionConfiguration>(), MockRepository.GenerateStub<IProduceConsumeInterceptor>(), MockRepository.GenerateStub<IMessageSerializationStrategy>(), MockRepository.GenerateStub<IConventions>(), advancedBusEventHandlers, persistentConnectionFactory); }