Explorar el Código

Fix exception message and add test cases.

release/3.x.x
PMExtra hace 4 años
padre
commit
774d49a908
Se han modificado 2 ficheros con 5 adiciones y 1 borrados
  1. +1
    -1
      Source/MQTTnet/Extensions/UserPropertyExtension.cs
  2. +4
    -0
      Tests/MQTTnet.Core.Tests/MqttApplicationMessage_Tests.cs

+ 1
- 1
Source/MQTTnet/Extensions/UserPropertyExtension.cs Ver fichero

@@ -25,7 +25,7 @@ namespace MQTTnet.Extensions
}
catch (Exception ex)
{
throw new InvalidOperationException($"Cannot convert value({value}) of UserProperty({propertyName}) to {typeof(T).FullName}.", ex);
throw new InvalidOperationException($"Cannot convert value({value ?? "null"}) of UserProperty({propertyName}) to {typeof(T).FullName}.", ex);
}
}
}


+ 4
- 0
Tests/MQTTnet.Core.Tests/MqttApplicationMessage_Tests.cs Ver fichero

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Extensions;
@@ -24,6 +25,9 @@ namespace MQTTnet.Tests
Assert.AreEqual("bar", message.GetUserProperty("foo"));
Assert.AreEqual(1011, message.GetUserProperty<int>("value"));
Assert.AreEqual("insensitive", message.GetUserProperty("case"));
Assert.AreEqual(null, message.GetUserProperty("nonExists"));
Assert.AreEqual(null, message.GetUserProperty<int?>("nonExists"));
Assert.ThrowsException<InvalidOperationException>(() => message.GetUserProperty<int>("nonExists"));
}
}
}

Cargando…
Cancelar
Guardar