mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Fix exception message and add test cases.
This commit is contained in:
@@ -25,7 +25,7 @@ namespace MQTTnet.Extensions
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using MQTTnet.Extensions;
|
using MQTTnet.Extensions;
|
||||||
@@ -24,6 +25,9 @@ namespace MQTTnet.Tests
|
|||||||
Assert.AreEqual("bar", message.GetUserProperty("foo"));
|
Assert.AreEqual("bar", message.GetUserProperty("foo"));
|
||||||
Assert.AreEqual(1011, message.GetUserProperty<int>("value"));
|
Assert.AreEqual(1011, message.GetUserProperty<int>("value"));
|
||||||
Assert.AreEqual("insensitive", message.GetUserProperty("case"));
|
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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user