Esempio n. 1
0
        public void UpdateDeviceCommand_ValidRequest()
        {
            const string commandResult = "{\"result\": \"test\"}";

            // create command
            var clientConnection = ClientController.Connect();

            ClientController.Authenticate(clientConnection, Login, Password);
            var insertCommandRes = ClientController.InsertDeviceCommand(clientConnection,
                                                                        DeviceGUID, new JObject(new JProperty("command", "_ut")));
            var command   = (JObject)insertCommandRes["command"];
            var commandId = (int)command["id"];

            // send handler for command update notification
            string result = null;

            clientConnection.SendMessageHandler = m =>
            {
                var res = JObject.Parse(m);
                var cmd = (JObject)res["command"];
                result = (string)cmd["result"];
            };

            // update command
            var connection = DeviceController.Connect();

            DeviceController.Authenticate(connection, DeviceGUID, DeviceKey);
            var msg = DeviceController.UpdateDeviceCommand(connection, commandId, new JObject(
                                                               new JProperty("result", commandResult)));

            clientConnection.WaiteForSendMessage();

            Expect((string)msg["status"], EqualTo("success"));
            Expect(result, EqualTo(commandResult));
        }
Esempio n. 2
0
        public void DeviceNotificationsSubscription_SubscribeToValidDevice()
        {
            // subscribe to notifications
            var clientConnection = ClientController.Connect();

            ClientController.Authenticate(clientConnection, Login, Password);
            var msg = ClientController.SubscribeToDeviceNotifications(clientConnection, new[] { DeviceGUID });

            Expect((string)msg["status"], EqualTo("success"));

            // send handler for new notification
            JObject notification = null;

            clientConnection.SendMessageHandler = m =>
            {
                var res = JObject.Parse(m);
                notification = (JObject)res["notification"];
            };

            // insert notification
            var deviceConnection = DeviceController.Connect();

            DeviceController.Authenticate(deviceConnection, DeviceGUID, DeviceKey);
            msg = DeviceController.InsertDeviceNotification(deviceConnection, new JObject(
                                                                new JProperty("notification", "_ut")));
            var insertedNotification = (JObject)msg["notification"];

            Expect(() => (string)notification["notification"], EqualTo("_ut"));
            Expect(() => (int)notification["id"], EqualTo((int)insertedNotification["id"]));
        }
Esempio n. 3
0
        public void DeviceCommandsSubscription_Unsubscribe()
        {
            // subscribe to commands
            var deviceConnection = DeviceController.Connect();

            DeviceController.Authenticate(deviceConnection, DeviceGUID, DeviceKey);
            var msg = DeviceController.SubsrcibeToDeviceCommands(deviceConnection);

            Expect((string)msg["status"], EqualTo("success"));

            // unsubscribe from commands
            msg = DeviceController.UnsubsrcibeFromDeviceCommands(deviceConnection);
            Expect((string)msg["status"], EqualTo("success"));

            // send handler for new command
            JObject command = null;

            deviceConnection.SendMessageHandler = m =>
            {
                var res = JObject.Parse(m);
                command = (JObject)res["command"];
            };

            // insert command
            var clientConnection = ClientController.Connect();

            ClientController.Authenticate(clientConnection, Login, Password);
            ClientController.InsertDeviceCommand(clientConnection, DeviceGUID, new JObject(
                                                     new JProperty("command", "_ut")));

            Expect(command, EqualTo(null));
        }
Esempio n. 4
0
        public void Authenticate_ValidDevice()
        {
            var connection = DeviceController.Connect();
            var msg        = DeviceController.Authenticate(connection, DeviceGUID, DeviceKey);

            Expect((string)msg["status"], EqualTo("success"));
        }
Esempio n. 5
0
        public void Authenticate_InvalidDevice()
        {
            var connection = DeviceController.Connect();
            var msg        = DeviceController.Authenticate(connection, Guid.NewGuid().ToString(), "bbb");

            Expect((string)msg["status"], EqualTo("error"));
        }
Esempio n. 6
0
        public void InsertDeviceNotification_EmptyData()
        {
            var connection = DeviceController.Connect();

            DeviceController.Authenticate(connection, DeviceGUID, DeviceKey);
            var msg = DeviceController.InsertDeviceNotification(connection, null);

            Expect((string)msg["status"], EqualTo("error"));
        }
Esempio n. 7
0
        public void UpdateDeviceCommand_InvalidCommand()
        {
            var connection = DeviceController.Connect();

            DeviceController.Authenticate(connection, DeviceGUID, DeviceKey);
            var msg = DeviceController.UpdateDeviceCommand(connection, -1, new JObject(
                                                               new JProperty("result", "testResult")));

            Expect((string)msg["status"], EqualTo("error"));
        }
Esempio n. 8
0
        public void InsertDeviceNotification_ValidRequest()
        {
            var connection = DeviceController.Connect();

            DeviceController.Authenticate(connection, DeviceGUID, DeviceKey);
            var msg = DeviceController.InsertDeviceNotification(connection,
                                                                new JObject(new JProperty("notification", "_ut")));

            Expect((string)msg["status"], EqualTo("success"));
        }
Esempio n. 9
0
        public void DeviceGetUpdate_ValidRequest()
        {
            var connection = DeviceController.Connect();

            DeviceController.Authenticate(connection, DeviceGUID, DeviceKey);

            var res    = DeviceController.GetDevice(connection);
            var device = (JObject)res["device"];

            Expect((string)device["name"], EqualTo("test device"));

            device["name"] = "updated name";
            res            = DeviceController.SaveDevice(connection, DeviceGUID, device);
            Expect((string)res["status"], EqualTo("success"));

            res    = DeviceController.GetDevice(connection);
            device = (JObject)res["device"];
            Expect((string)device["name"], EqualTo("updated name"));

            device["name"] = "test device";
            DeviceController.SaveDevice(connection, DeviceGUID, device);
        }