Ejemplo n.º 1
0
        public void TestGatewayListenForDevice()
        {
            var gatewayId = "rsa-listen-gateway";
            var deviceId  = "rsa-listen-device";

            try
            {
                //Setup
                CloudIotSample.CreateGateway(_fixture.ProjectId, _fixture.RegionId,
                                             _fixture.RegistryId, gatewayId, "test/data/rsa_cert.pem", "RS256");
                CloudIotSample.BindDeviceToGateway(_fixture.ProjectId, _fixture.RegionId, _fixture.RegistryId,
                                                   deviceId, gatewayId);

                //Connect
                var listenConfigMsgOut = Run("listenForConfigMessages", _fixture.ProjectId,
                                             _fixture.RegionId, _fixture.RegistryId, gatewayId, deviceId, _fixture.CertPath,
                                             _fixture.PrivateKeyPath, "RS256", "--listentime", "10");

                //Assertions
                Assert.DoesNotContain("error occurred", listenConfigMsgOut.Stdout);
                Assert.Contains("On Subscribe", listenConfigMsgOut.Stdout);
                Assert.Contains("On Publish", listenConfigMsgOut.Stdout);
            }
            finally
            {
                //Clean up
                CloudIotSample.UnbindDeviceFromGateway(_fixture.ProjectId, _fixture.RegionId,
                                                       _fixture.RegistryId, deviceId, gatewayId);
                CloudIotSample.DeleteDevice(_fixture.ProjectId, _fixture.RegionId, _fixture.RegistryId, deviceId);
                CloudIotSample.DeleteDevice(_fixture.ProjectId, _fixture.RegionId, _fixture.RegistryId, gatewayId);
            }
        }
Ejemplo n.º 2
0
        public void TestSendDataForBoundDevice()
        {
            var gatewayId = string.Format("test-gateway-{0}", "RS256");
            var deviceId  = string.Format("test-device-{0}", TestUtil.RandomName());

            try
            {
                //Setup
                CloudIotSample.CreateGateway(_fixture.ProjectId, _fixture.RegionId, _fixture.RegistryId,
                                             gatewayId, "test/data/rsa_cert.pem", "RS256");
                CloudIotSample.BindDeviceToGateway(_fixture.ProjectId, _fixture.RegionId,
                                                   _fixture.RegistryId, deviceId, gatewayId);

                //Connect the gateway
                var sendDataBoundDeviceOut = Run("sendDataFromBoundDevice", _fixture.ProjectId,
                                                 _fixture.RegionId, _fixture.RegistryId,
                                                 deviceId, gatewayId, _fixture.PrivateKeyPath, "RS256", _fixture.CertPath,
                                                 "state", "test-message");
                Assert.Contains("Data sent", sendDataBoundDeviceOut.Stdout);
                Assert.Contains("On Publish", sendDataBoundDeviceOut.Stdout);
                Assert.DoesNotContain("An error occured", sendDataBoundDeviceOut.Stdout);
            }
            finally
            {
                //Clean up
                CloudIotSample.UnbindDeviceFromGateway(_fixture.ProjectId, _fixture.RegionId,
                                                       _fixture.RegistryId, deviceId, gatewayId);
                CloudIotSample.DeleteDevice(_fixture.ProjectId, _fixture.RegionId,
                                            _fixture.RegistryId, deviceId);
                CloudIotSample.DeleteDevice(_fixture.ProjectId, _fixture.RegionId,
                                            _fixture.RegistryId, gatewayId);
            }
        }