Example #1
0
        public async void RunE2ETest()
        {
            string deviceConnectionString                   = Environment.GetEnvironmentVariable("IoTHubDeviceConnectionString");
            string maxRetriesEnvironmentVariable            = Environment.GetEnvironmentVariable("VerificationMaxRetries");
            string retrySecondsEnvironmentVariable          = Environment.GetEnvironmentVariable("VerificationRetrySeconds");
            string shouldCreateWorkOrderEnvironmentVariable = Environment.GetEnvironmentVariable("ShouldCreateWorkOrder");
            int    maxRetries = maxRetriesEnvironmentVariable != null?int.Parse(maxRetriesEnvironmentVariable) : 10;

            int retrySeconds = retrySecondsEnvironmentVariable != null?int.Parse(retrySecondsEnvironmentVariable) : 5;

            bool shouldCreateWorkOrder = shouldCreateWorkOrderEnvironmentVariable != null?bool.Parse(shouldCreateWorkOrderEnvironmentVariable) : false;

            Microsoft.Azure.Devices.Client.TransportType transportType = Microsoft.Azure.Devices.Client.TransportType.Mqtt;
            using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, transportType))
            {
                // generate unique GUIDs
                string uniqueAssetName = Guid.NewGuid().ToString();
                string uniqueAssetPath = Guid.NewGuid().ToString();
                uniqueFaultName = Guid.NewGuid().ToString();
                output.WriteLine($"Generated unique AssetName - {uniqueAssetName}");
                output.WriteLine($"Generated unique AssetPath - {uniqueAssetPath}");
                output.WriteLine($"Generated unique FaultName - {uniqueFaultName}");

                // send message to IoTHub
                output.WriteLine("Sending message to IoT Hub");
                string currentISOTimeString = DateTime.UtcNow.ToString("o");
                await SendIconicsFaultDataToIoTHubAsync(deviceClient, uniqueAssetName, uniqueAssetPath, uniqueFaultName, "Active", currentISOTimeString);

                // verify Dynamics Alert and Asset
                output.WriteLine("Attempting Dynamics Alert and Asset verification");
                AssetAlertVerification assetAlertVerification = VerifyDynamicsAssetAndAlert(maxRetries, retrySeconds, uniqueAssetName, uniqueFaultName);

                // create WorkOrder if necessary
                if (shouldCreateWorkOrder)
                {
                    CreateWorkOrderIfNecessary(assetAlertVerification.verifiedAlertId);
                }

                EventHubConsumerClient consumer = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, Environment.GetEnvironmentVariable("IoTHubEventHubEndpoint"), Environment.GetEnvironmentVariable("IoTHubEventHubName"));

                // verify work order acknowledgement in IoTHub
                output.WriteLine("Attempting IoT Hub work order acknowledgement verification");
                bool iotHubMessageVerified = await VerifyWorkOrderAcknowledgementAsync(consumer, maxRetries, retrySeconds, uniqueAssetPath, uniqueFaultName);

                // assert
                Assert.True(assetAlertVerification.assetVerified);
                Assert.True(assetAlertVerification.alertVerified);
                Assert.True(iotHubMessageVerified);
            }
        }
Example #2
0
        public async void ValidateDynamicsInActiveAlert()
        {
            string deviceConnectionString                   = Environment.GetEnvironmentVariable("IoTHubDeviceConnectionString");
            string maxRetriesEnvironmentVariable            = Environment.GetEnvironmentVariable("VerificationMaxRetries");
            string retrySecondsEnvironmentVariable          = Environment.GetEnvironmentVariable("VerificationRetrySeconds");
            string shouldCreateWorkOrderEnvironmentVariable = Environment.GetEnvironmentVariable("ShouldCreateWorkOrder");
            int    maxRetries = maxRetriesEnvironmentVariable != null?int.Parse(maxRetriesEnvironmentVariable) : 10;

            int retrySeconds = retrySecondsEnvironmentVariable != null?int.Parse(retrySecondsEnvironmentVariable) : 5;

            Microsoft.Azure.Devices.Client.TransportType transportType = Microsoft.Azure.Devices.Client.TransportType.Mqtt;
            using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, transportType))
            {
                // generate unique GUIDs
                string uniqueAssetName = Guid.NewGuid().ToString();
                string uniqueAssetPath = Guid.NewGuid().ToString();
                uniqueFaultName = Guid.NewGuid().ToString();
                output.WriteLine($"Generated unique AssetName - {uniqueAssetName}");
                output.WriteLine($"Generated unique AssetPath - {uniqueAssetPath}");
                output.WriteLine($"Generated unique FaultName - {uniqueFaultName}");

                // send message to IoTHub
                output.WriteLine("Sending message to IoT Hub");
                string currentISOTimeString = DateTime.UtcNow.ToString("o");
                await SendIconicsFaultDataToIoTHubAsync(deviceClient, uniqueAssetName, uniqueAssetPath, uniqueFaultName, "Active", currentISOTimeString);

                // verify Dynamics Alert and Asset
                output.WriteLine("Attempting Dynamics Alert and Asset verification");
                AssetAlertVerification assetAlertVerification = VerifyDynamicsAssetAndAlert(maxRetries, retrySeconds, uniqueAssetName, uniqueFaultName);
                output.WriteLine("Sending message to IoT Hub with Fault State as InActive");
                await SendIconicsFaultDataToIoTHubAsync(deviceClient, uniqueAssetName, uniqueAssetPath, uniqueFaultName, "InActive", currentISOTimeString);

                bool inActiveAlertVerified = VerifyDynamicsInActiveAlert(maxRetries, retrySeconds, uniqueFaultName);

                // assert
                Assert.True(assetAlertVerification.assetVerified);
                Assert.True(assetAlertVerification.alertVerified);
                Assert.True(inActiveAlertVerified);
            }
        }