Exemplo n.º 1
0
        public void DuplicateHubNamesThrows()
        {
            // Arrange
            var mockHub        = new Mock <IHub>();
            var mockHubManager = new Mock <IHubManager>();

            mockHubManager.Setup(m => m.GetHub("foo")).Returns(new HubDescriptor {
                Name = "foo", HubType = mockHub.Object.GetType()
            });

            var serviceProvider = new ServiceCollection()
                                  .Add(OptionsServices.GetDefaultServices())
                                  .Add(HostingServices.GetDefaultServices())
                                  .Add(SignalRServices.GetDefaultServices().Where(descriptor => descriptor.ServiceType != typeof(IHubManager)))
                                  .AddInstance <IHubManager>(mockHubManager.Object)
                                  .BuildServiceProvider();

            var dispatcher  = new HubDispatcher(serviceProvider.GetRequiredService <IOptions <SignalROptions> >());
            var testContext = new TestContext("/ignorePath", new Dictionary <string, string>
            {
                { "connectionData", @"[{name: ""foo""}, {name: ""Foo""}]" },
            });

            // Act & Assert
            dispatcher.Initialize(serviceProvider);
            Assert.Throws <InvalidOperationException>(() => dispatcher.Authorize(testContext.MockRequest.Object));
        }
Exemplo n.º 2
0
        public static IServiceProvider CreateServiceProvider(Action <IServiceCollection> configure)
        {
            var collection = new ServiceCollection()
                             .Add(OptionsServices.GetDefaultServices())
                             .Add(HostingServices.GetDefaultServices())
                             .Add(SignalRServices.GetDefaultServices());

            configure(collection);

            return(collection.BuildServiceProvider(CallContextServiceLocator.Locator.ServiceProvider));
        }
Exemplo n.º 3
0
        public static SignalRServiceCollection AddSignalR(this IServiceCollection services, Action <SignalROptions> configureOptions = null)
        {
            services.Add(SignalRServices.GetDefaultServices());
            var result = new SignalRServiceCollection(services);

            if (configureOptions != null)
            {
                result.Configure(configureOptions);
            }
            return(result);
        }
        public void GetHubContextRejectsInvalidTypes()
        {
            //var resolver = new DefaultDependencyResolver();
            var serviceProvider = new ServiceCollection()
                                  .Add(OptionsServices.GetDefaultServices())
                                  .Add(HostingServices.GetDefaultServices())
                                  .Add(SignalRServices.GetDefaultServices())
                                  .BuildServiceProvider(CallContextServiceLocator.Locator.ServiceProvider);

            var manager = serviceProvider.GetService <IConnectionManager>();

            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, IDontReturnVoidOrTask>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, IHaveOutParameter>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, IHaveRefParameter>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, IHaveProperties>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, IHaveIndexer>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, IHaveEvent>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, NotAnInterface>());
        }
 public static SignalRServiceCollection AddSignalR(this IServiceCollection services, IConfiguration configuration)
 {
     services.Add(SignalRServices.GetDefaultServices(configuration));
     return(new SignalRServiceCollection(services));
 }
 public static SignalRServiceCollection AddSignalR(this IServiceCollection services)
 {
     services.Add(SignalRServices.GetDefaultServices());
     return(new SignalRServiceCollection(services));
 }