public void SetMode_Should_Not_Throw_Exceptions() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessage(It.IsAny <string>())).Returns("{\"result\":[\"ok\"],\"id\":1}"); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act airHumidifier.SetMode(AirHumidifier.Mode.High); // Assert miioDevice.Verify(x => x.SendMessage("{\"id\": 1, \"method\": \"set_mode\", \"params\": [\"high\"]}"), Times.Once()); }
public async Task SetModeAsync_Should_Not_Throw_Exceptions() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"ok\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act await airHumidifier.SetModeAsync(AirHumidifier.Mode.Medium); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"set_mode\", \"params\": [\"medium\"]}"), Times.Once()); }
public async void IsChildLockOnAsync_Returns_Valid_ChildLockState() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"off\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var childLock = await airHumidifier.IsChildLockOnAsync(); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"child_lock\"]}"), Times.Once()); Assert.False(childLock); }
public async void GetTargetHumidityAsync_Returns_Valid_TargetHumidity() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"50\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var targetHumidity = await airHumidifier.GetTargetHumidityAsync(); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"limit_hum\"]}"), Times.Once()); Assert.Equal(50, targetHumidity); }
public void IsBuzzerOn_Returns_Valid_BuzzerState() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessage(It.IsAny <string>())).Returns("{\"result\":[\"on\"],\"id\":1}"); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var buzzer = airHumidifier.IsBuzzerOn(); // Assert miioDevice.Verify(x => x.SendMessage("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"buzzer\"]}"), Times.Once()); Assert.True(buzzer); }
public async void GetBrightnessAsync_Returns_Valid_Brightness() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"2\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var brightness = await airHumidifier.GetBrightnessAsync(); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"led_b\"]}"), Times.Once()); Assert.Equal(AirHumidifier.Brightness.Off, brightness); }
public void GetHumidity_Returns_Valid_Humidity() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessage(It.IsAny <string>())).Returns("{\"result\":[\"45\"],\"id\":1}"); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var humidity = airHumidifier.GetHumidity(); // Assert miioDevice.Verify(x => x.SendMessage("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"humidity\"]}"), Times.Once()); Assert.Equal(45, humidity); }
public async Task GetTemperatureAsync_Returns_Valid_Temperature() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"323\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var temperature = await airHumidifier.GetTemperatureAsync(); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"temp_dec\"]}"), Times.Once()); Assert.Equal(32.3f, temperature); }
public async void GetDeviceModeAsync_Returns_Valid_Mode() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"medium\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var mode = await airHumidifier.GetDeviceModeAsync(); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"mode\"]}"), Times.Once()); Assert.Equal(AirHumidifier.Mode.Medium, mode); }
public async void IsTurnedOnAsync_Returns_State_Power() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessageAsync(It.IsAny <string>())).Returns(Task.FromResult("{\"result\":[\"on\"],\"id\":1}")); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var power = await airHumidifier.IsTurnedOnAsync(); // Assert miioDevice.Verify(x => x.SendMessageAsync("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"power\"]}"), Times.Once()); Assert.True(power); }
public void ToString_Returns_Valid_State() { // Arrange var miioDevice = new Mock <IMiioTransport>(); miioDevice.Setup(x => x.SendMessage(It.IsAny <string>())) .Returns("{\"result\": [\"on\", \"high\", \"323\", \"45\", \"0\", \"on\", \"off\", \"50\"], \"id\": 1}"); var airHumidifier = new AirHumidifier(miioDevice.Object); // Act var str = airHumidifier.ToString(); // Assert miioDevice.Verify(x => x.SendMessage("{\"id\": 1, \"method\": \"get_prop\", \"params\": [\"power\",\"mode\",\"temp_dec\",\"humidity\",\"led_b\",\"buzzer\",\"child_lock\",\"limit_hum\"]}"), Times.Once()); Assert.Equal("Power: on\nMode: high\nTemperature: 32.3 °C\nHumidity: 45%\nLED brightness: bright\nBuzzer: on\nChild lock: off\nTarget humidity: 50%\nModel: zhimi.humidifier.v1\nIP Address:\nToken: ", str); }