Пример #1
0
        public void TestDesiredPropertyRecurringReporting()
        {
            // Expected values
            var expectedEndpoint = "Dummy Endpoint";

            // Mock Object setup
            var callback = new CallBackMockup();

            callback.SendMessageHook      = SendMessageHook;
            callback.ReportPropertiesHook = ReportPropertiesHook;


            var systemConfigurator = new ConfigurationProxyMockup();

            systemConfigurator.SendCommandHook = (IRequest request) =>
            {
                if (request.Tag == DMMessageKind.DeviceHealthAttestationVerifyHealth)
                {
                    var request2 = (DeviceHealthAttestationVerifyHealthRequest)request;
                    Assert.AreEqual(expectedEndpoint, request2.HealthAttestationServerEndpoint);
                    return(new StatusCodeResponse(ResponseStatus.Success, DMMessageKind.DeviceHealthAttestationVerifyHealth));
                }
                Assert.Fail($"Got unexpected command - {request.Tag}");
                return(null);
            };

            var dha = new DeviceHealthAttestationHandler(callback, systemConfigurator);

            // Test begins
            try
            {
                var desiredProperty = new DeviceHealthAttestationDataContract.DesiredProperty();
                desiredProperty.Endpoint = expectedEndpoint;
                desiredProperty.ReportIntervalInSeconds = 1;
                dha.OnDesiredPropertyChange(JObject.FromObject(desiredProperty));

                // Test validation
                for (int i = 0; i < 3; i++)
                {
                    Assert.IsTrue(sentMessageEvent.WaitOne(TimeSpan.FromSeconds(5)));
                    Assert.AreEqual(DeviceHealthAttestationDataContract.NonceRequestTag, sentMessageProperties["MessageType"]);
                }
            }
            finally
            {
                // Disable the reporting
                var desiredProperty = new DeviceHealthAttestationDataContract.DesiredProperty();
                desiredProperty.Endpoint = "";
                desiredProperty.ReportIntervalInSeconds = -1;
                dha.OnDesiredPropertyChange(JObject.FromObject(desiredProperty));
            }
        }
Пример #2
0
        public void TestDesiredPropertyInvalidJObject()
        {
            // Send invalid JObject as desired property.  Ensure error is reflected in the reported property.
            var callback = new CallBackMockup();

            callback.ReportPropertiesHook = ReportPropertiesHook;
            var systemConfigurator = new ConfigurationProxyMockup();
            var dha = new DeviceHealthAttestationHandler(callback, systemConfigurator);

            {
                // Test 1: Endpoint = null
                dha.OnDesiredPropertyChange(new JObject());
                EnsureReportedPropertyStatus("VerifyHealth failed: Value cannot be null.");
            }

            {
                // Test 2:
                var jobj = new JObject();
                jobj.Add("ReportIntervalInSeconds", "string in an integer field");
                dha.OnDesiredPropertyChange(jobj);
                EnsureReportedPropertyStatus("VerifyHealth failed: Could not convert string to integer: string in an integer field. Path 'ReportIntervalInSeconds'.");
            }
        }
Пример #3
0
        public void TestDesiredPropertyDisabledReporting()
        {
            // Mock Object setup
            var callback = new CallBackMockup();

            callback.ReportPropertiesHook = ReportPropertiesHook;
            var systemConfigurator = new ConfigurationProxyMockup();
            var dha = new DeviceHealthAttestationHandler(callback, systemConfigurator);

            // Test begins
            var desiredProperty = new DeviceHealthAttestationDataContract.DesiredProperty();

            desiredProperty.Endpoint = "";
            desiredProperty.ReportIntervalInSeconds = -1;
            dha.OnDesiredPropertyChange(JObject.FromObject(desiredProperty));

            // Test validation
            EnsureReportedPropertyStatus("Reporting Disabled");
        }