public async Task TransparentGateway(
            [Values] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            CancellationToken token = this.TestToken;

            await this.runtime.DeployConfigurationAsync(token, Context.Current.NestedEdge);

            string leafDeviceId = DeviceId.Current.Generate();

            Option <string> parentId = testAuth == TestAuthenticationType.SasOutOfScope
                ? Option.None <string>()
                : Option.Some(this.runtime.DeviceId);

            LeafDevice leaf = null;

            try
            {
                leaf = await LeafDevice.CreateAsync(
                    leafDeviceId,
                    protocol,
                    testAuth.ToAuthenticationType(),
                    parentId,
                    testAuth.UseSecondaryCertificate(),
                    this.ca,
                    this.iotHub,
                    Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                    token,
                    Option.None <string>(),
                    Context.Current.NestedEdge);
            }
            catch (Exception) when(!parentId.HasValue)
            {
                return;
            }

            if (!parentId.HasValue)
            {
                Assert.Fail("Expected to fail when not in scope.");
            }

            Assert.NotNull(leaf);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
            });
        }
        public async Task GrandparentScopeDevice(
            [Values(
                 TestAuthenticationType.SasInScope,
                 TestAuthenticationType.SelfSignedPrimary,
                 TestAuthenticationType.SelfSignedSecondary)] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            if (!this.device.NestedEdge.IsNestedEdge)
            {
                Assert.Ignore("The test can only be run in the nested edge topology");
            }

            Option <string> parentId = Option.Some(this.runtime.DeviceId);

            CancellationToken token = this.TestToken;

            await this.runtime.DeployConfigurationAsync(token, Context.Current.NestedEdge);

            string leafDeviceId = DeviceId.Current.Generate();

            LeafDevice leaf = null;

            try
            {
                leaf = await LeafDevice.CreateAsync(
                    leafDeviceId,
                    protocol,
                    testAuth.ToAuthenticationType(),
                    parentId,
                    testAuth.UseSecondaryCertificate(),
                    this.ca,
                    this.IotHub,
                    this.device.NestedEdge.ParentHostname,
                    token,
                    Option.None <string>(),
                    this.device.NestedEdge.IsNestedEdge);
            }
            catch (Exception) when(!parentId.HasValue)
            {
                return;
            }

            if (!parentId.HasValue)
            {
                Assert.Fail("Expected to fail when not in scope.");
            }

            Assert.NotNull(leaf);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
                await Task.CompletedTask;
            });
        }