Exemplo 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);
            }
        }
Exemplo n.º 2
0
        public void TestMqttDeviceState()
        {
            var deviceId = "rsa-device-mqtt-state-" + _fixture.TestId;

            try
            {
                //Setup screnario
                CloudIotSample.CreateRsaDevice(_fixture.ProjectId, _fixture.RegionId, _fixture.RegistryId, deviceId, "test/data/rsa_cert.pem");
                var mqttExampleOut = Run("startMqtt",
                                         _fixture.ProjectId,
                                         _fixture.RegionId,
                                         _fixture.RegistryId,
                                         deviceId,
                                         _fixture.PrivateKeyPath,
                                         "RS256",
                                         _fixture.CertPath,
                                         "state",
                                         "--waittime",
                                         "5",
                                         "--nummessages",
                                         "1");
                Assert.Contains("Publishing state message", mqttExampleOut.Stdout);
                Assert.Contains("On Publish", mqttExampleOut.Stdout);
            }
            catch (Google.GoogleApiException e)
            {
                Console.WriteLine("Failure on exception: {0}", e.Message);
            }
            finally
            {
                //Clean up
                CloudIotSample.DeleteDevice(_fixture.ProjectId, _fixture.RegionId, _fixture.RegistryId, deviceId);
            }
        }
Exemplo n.º 3
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);
            }
        }