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