コード例 #1
0
        public void BasicConnectionFactory_WhenConstructed_ThenDetailsSet()
        {
            // Arrange
            string hostname = "127.0.0.1";
            string username = "******";
            string password = "******";
            SecureConnectionSettings settings = GetSecureConnectionSettings();

            // Act
            BasicConnectionFactory basicConnectionFactory = new BasicConnectionFactory(
                hostname,
                username,
                password,
                settings);

            // Assert
            Assert.Equal(hostname, basicConnectionFactory.HostName);
            Assert.Equal(username, basicConnectionFactory.UserName);
            Assert.Equal(password, basicConnectionFactory.Password);
            Assert.True(basicConnectionFactory.Ssl.Enabled);
            Assert.Equal(settings.ServerName, basicConnectionFactory.Ssl.ServerName);
            Assert.Equal(settings.CertPath, basicConnectionFactory.Ssl.CertPath);
            Assert.Equal(settings.CertPassphrase, basicConnectionFactory.Ssl.CertPassphrase);
            Assert.Equal(settings.Protocol, basicConnectionFactory.Ssl.Version);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: cjshelton/RabbitMQDemo
        static void Main(string[] args)
        {
            // Dependencies.
            IDateTimeGenerator       dateTimeGenerator        = new DateTimeGenerator();
            ITypeConverter           typeConverter            = new TypeConverter();
            ExternalMechanismFactory externalMechanismFactory = new ExternalMechanismFactory();

            SecureConnectionSettings connectionSettings = new SecureConnectionSettings(
                "raspberrypi",
                "/path/to/client/certificate.p12",
                "password");

            ExternalAuthConnectionFactory sslAuthConnectionFactory = new ExternalAuthConnectionFactory(
                "raspberrypi",
                externalMechanismFactory,
                connectionSettings);

            Settings producingSettings = new Settings("Journeys", "journey");

            // Generate journey message.
            Journey            journey = new Journey(150, 35.5, 121.3, "Weather was wet and windy.");
            IMessage <Journey> message = new Message <Journey>(dateTimeGenerator, journey);

            // Produce the message.
            using IMessageProducer messageProducer = new MessageProducer(sslAuthConnectionFactory, typeConverter);
            messageProducer.Produce(producingSettings, message);

            Console.WriteLine($"Message sent. ID: {message.Data.Id}");
            Console.ReadLine();
        }
コード例 #3
0
        public void SecureConnectionSettings_WhenProtocolNotSupplied_ThenDefaultProtocolSet()
        {
            // Arrange
            const SslProtocols DEFAULT_PROTOCOL = SslProtocols.Tls12;
            const string       serverName       = "localhost";
            const string       certPath         = "/path/to/cert";
            const string       certPassphrase   = "password";

            // Act
            SecureConnectionSettings secureConnectionSettings = new SecureConnectionSettings(
                serverName,
                certPath,
                certPassphrase);

            // Assert
            Assert.Equal(DEFAULT_PROTOCOL, secureConnectionSettings.Protocol);
        }
コード例 #4
0
        public void ExternalAuthConnectionFactory_WhenHostNameIsNotSupplied_ThenArgumentException(string hostname)
        {
            // Arrange
            SecureConnectionSettings settings = GetSecureConnectionSettings();
            ExternalMechanismFactory externalMechanismFactory = new ExternalMechanismFactory();

            // Act
            void instantiation()
            {
                ExternalAuthConnectionFactory externalAuthConnectionFactory = new ExternalAuthConnectionFactory(
                    hostname,
                    externalMechanismFactory,
                    settings);
            }

            // Assert
            Assert.Throws <ArgumentException>(instantiation);
        }
コード例 #5
0
        public void ExternalAuthConnectionFactory_WhenConstructed_ThenExternalAuthMechanismSet()
        {
            // Arrange
            string hostname = "127.0.0.1";
            SecureConnectionSettings settings = GetSecureConnectionSettings();
            ExternalMechanismFactory externalMechanismFactory = new ExternalMechanismFactory();

            // Act
            ExternalAuthConnectionFactory externalAuthConnectionFactory = new ExternalAuthConnectionFactory(
                hostname,
                externalMechanismFactory,
                settings);

            // Assert
            Assert.NotNull(externalAuthConnectionFactory.AuthMechanisms);
            Assert.Single(externalAuthConnectionFactory.AuthMechanisms);
            Assert.Same(externalMechanismFactory, externalAuthConnectionFactory.AuthMechanisms.First());
        }
コード例 #6
0
        public void ExternalAuthConnectionFactory_WhenExternalAuthMechanismNotSupplied_ThenArgumentNullException()
        {
            // Arrange
            string hostname = "127.0.0.1";
            SecureConnectionSettings settings = GetSecureConnectionSettings();
            ExternalMechanismFactory externalMechanismFactory = null;

            // Act
            void instantiation()
            {
                ExternalAuthConnectionFactory externalAuthConnectionFactory = new ExternalAuthConnectionFactory(
                    hostname,
                    externalMechanismFactory,
                    settings);
            }

            // Assert
            Assert.Throws <ArgumentNullException>(instantiation);
        }
コード例 #7
0
        public void SecureConnectionSettings_WhenPortNotSupplied_ThenDefaultPortSet()
        {
            // Arrange
            const int          DEFAULT_PORT   = 5671;
            const string       serverName     = "localhost";
            const string       certPath       = "/path/to/cert";
            const string       certPassphrase = "password";
            const SslProtocols protocol       = SslProtocols.Tls12;

            // Act
            SecureConnectionSettings secureConnectionSettings = new SecureConnectionSettings(
                serverName,
                certPath,
                certPassphrase,
                protocol);

            // Assert
            Assert.Equal(DEFAULT_PORT, secureConnectionSettings.Port);
        }
コード例 #8
0
        public void BasicConnectionFactory_WhenPasswordIsNotSupplied_ThenArgumentException(string password)
        {
            // Arrange
            string hostname = "127.0.0.1";
            string username = "******";
            SecureConnectionSettings settings = GetSecureConnectionSettings();

            // Act
            void instantiation()
            {
                BasicConnectionFactory basicConnectionFactory = new BasicConnectionFactory(
                    hostname,
                    username,
                    password,
                    settings);
            }

            // Assert
            Assert.Throws <ArgumentException>(instantiation);
        }
コード例 #9
0
        public void ExternalAuthConnectionFactory_WhenConstructed_ThenDetailsSet()
        {
            // Arrange
            string hostname = "127.0.0.1";
            SecureConnectionSettings settings = GetSecureConnectionSettings();
            ExternalMechanismFactory externalMechanismFactory = new ExternalMechanismFactory();

            // Act
            ExternalAuthConnectionFactory externalAuthConnectionFactory = new ExternalAuthConnectionFactory(
                hostname,
                externalMechanismFactory,
                settings);

            // Assert
            Assert.Equal(hostname, externalAuthConnectionFactory.HostName);
            Assert.True(externalAuthConnectionFactory.Ssl.Enabled);
            Assert.Equal(settings.ServerName, externalAuthConnectionFactory.Ssl.ServerName);
            Assert.Equal(settings.CertPath, externalAuthConnectionFactory.Ssl.CertPath);
            Assert.Equal(settings.CertPassphrase, externalAuthConnectionFactory.Ssl.CertPassphrase);
            Assert.Equal(settings.Protocol, externalAuthConnectionFactory.Ssl.Version);
        }
コード例 #10
0
        public void SecureConnectionSettings_WhenPortOutOfBounds_ThenArgumentException(int port)
        {
            // Arrange
            const string serverName     = "localhost";
            const string certPath       = "/path/to/cert";
            const string certPassphrase = "password";

            // Act
            // Act
            void instantiation()
            {
                SecureConnectionSettings secureConnectionSettings = new SecureConnectionSettings(
                    serverName,
                    certPath,
                    certPassphrase,
                    port);
            }

            // Assert
            Assert.Throws <ArgumentException>(instantiation);
        }
コード例 #11
0
        public void SecureConnectionSettings_WhenCertPassphraseNotSupplied_ThenArgumentException(string certPassphrase)
        {
            // Arrange
            const string       serverName = "localhost";
            const string       certPath   = "/path/to/cert";
            const int          port       = 1;
            const SslProtocols protocol   = SslProtocols.Tls12;

            // Act
            void instantiation()
            {
                SecureConnectionSettings secureConnectionSettings = new SecureConnectionSettings(
                    serverName,
                    certPath,
                    certPassphrase,
                    port,
                    protocol);
            }

            // Assert
            Assert.Throws <ArgumentException>(instantiation);
        }
コード例 #12
0
        public void SecureConnectionSettings_WhenProtocolInvalid_ThenArgumentException()
        {
            // Arrange
            const SslProtocols INVALID_PROTOCOL = (SslProtocols)100;
            const string       serverName       = "localhost";
            const string       certPath         = "/path/to/cert";
            const string       certPassphrase   = "password";

            // Act
            // Act
            void instantiation()
            {
                SecureConnectionSettings secureConnectionSettings = new SecureConnectionSettings(
                    serverName,
                    certPath,
                    certPassphrase,
                    INVALID_PROTOCOL);
            }

            // Assert
            Assert.Throws <ArgumentException>(instantiation);
        }
コード例 #13
0
        public void SecureConnectionSettings_WhenConstructed_ThenConnectionDetailsSet()
        {
            // Arrange
            const string       serverName     = "localhost";
            const string       certPath       = "/path/to/cert";
            const string       certPassphrase = "password";
            const int          port           = 1;
            const SslProtocols protocol       = SslProtocols.Tls12;

            // Act
            SecureConnectionSettings secureConnectionSettings = new SecureConnectionSettings(
                serverName,
                certPath,
                certPassphrase,
                port,
                protocol);

            // Assert
            Assert.Equal(serverName, secureConnectionSettings.ServerName);
            Assert.Equal(certPath, secureConnectionSettings.CertPath);
            Assert.Equal(certPassphrase, secureConnectionSettings.CertPassphrase);
            Assert.Equal(port, secureConnectionSettings.Port);
            Assert.Equal(protocol, secureConnectionSettings.Protocol);
        }