This class represents the user device.
        public void setUp()
        {
            this.context = new Context("https://api.sentinelapp.com.br", "key", "secret");
            if (this.user == null)
            {
                this.user = new User("Maria", "maria");
                Device device1 = new Device("558211223344", new Device.Capability[] { Device.Capability.otp, Device.Capability.sms, Device.Capability.call });
                Device device2 = new Device("558299887766", new Device.Capability[] { Device.Capability.call });

                this.user.Devices = new Device[] { device1, device2 };
            }
        }
        public void UpdateDevice_Test()
        {
            this.context.HttpService = createHttpServiceMock(
                "api/v2/users/maria/devices/1", HttpMethod.Post,
                "{\"id\":1,\"number\":\"558211223344\",\"token\":null,\"capabilities\":[\"otp\",\"sms\",\"call\"],\"confirmed_at\":null,\"otp_activated\":false}",
                "OK", DeviceJson);

            Device device = new Device(this.Device0Number, this.Device0Capabilities);
            device.Id = 1;
            checkDevice(context.UpdateDevice("maria", device));
        }
 private void checkDevice(Device device)
 {
     Assert.AreEqual(Device0Number, device.Number);
     Assert.IsNotNull(device.Capabilities);
     Assert.AreEqual(Device0Capabilities.Length, device.Capabilities.Length);
 }
        public void UpdateDevice_NotRegistredUserTest()
        {
            this.context.HttpService = createHttpServiceMock(
                "api/v2/users/invalid/devices/1", HttpMethod.Post,
                "{\"id\":1,\"number\":\"558211223344\",\"token\":null,\"capabilities\":[\"otp\",\"sms\",\"call\"],\"confirmed_at\":null,\"otp_activated\":false}",
                "NotFound", null);

            Device device = new Device(this.Device0Number, this.Device0Capabilities);
            device.Id = 1;
            context.UpdateDevice("invalid", device);
        }
        public void UpdateDevice_InvalidTest()
        {
            this.context.HttpService = createHttpServiceMock(
                "api/v2/users/maria/devices/1", HttpMethod.Post,
                "{\"id\":1,\"number\":null,\"token\":null,\"capabilities\":null,\"confirmed_at\":null,\"otp_activated\":false}",
                "422", ErrorsJson);

            Device device = new Device(null, null);
            device.Id = 1;
            context.UpdateDevice("maria", device);
        }
        public void CreateUser_Test()
        {
            this.context.HttpService = createHttpServiceMock(
                "api/v2/users", HttpMethod.Post,
                "{\"id\":0,\"name\":\"Maria\",\"username\":\"maria\",\"devices\":[{\"id\":0,\"number\":\"558211223344\",\"token\":null,\"capabilities\":[\"otp\",\"sms\",\"call\"],\"confirmed_at\":null,\"otp_activated\":false},{\"id\":0,\"number\":\"558299887766\",\"token\":null,\"capabilities\":[\"call\"],\"confirmed_at\":null,\"otp_activated\":false}],\"keep_otp_devices\":true}",
                "OK", UserJson);

            Device device0 = new Device(this.Device0Number, this.Device0Capabilities);
            Device device1 = new Device(this.Device1Number, this.Device1Capabilities);

            checkUser(context.CreateUser(this.UserUsername, this.UserName, new Device[] { device0, device1 }));
        }
        public void CreateUser_InvalidTest()
        {
            this.context.HttpService = createHttpServiceMock(
                "api/v2/users", HttpMethod.Post,
                "{\"id\":0,\"name\":null,\"username\":null,\"devices\":null,\"keep_otp_devices\":true}",
                "422", ErrorsJson);

            Device device0 = new Device(this.Device0Number, this.Device0Capabilities);
            Device device1 = new Device(this.Device1Number, this.Device1Capabilities);

            context.CreateUser(null, null, null);
        }
        public void CreateOrUpdateUser_InvalidTest()
        {
            this.context.HttpService = createHttpServiceMock(
                "api/v2/users/maria", HttpMethod.Post,
                "{\"id\":0,\"name\":null,\"username\":\"maria\",\"devices\":[{\"id\":0,\"number\":\"558211223344\",\"token\":null,\"capabilities\":[\"otp\",\"sms\",\"call\"],\"confirmed_at\":null,\"otp_activated\":false},{\"id\":0,\"number\":\"558299887766\",\"token\":null,\"capabilities\":[\"call\"],\"confirmed_at\":null,\"otp_activated\":false}],\"keep_otp_devices\":true}",
                "422", ErrorsJson);

            Device device0 = new Device(this.Device0Number, this.Device0Capabilities);
            Device device1 = new Device(this.Device1Number, this.Device1Capabilities);
            User user = new User(null, "maria");
            user.Devices = new Device[] { device0, device1 };

            checkUser(context.CreateOrUpdateUser(user));
        }