Esempio n. 1
0
        public static async Task SendSendBatchMessagesAndVerifyAsync(DeviceClient deviceClient, string deviceId)
        {
            EventHubTestListener testListener = await EventHubTestListener.CreateListener(deviceId).ConfigureAwait(false);

            try
            {
                var messages = new List <Client.Message>();
                var props    = new List <Tuple <string, string> >();
                for (int i = 0; i < MESSAGE_BATCH_COUNT; i++)
                {
                    (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2CTestMessage();
                    messages.Add(testMessage);
                    props.Add(Tuple.Create(payload, p1Value));
                }

                await deviceClient.SendEventBatchAsync(messages).ConfigureAwait(false);

                foreach (Tuple <string, string> prop in props)
                {
                    bool isReceived = await testListener.WaitForMessage(deviceId, prop.Item1, prop.Item2).ConfigureAwait(false);

                    Assert.IsTrue(isReceived, "Message is not received.");
                }
            }
            finally
            {
                await testListener.CloseAsync().ConfigureAwait(false);
            }
        }
        internal async Task SendMessageRecovery(
            TestDeviceType type,
            Client.TransportType transport,
            string faultType,
            string reason,
            int delayInSec,
            int durationInSec           = FaultInjection.DefaultDurationInSec,
            int retryDurationInMilliSec = FaultInjection.RecoveryTimeMilliseconds)
        {
            EventHubTestListener testListener = null;

            Func <DeviceClient, TestDevice, Task> init = async(deviceClient, testDevice) =>
            {
                testListener = await EventHubTestListener.CreateListener(testDevice.Id).ConfigureAwait(false);

                deviceClient.OperationTimeoutInMilliseconds = (uint)retryDurationInMilliSec;
            };

            Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) =>
            {
                string payload, p1Value;

                Client.Message testMessage = ComposeD2CTestMessage(out payload, out p1Value);
                await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);

                bool isReceived = false;
                isReceived = await testListener.WaitForMessage(testDevice.Id, payload, p1Value).ConfigureAwait(false);

                Assert.IsTrue(isReceived);
            };

            Func <Task> cleanupOperation = () =>
            {
                if (testListener != null)
                {
                    return(testListener.CloseAsync());
                }
                else
                {
                    return(Task.FromResult(false));
                }
            };

            await FaultInjection.TestErrorInjectionAsync(
                DevicePrefix,
                type,
                transport,
                faultType,
                reason,
                delayInSec,
                durationInSec,
                init,
                testOperation,
                cleanupOperation).ConfigureAwait(false);
        }
Esempio n. 3
0
        private async Task SendSingleMessageModuleAndVerifyAsync(ModuleClient moduleClient, string deviceId)
        {
            EventHubTestListener testListener = await EventHubTestListener.CreateListener(deviceId).ConfigureAwait(false);

            try
            {
                (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2CTestMessage();
                await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false);

                bool isReceived = await testListener.WaitForMessage(deviceId, payload, p1Value).ConfigureAwait(false);

                Assert.IsTrue(isReceived, "Message is not received.");
            }
            finally
            {
                await testListener.CloseAsync().ConfigureAwait(false);
            }
        }
        private async Task TestSecurityMessageModule(Client.TransportType transport)
        {
            TestModule testModule = await TestModule.GetTestModuleAsync(_devicePrefix, _modulePrefix).ConfigureAwait(false);

            EventHubTestListener testListener = await EventHubTestListener.CreateListener(testModule.Id).ConfigureAwait(false);

            using (ModuleClient moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, transport))
            {
                try
                {
                    await SendSingleSecurityMessageModule(moduleClient, testModule.DeviceId, testListener, _logAnalyticsClient).ConfigureAwait(false);
                }
                finally
                {
                    await moduleClient.CloseAsync().ConfigureAwait(false);

                    await testListener.CloseAsync().ConfigureAwait(false);
                }
            }
        }
        private async Task TestSecurityMessage(Client.TransportType transport)
        {
            TestDevice testDevice = await TestDevice.GetTestDeviceAsync(_devicePrefix).ConfigureAwait(false);

            EventHubTestListener testListener = await EventHubTestListener.CreateListener(testDevice.Id).ConfigureAwait(false);

            using (DeviceClient deviceClient = testDevice.CreateDeviceClient(transport))
            {
                try
                {
                    await SendSingleSecurityMessage(deviceClient, testDevice.Id, testListener, _logAnalyticsClient).ConfigureAwait(false);
                }
                finally
                {
                    await deviceClient.CloseAsync().ConfigureAwait(false);

                    await testListener.CloseAsync().ConfigureAwait(false);
                }
            }
        }
Esempio n. 6
0
        public static async Task SendSingleMessageAndVerifyAsync(DeviceClient deviceClient, string deviceId)
        {
            EventHubTestListener testListener = await EventHubTestListener.CreateListener(deviceId).ConfigureAwait(false);

            try
            {
                string         payload;
                string         p1Value;
                Client.Message testMessage = ComposeD2CTestMessage(out payload, out p1Value);
                await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false);

                bool isReceived = await testListener.WaitForMessage(deviceId, payload, p1Value).ConfigureAwait(false);

                Assert.IsTrue(isReceived, "Message is not received.");
            }
            finally
            {
                await testListener.CloseAsync().ConfigureAwait(false);
            }
        }