private async Task Twin_DeviceSetsReportedPropertyAndGetsItBackPoolOverAmqp(
            TestDeviceType type,
            Client.TransportType transport,
            int poolSize,
            int devicesCount,
            ConnectionStringAuthScope authScope = ConnectionStringAuthScope.Device)
        {
            Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) =>
            {
                s_log.WriteLine($"{nameof(TwinE2EPoolAmqpTests)}: Setting reported propery and verifying twin for device {testDevice.Id}");
                await TwinE2ETests.Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(deviceClient, Guid.NewGuid().ToString()).ConfigureAwait(false);
            };

            await PoolingOverAmqp.TestPoolAmqpAsync(
                _devicePrefix,
                transport,
                poolSize,
                devicesCount,
                null,
                testOperation,
                null,
                authScope,
                true).ConfigureAwait(false);
        }
        private async Task DeviceCombinedClientOperationsAsync(
            Client.TransportType transport,
            int poolSize,
            int devicesCount,
            ConnectionStringAuthScope authScope = ConnectionStringAuthScope.Device)
        {
            // Initialize service client for service-side operations
            using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(Configuration.IoTHub.ConnectionString);

            // Message payload for C2D operation
            var messagesSent = new Dictionary <string, List <string> >();

            // Twin properties
            var twinPropertyMap = new Dictionary <string, List <string> >();

            Func <DeviceClient, TestDevice, Task> initOperation = async(deviceClient, testDevice) =>
            {
                IList <Task> initOperations = new List <Task>();

                // Send C2D Message
                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Send C2D for device={testDevice.Id}");
                (Message msg, string messageId, string payload, string p1Value) = MessageReceiveE2ETests.ComposeC2dTestMessage();
                using (msg)
                {
                    messagesSent.Add(testDevice.Id, new List <string> {
                        payload, p1Value
                    });
                    Task sendC2dMessage = serviceClient.SendAsync(testDevice.Id, msg);
                    initOperations.Add(sendC2dMessage);

                    // Set method handler
                    s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Set direct method {MethodName} for device={testDevice.Id}");
                    Task <Task> methodReceivedTask = MethodE2ETests.SetDeviceReceiveMethodAsync(deviceClient, MethodName);
                    initOperations.Add(methodReceivedTask);

                    // Set the twin desired properties callback
                    s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Set desired property callback for device={testDevice.Id}");
                    string propName  = Guid.NewGuid().ToString();
                    string propValue = Guid.NewGuid().ToString();
                    twinPropertyMap.Add(testDevice.Id, new List <string> {
                        propName, propValue
                    });
                    Task <Task> updateReceivedTask = TwinE2ETests.SetTwinPropertyUpdateCallbackHandlerAsync(deviceClient, propName, propValue);
                    initOperations.Add(updateReceivedTask);

                    await Task.WhenAll(initOperations).ConfigureAwait(false);
                }
            };

            Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) =>
            {
                IList <Task> clientOperations = new List <Task>();
                await deviceClient.OpenAsync().ConfigureAwait(false);

                // D2C Operation
                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 1: Send D2C for device={testDevice.Id}");
                Task sendD2cMessage = MessageSendE2ETests.SendSingleMessageAndVerifyAsync(deviceClient, testDevice.Id);
                clientOperations.Add(sendD2cMessage);

                // C2D Operation
                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 2: Receive C2D for device={testDevice.Id}");
                List <string> msgSent = messagesSent[testDevice.Id];
                string        payload = msgSent[0];
                string        p1Value = msgSent[1];
                Task          verifyDeviceClientReceivesMessage = MessageReceiveE2ETests.VerifyReceivedC2DMessageAsync(transport, deviceClient, testDevice.Id, payload, p1Value);
                clientOperations.Add(verifyDeviceClientReceivesMessage);

                // Invoke direct methods
                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 3: Direct methods test for device={testDevice.Id}");
                Task serviceInvokeMethod = MethodE2ETests.ServiceSendMethodAndVerifyResponseAsync(testDevice.Id, MethodName, MethodE2ETests.DeviceResponseJson, MethodE2ETests.ServiceRequestJson);
                clientOperations.Add(serviceInvokeMethod);

                // Set reported twin properties
                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 4: Set reported property for device={testDevice.Id}");
                Task setReportedProperties = TwinE2ETests.Twin_DeviceSetsReportedPropertyAndGetsItBackAsync(deviceClient, Guid.NewGuid().ToString());
                clientOperations.Add(setReportedProperties);

                // Receive set desired twin properties
                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: Operation 5: Receive desired property for device={testDevice.Id}");
                List <string> twinProperties          = twinPropertyMap[testDevice.Id];
                string        propName                = twinProperties[0];
                string        propValue               = twinProperties[1];
                Task          updateDesiredProperties = TwinE2ETests.RegistryManagerUpdateDesiredPropertyAsync(testDevice.Id, propName, propValue);
                clientOperations.Add(updateDesiredProperties);

                await Task.WhenAll(clientOperations).ConfigureAwait(false);

                s_log.WriteLine($"{nameof(CombinedClientOperationsPoolAmqpTests)}: All operations completed for device={testDevice.Id}");
            };

            Func <Task> cleanupOperation = () =>
            {
                messagesSent.Clear();
                twinPropertyMap.Clear();
                return(Task.FromResult(0));
            };

            await PoolingOverAmqp
            .TestPoolAmqpAsync(
                _devicePrefix,
                transport,
                poolSize,
                devicesCount,
                initOperation,
                testOperation,
                cleanupOperation,
                authScope,
                false)
            .ConfigureAwait(false);
        }