Пример #1
0
        public void SendActionsTest()
        {
            string        ddid        = Properties["device4.id"];
            string        deviceToken = Properties["device4.token"];
            Configuration config      = new Configuration(timeout: 10000, accessToken: deviceToken);
            MessagesApi   newApi      = new MessagesApi(config);

            Action action = new Action();

            action.Name       = "setVolume";
            action.Parameters = new Dictionary <string, object>();
            action.Parameters.Add("volume", 5);

            ActionArray actionArray = new ActionArray();

            actionArray.Actions = new List <Action>();
            actionArray.Actions.Add(action);

            Actions actions = new Actions();

            actions.Ddid = ddid;
            actions.Ts   = GetCurrentUnixTimestampMillis();
            actions.Data = actionArray;

            string mid = newApi.SendActions(actions).Data.Mid;

            // Wait 2 seconds for the message to be normalized. 2 seconds just to be
            // safe, usually much faster.
            Thread.Sleep(2000);

            NormalizedActionsEnvelope envelope = newApi.GetNormalizedActions(null, null, mid, null, null, null, null, null);

            Assert.AreEqual(1, envelope.Size);

            NormalizedAction normalized = envelope.Data[0];
            Action           actionRx   = normalized.Data.Actions[0];

            Assert.AreEqual("setVolume", actionRx.Name);

            object volume = actionRx.Parameters["volume"];

            Assert.NotNull(volume, "Volume should not be null");
            Assert.AreEqual(5, volume);
        }