예제 #1
0
        public void ValidateSettingsTest()
        {
            // Arrange
            string iotHubHostName      = "foo.azure-devices.net";
            var    authenticator       = Mock.Of <IAuthenticator>();
            var    identityFactory     = Mock.Of <IClientCredentialsFactory>();
            var    linkHandlerProvider = Mock.Of <ILinkHandlerProvider>();
            var    connectionProvider  = Mock.Of <IConnectionProvider>();

            // Act
            AmqpSettings settings = AmqpSettingsProvider.GetDefaultAmqpSettings(iotHubHostName, authenticator, identityFactory, linkHandlerProvider, connectionProvider, new NullCredentialsCache());

            // Assert
            Assert.NotNull(settings);
            Assert.Equal(2, settings.TransportProviders.Count);

            var saslTransportProvider = settings.GetTransportProvider <SaslTransportProvider>();

            Assert.NotNull(saslTransportProvider);

            SaslHandler anonHandler = saslTransportProvider.GetHandler("ANONYMOUS", false);

            Assert.NotNull(anonHandler);

            SaslHandler plainHandler = saslTransportProvider.GetHandler("PLAIN", false);

            Assert.NotNull(plainHandler);

            SaslHandler cbsHandler = saslTransportProvider.GetHandler(Amqp.Constants.ServiceBusCbsSaslMechanismName, false);

            Assert.NotNull(cbsHandler);

            var amqpTransportProvider = settings.GetTransportProvider <AmqpTransportProvider>();

            Assert.NotNull(amqpTransportProvider);

            Assert.Equal(Amqp.Constants.AmqpVersion100, amqpTransportProvider.Versions[0]);
        }
예제 #2
0
        protected override void Load(ContainerBuilder builder)
        {
            // ITransportSettings
            builder.Register(
                async c =>
            {
                IClientCredentialsFactory clientCredentialsProvider = c.Resolve <IClientCredentialsFactory>();
                IAuthenticator authenticator = await c.Resolve <Task <IAuthenticator> >();
                ITransportSettings settings  = new DefaultTransportSettings(this.scheme, HostName, this.port, this.tlsCertificate, this.clientCertAuthAllowed, authenticator, clientCredentialsProvider);
                return(settings);
            })
            .As <Task <ITransportSettings> >()
            .SingleInstance();

            // ITransportListenerProvider
            builder.Register(c => new AmqpTransportListenerProvider())
            .As <ITransportListenerProvider>()
            .SingleInstance();

            // ILinkHandlerProvider
            builder.Register(
                c =>
            {
                IMessageConverter <AmqpMessage> messageConverter             = new AmqpMessageConverter();
                IMessageConverter <AmqpMessage> twinMessageConverter         = new AmqpTwinMessageConverter();
                IMessageConverter <AmqpMessage> directMethodMessageConverter = new AmqpDirectMethodMessageConverter();
                var identityProvider = c.Resolve <IIdentityProvider>();
                var productInfoStore = c.Resolve <IProductInfoStore>();
                ILinkHandlerProvider linkHandlerProvider = new LinkHandlerProvider(messageConverter, twinMessageConverter, directMethodMessageConverter, identityProvider, productInfoStore);
                return(linkHandlerProvider);
            })
            .As <ILinkHandlerProvider>()
            .SingleInstance();

            // Task<AmqpProtocolHead>
            builder.Register(
                async c =>
            {
                var identityFactory                    = c.Resolve <IClientCredentialsFactory>();
                var transportSettingsTask              = c.Resolve <Task <ITransportSettings> >();
                var transportListenerProvider          = c.Resolve <ITransportListenerProvider>();
                var linkHandlerProvider                = c.Resolve <ILinkHandlerProvider>();
                var credentialsCacheTask               = c.Resolve <Task <ICredentialsCache> >();
                var authenticatorTask                  = c.Resolve <Task <IAuthenticator> >();
                var connectionProviderTask             = c.Resolve <Task <IConnectionProvider> >();
                ICredentialsCache credentialsCache     = await credentialsCacheTask;
                IAuthenticator authenticator           = await authenticatorTask;
                IConnectionProvider connectionProvider = await connectionProviderTask;
                ITransportSettings transportSettings   = await transportSettingsTask;
                var webSocketListenerRegistry          = c.Resolve <IWebSocketListenerRegistry>();
                AmqpSettings amqpSettings              = AmqpSettingsProvider.GetDefaultAmqpSettings(
                    this.iotHubHostName,
                    authenticator,
                    identityFactory,
                    linkHandlerProvider,
                    connectionProvider,
                    credentialsCache);

                return(new AmqpProtocolHead(
                           transportSettings,
                           amqpSettings,
                           transportListenerProvider,
                           webSocketListenerRegistry,
                           authenticator,
                           identityFactory));
            })
            .As <Task <AmqpProtocolHead> >()
            .SingleInstance();

            base.Load(builder);
        }