public void InvalidInputsTest()
        {
            Assert.Throws <ArgumentException>(() => new ModuleConnectionStringBuilder(null, "1"));
            Assert.Throws <ArgumentException>(() => new ModuleConnectionStringBuilder("", "1"));
            Assert.Throws <ArgumentException>(() => new ModuleConnectionStringBuilder("iothub", null));
            Assert.Throws <ArgumentException>(() => new ModuleConnectionStringBuilder("iothub", ""));

            var builder = new ModuleConnectionStringBuilder("foo.azure.com", "device1");

            Assert.Throws <ArgumentException>(() => builder.Create(null));
            Assert.Throws <ArgumentException>(() => builder.Create("m1").WithGatewayHostName(null));
            Assert.Throws <ArgumentException>(() => builder.Create("m1").WithSharedAccessKey(null));
        }
        public void ImplicitOperatorTest()
        {
            // Arrange/Act
            var    builder          = new ModuleConnectionStringBuilder("foo.azure.com", "device1");
            string connectionString = builder.Create("module1")
                                      .WithGatewayHostName("localhost");

            Assert.Equal("HostName=foo.azure.com;DeviceId=device1;ModuleId=module1;GatewayHostName=localhost", connectionString);
        }
        public void CreateConnectionStringTest(string expectedConnectionString, string iotHubHostName, string deviceId, string moduleId, string sasKey = null, string gatewayHostName = null)
        {
            // Arrange
            var builder = new ModuleConnectionStringBuilder(iotHubHostName, deviceId);

            ModuleConnectionStringBuilder.ModuleConnectionString moduleConnectionString = builder.Create(moduleId);

            if (!string.IsNullOrEmpty(sasKey))
            {
                moduleConnectionString.WithSharedAccessKey(sasKey);
            }

            if (!string.IsNullOrEmpty(gatewayHostName))
            {
                moduleConnectionString.WithGatewayHostName(gatewayHostName);
            }

            // Act
            string connectionString = moduleConnectionString.Build();

            // Assert
            Assert.Equal(expectedConnectionString, connectionString);
        }