Ejemplo n.º 1
0
        private void continueButton_Click(object sender, EventArgs e)
        {
            if (!ValidationManager.Validate(this))
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                "All fields need to have a value.", PopupButtons.Ok);
                return;
            }

            try
            {
                var assembly = Assembly.LoadFrom(assemblyFilePathTextBox.Text);
                if (ServiceProviderHelper.CreateServiceProvider(assembly) == null)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while creating a service provider.",
                                    "The selected assembly doesn't contain any types that are marked with the TransferServiceProvider-attribute.", PopupButtons.Ok);
                    return;
                }
            }
            catch (Exception ex)
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Error while creating a service provider.",
                                ex, PopupButtons.Ok);
                return;
            }

            DialogResult = DialogResult.OK;
        }
 private static IServiceProvider CreateServiceProvider()
 {
     return(ServiceProviderHelper.CreateServiceProvider(services =>
     {
         services.AddTransient <IProtectedData, EmptyProtectedData>();
         services.AddTransient <ErrorHub>();
     }));
 }
        public void GetHubContextRejectsInvalidTypes()
        {
            //var resolver = new DefaultDependencyResolver();
            var serviceProvider = ServiceProviderHelper.CreateServiceProvider();

            var manager = serviceProvider.GetRequiredService <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, IAmDerivedFromInvalidInterface>());
            Assert.Throws <InvalidOperationException>(() => manager.GetHubContext <DemoHub, NotAnInterface>());
        }
Ejemplo n.º 4
0
        public void TypedHubContextServiceCallsConnectionManagerCorrectly()
        {
            var mockConnectionManager = new Mock <IConnectionManager>(MockBehavior.Strict);
            var testContext           = Mock.Of <IHubContext <TypedContextHub, IClient> >();

            mockConnectionManager.Setup(m => m.GetHubContext <TypedContextHub, IClient>()).Returns(testContext);

            var sp = ServiceProviderHelper.CreateServiceProvider(sc =>
            {
                sc.AddSingleton <IConnectionManager>(mockConnectionManager.Object);
            });

            var returnedContext = sp.GetRequiredService <IHubContext <TypedContextHub, IClient> >();

            Assert.Same(testContext.Clients, returnedContext.Clients);
            Assert.Same(testContext.Clients, returnedContext.Clients);
            mockConnectionManager.VerifyAll();
        }
Ejemplo n.º 5
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 = ServiceProviderHelper.CreateServiceProvider(services => services.AddInstance(mockHubManager.Object));

            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));
        }