Esempio n. 1
0
// ReSharper disable PossibleMultipleEnumeration
        public async Task RunAsync(IRestContext context)
        {
            ISystemApi systemApi = context.Factory.CreateSystemApi();
            
            IEnumerable<DeviceResponse> devices = await systemApi.GetDevicesAsync(new SqlQuery());
            await DeleteAnyDevices(devices, systemApi);

            IUserApi userApi = context.Factory.CreateUserApi();
            DeviceRequest device = new DeviceRequest
            {
                uuid = "1",
                model = "model",
                platform = "windows",
                version = "1.0"
            };

            bool ok = await userApi.SetDeviceAsync(device);
            Console.WriteLine("SetDeviceAsync(): success={0}", ok);

            SqlQuery query = new SqlQuery { filter = "platform=\"windows\"", fields = "*" };
            devices = await systemApi.GetDevicesAsync(query);
            Console.WriteLine("GetDevicesAsync(): {0}", context.ContentSerializer.Serialize(devices.Single()));

            await DeleteAnyDevices(devices, systemApi);
        }
Esempio n. 2
0
        public async Task<bool> SetDeviceAsync(DeviceRequest deviceRequest)
        {
            if (deviceRequest == null)
            {
                throw new ArgumentNullException("deviceRequest");
            }

            var address = baseAddress.WithResource("device");
            string content = contentSerializer.Serialize(deviceRequest);
            IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, content);

            IHttpResponse response = await httpFacade.RequestAsync(request);
            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var success = new { success = false };
            return contentSerializer.Deserialize(response.Body, success).success;
        }
Esempio n. 3
0
        public void ShouldSetDeviceAsync()
        {
            // Arrange
            IUserApi userApi = CreateUserApi();
            DeviceRequest request = new DeviceRequest
                                    {
                                        id = 1,
                                        uuid = "1",
                                        platform = "windows",
                                        model = "new",
                                        version = "1"
                                    };

            // Act
            bool ok = userApi.SetDeviceAsync(request).Result;

            // Assert
            ok.ShouldBe(true);
        }