Пример #1
0
        public async Task CanAccess_MasterApiKey_ListOf_CommandsSent_TakeOne_AndView_Details()
        {
            try
            {
                var targetCommandId = string.Empty;
                using (var client = new M2XClient(_masterKey))
                {
                    var retrieveCommandsResult = await client.Commands();

                    Assert.IsNotNull(retrieveCommandsResult);
                    Assert.IsFalse(retrieveCommandsResult.Error);
                    Assert.IsFalse(retrieveCommandsResult.ServerError);
                    Assert.IsNull(retrieveCommandsResult.WebError);
                    Assert.IsFalse(string.IsNullOrWhiteSpace(retrieveCommandsResult.Raw));

                    var commandData = JsonConvert.DeserializeObject <ApiResponseForCommandSearch>(retrieveCommandsResult.Raw);
                    if (!commandData.commands.Any())
                    {
                        Assert.Fail("There are no commands to view. Please send one using the appropriate test or create one manually before trying again.");
                    }
                    targetCommandId = commandData.commands.First().id;
                }


                using (var client = new M2XClient(_masterKey))
                {
                    var result = await client.CommandDetails(targetCommandId);

                    Assert.IsNotNull(result);
                    Assert.IsFalse(result.Error);
                    Assert.IsFalse(result.ServerError);
                    Assert.IsNull(result.WebError);
                    Assert.IsFalse(string.IsNullOrWhiteSpace(result.Raw));

                    var commandDetail = JsonConvert.DeserializeObject <ApiResponseForCommandDetail>(result.Raw);
                    Assert.IsNotNull(commandDetail);
                    Assert.IsNotNull(commandDetail.data);
                    Assert.IsNotNull(commandDetail.deliveries);
                    Assert.AreNotEqual(default(DateTime), commandDetail.sent_at);
                }
            }
            catch (Exception)
            {
                DestroyTestDevice();
                throw;
            }
        }