public void When_Body_With_Text_Payload_Is_Valid_Json_Should_Be_Valid(string json, string expectedPayload) { var message = new Message(Encoding.UTF8.GetBytes(json)); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.True(target.IsValid(out _)); Assert.Equal(expectedPayload, Encoding.UTF8.GetString(target.GetPayload())); }
public void When_Body_Has_Invalid_MacCommand_Should_Not_Be_Valid(string json) { var message = new Message(Encoding.UTF8.GetBytes(json)); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.False(target.IsValid(out var errorMessage)); Assert.Equal($"could not parse cloud to device message: {json}", errorMessage); }
public void When_Body_Is_Empty_Text_Should_Not_Be_Valid() { var message = new Message(Encoding.UTF8.GetBytes(string.Empty)); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.False(target.IsValid(out var errorMessage)); Assert.Equal("cloud message does not have a body", errorMessage); }
public void When_Body_Has_Invalid_MacCommand_Should_Not_Be_Valid(string json) { using var message = new Message(Encoding.UTF8.GetBytes(json)); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.False(target.IsValid(out var errorMessage)); Assert.Contains($"could not parse cloud to device message: {json}: Unknown MAC command identifier", errorMessage, StringComparison.InvariantCulture); }
public void When_Body_Is_Empty_Should_Not_Be_Valid() { using var message = new Message(); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.False(target.IsValid(out var errorMessage)); Assert.Equal("cloud message does not have a body", errorMessage); }
public void When_Body_Has_MacCommand_Should_Contain_It_List(string json) { var message = new Message(Encoding.UTF8.GetBytes(json)); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.True(target.IsValid(out _)); Assert.Single(target.MacCommands); Assert.IsType <DevStatusRequest>(target.MacCommands.First()); }
public void When_Body_Has_MacCommand_With_Parameters_Should_Contain_It_List(string json) { var message = new Message(Encoding.UTF8.GetBytes(json)); var target = new LoRaCloudToDeviceMessageWrapper(this.sampleDevice, message); Assert.True(target.IsValid(out _)); Assert.Single(target.MacCommands); Assert.IsType <DutyCycleRequest>(target.MacCommands.First()); var dutyCycleCmd = (DutyCycleRequest)target.MacCommands.First(); Assert.Equal(2, dutyCycleCmd.DutyCyclePL); }