public void MockupProxyPostponedRebootTest() { var twin = new TwinMockup(); var requestHandler = new HandlerMockupForReboot(false); var proxy = new ConfigurationProxyMockup(); var dmClient = DeviceManagementClient.Create(twin, requestHandler, proxy); dmClient.RebootAsync().Wait(); Assert.AreEqual(proxy.ReceivedRequest, null); Assert.AreEqual(proxy.ReturnedResponse, null); }
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)); } }
public void MockupProxyImmediateRebootTest() { var twin = new TwinMockup(); var requestHandler = new HandlerMockupForReboot(true); var proxy = new ConfigurationProxyMockup(); var dmClient = DeviceManagementClient.Create(twin, requestHandler, proxy); dmClient.RebootAsync().Wait(); Assert.AreEqual(proxy.ReceivedRequest.Tag, DMMessageKind.ImmediateReboot); Assert.AreEqual(proxy.ReturnedResponse.Tag, DMMessageKind.ImmediateReboot); Assert.AreEqual(proxy.ReturnedResponse.Status, ResponseStatus.Success); }
public void TestRequestSendToProxy() { var appInstallRequest = new AppInstallRequest(new AppInstallInfo() { AppxPath = "abc", PackageFamilyName = "def", Dependencies = new List <String>() { "ghi", "jkl" } }); var proxy = new ConfigurationProxyMockup(); IResponse response = proxy.SendCommandAsync(appInstallRequest).Result; Assert.AreEqual(response.Status, ResponseStatus.Success); }
public void TestDirectMethodGetCertificate() { // Expected values var expectedNonce = "AFAFAFAFAF"; var expectedHealthCert = "Dummy health cert"; var expectedCorrelationId = "Dummy correlation id"; // 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.DeviceHealthAttestationGetReport) { var request2 = (DeviceHealthAttestationGetReportRequest)request; Assert.AreEqual(expectedNonce, request2.Nonce); return(new DeviceHealthAttestationGetReportResponse(expectedHealthCert, expectedCorrelationId)); } Assert.Fail($"Got unexpected command - {request.Tag}"); return(null); }; var dha = new DeviceHealthAttestationHandler(callback, systemConfigurator); // Test begins var getCertificateMethod = dha.GetDirectMethodHandler()[DeviceHealthAttestationDataContract.GetReportMethodName]; var param = new DeviceHealthAttestationDataContract.GetReportMethodParam() { Nonce = expectedNonce }; var response = getCertificateMethod(JsonConvert.SerializeObject(param)).Result; // Test validation Assert.IsTrue(sentMessageEvent.WaitOne(TimeSpan.FromSeconds(5))); Assert.AreEqual(SuccessResponse, response); Assert.AreEqual(DeviceHealthAttestationDataContract.HealthReportTag, sentMessageProperties["MessageType"]); var message = JsonConvert.DeserializeObject <DeviceHealthAttestationDataContract.HealthReport>(sentMessaage); Assert.AreEqual(expectedCorrelationId, message.CorrelationId); Assert.AreEqual(expectedHealthCert, message.HealthCertificate); EnsureReportedPropertyStatus("Reported"); }
public void MockupProxyInstallAppTest() { var twin = new TwinMockup(); var proxy = new ConfigurationProxyMockup(); var appInstallRequest = new AppInstallRequest(new AppInstallRequestData() { AppxPath = "abc", PackageFamilyName = "def", Dependencies = new List <String>() { "ghi", "jkl" } }); var response = proxy.SendCommandAsync(appInstallRequest).Result; Assert.AreEqual(response.Status, ResponseStatus.Success); Assert.AreEqual(response.Tag, DMMessageKind.InstallApp); }
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"); }
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'."); } }