-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for message with content type and user properties (#263)
- Loading branch information
1 parent
ed01470
commit 87e5996
Showing
10 changed files
with
448 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<!-- Configurations that affect the Test Framework --> | ||
<RunConfiguration> | ||
<MaxCpuCount>1</MaxCpuCount> | ||
<ResultsDirectory>.\TestResults</ResultsDirectory><!-- Path relative to solution directory --> | ||
<TestSessionTimeout>120000</TestSessionTimeout><!-- Milliseconds --> | ||
<TargetFrameworkVersion>net48</TargetFrameworkVersion> | ||
<TargetPlatform>x64</TargetPlatform> | ||
</RunConfiguration> | ||
<nanoFrameworkAdapter> | ||
<Logging>None</Logging> | ||
<IsRealHardware>False</IsRealHardware> | ||
</nanoFrameworkAdapter> | ||
</RunSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using nanoFramework.Azure.Devices.Client; | ||
using nanoFramework.M2Mqtt.Messages; | ||
using nanoFramework.TestFramework; | ||
using System; | ||
using System.Collections; | ||
|
||
namespace DeviceClientTests | ||
{ | ||
[TestClass] | ||
public class DeviceClientTests | ||
{ | ||
private static string _propertyOneName = "prop1"; | ||
private static string _propertyTwoName = "prop2"; | ||
private static string _propertyThreeName = "prop3"; | ||
private static string _propertyOneValue = "iAmValue1"; | ||
private static float _propertyTwoValue = 33.44f; | ||
private static string _propertyThreeValue = "string with $/#% chars"; | ||
|
||
private static UserProperty _userProperty1 = new(_propertyOneName, _propertyOneValue); | ||
private static UserProperty _userProperty2 = new(_propertyTwoName, _propertyTwoValue.ToString()); | ||
private static UserProperty _userProperty3 = new(_propertyThreeName, _propertyThreeValue); | ||
|
||
private static UserProperty _userPropertyBad1 = new(null, _propertyOneValue); | ||
private static UserProperty _userPropertyBad2 = new(_propertyTwoName, null); | ||
|
||
[TestMethod] | ||
public void EncodeUserPropertiesTest_00() | ||
{ | ||
DeviceClient client = new(); | ||
|
||
var encodedProperties = client.EncodeUserProperties(new ArrayList() { _userProperty1, _userProperty2, _userProperty3 }); | ||
|
||
Assert.Equal(encodedProperties, "prop1=iAmValue1&prop2=33.44&prop3=string+with+%24%2F%23%25+chars"); | ||
} | ||
|
||
[TestMethod] | ||
public void EncodeUserPropertiesTest_01() | ||
{ | ||
DeviceClient client = new(); | ||
|
||
Assert.Throws(typeof(ArgumentException), () => | ||
{ | ||
client.EncodeUserProperties(new ArrayList() { _userProperty3, _userPropertyBad1 }); | ||
}, | ||
"Expecting ArgumentException with invalid user property 01." | ||
); | ||
|
||
Assert.Throws(typeof(ArgumentException), () => | ||
{ | ||
client.EncodeUserProperties(new ArrayList() { _userPropertyBad2, _userProperty3 }); | ||
}, | ||
"Expecting ArgumentException with invalid user property 02." | ||
); | ||
|
||
Assert.Throws(typeof(InvalidCastException), () => | ||
{ | ||
client.EncodeUserProperties(new ArrayList() { _userProperty1, "Invalid property" }); | ||
}, | ||
"Expecting ArgumentException with invalid user property 03." | ||
); | ||
|
||
Assert.Throws(typeof(InvalidCastException), () => | ||
{ | ||
client.EncodeUserProperties(new ArrayList() { 8888888, "Invalid property" }); | ||
}, | ||
"Expecting ArgumentException with invalid user property 04." | ||
); | ||
} | ||
|
||
[DataRow("application/json", "$.ct=application%2Fjson&$.ce=utf-8")] | ||
[DataRow("application/mime", "$.ct=application%2Fmime&$.ce=utf-8")] | ||
[TestMethod] | ||
public void EncodeContentType_00(string contentType, string encodedContentType) | ||
{ | ||
DeviceClient client = new(); | ||
|
||
Assert.Equal( | ||
client.EncodeContentType(contentType), | ||
encodedContentType); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath> | ||
</PropertyGroup> | ||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" /> | ||
<ItemGroup> | ||
<ProjectCapability Include="TestContainer" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<ProjectGuid>557ef898-6cf2-4cbc-ae29-72f387ff0ee0</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<FileAlignment>512</FileAlignment> | ||
<RootNamespace>DeviceClientTests</RootNamespace> | ||
<AssemblyName>NFUnitTest</AssemblyName> | ||
<IsCodedUITest>False</IsCodedUITest> | ||
<IsTestProject>true</IsTestProject> | ||
<TestProjectType>UnitTest</TestProjectType> | ||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SignAssembly>true</SignAssembly> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<AssemblyOriginatorKeyFile>..\..\nanoFramework.Azure.Devices.Client\key.snk</AssemblyOriginatorKeyFile> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DelaySign>false</DelaySign> | ||
</PropertyGroup> | ||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" /> | ||
<ItemGroup> | ||
<Compile Include="DeviceClientTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="mscorlib"> | ||
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.12.0\lib\mscorlib.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.M2Mqtt"> | ||
<HintPath>..\..\packages\nanoFramework.M2Mqtt.5.1.59\lib\nanoFramework.M2Mqtt.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.Runtime.Events"> | ||
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.11.1\lib\nanoFramework.Runtime.Events.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.Runtime.Native"> | ||
<HintPath>..\..\packages\nanoFramework.Runtime.Native.1.5.4\lib\nanoFramework.Runtime.Native.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.System.Collections"> | ||
<HintPath>..\..\packages\nanoFramework.System.Collections.1.4.0\lib\nanoFramework.System.Collections.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.System.Text"> | ||
<HintPath>..\..\packages\nanoFramework.System.Text.1.2.22\lib\nanoFramework.System.Text.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.TestFramework"> | ||
<HintPath>..\..\packages\nanoFramework.TestFramework.2.0.60\lib\nanoFramework.TestFramework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nanoFramework.UnitTestLauncher"> | ||
<HintPath>..\..\packages\nanoFramework.TestFramework.2.0.60\lib\nanoFramework.UnitTestLauncher.exe</HintPath> | ||
</Reference> | ||
<Reference Include="System.IO.Streams"> | ||
<HintPath>..\..\packages\nanoFramework.System.IO.Streams.1.1.27\lib\System.IO.Streams.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Net"> | ||
<HintPath>..\..\packages\nanoFramework.System.Net.1.10.38\lib\System.Net.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Threading"> | ||
<HintPath>..\..\packages\nanoFramework.System.Threading.1.1.8\lib\System.Threading.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\nanoFramework.Azure.Devices.Client\Azure.Devices.Client.nfproj" /> | ||
</ItemGroup> | ||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" /> | ||
<!-- MANUAL UPDATE HERE --> | ||
<Import Project="..\..\packages\nanoFramework.TestFramework.2.0.60\build\nanoFramework.TestFramework.targets" Condition="Exists('..\..\packages\nanoFramework.TestFramework.2.0.60\build\nanoFramework.TestFramework.targets')" /> | ||
<ProjectExtensions> | ||
<ProjectCapabilities> | ||
<ProjectConfigurationsDeclaredAsItems /> | ||
</ProjectCapabilities> | ||
</ProjectExtensions> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<WarningText>Update the Import path in nfproj to the correct nanoFramework.TestFramework NuGet package folder.</WarningText> | ||
</PropertyGroup> | ||
<Warning Condition="!Exists('..\..\packages\nanoFramework.TestFramework.2.0.60\build\nanoFramework.TestFramework.targets')" Text="'$(WarningText)'" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2021 nanoFramework contributors")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.M2Mqtt" version="5.1.59" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.Runtime.Events" version="1.11.1" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.Runtime.Native" version="1.5.4" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Collections" version="1.4.0" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.IO.Streams" version="1.1.27" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Net" version="1.10.38" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Text" version="1.2.22" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Threading" version="1.1.8" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.TestFramework" version="2.0.60" targetFramework="netnano1.0" developmentDependency="true" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": { | ||
".NETnanoFramework,Version=v1.0": { | ||
"nanoFramework.CoreLibrary": { | ||
"type": "Direct", | ||
"requested": "[1.12.0, 1.12.0]", | ||
"resolved": "1.12.0", | ||
"contentHash": "qQrFNXmJiStMC4VXk5cVMOJp23/qlT9FW5i9i+igwQVwraQTtvpkam8yK1hj992jqrbjoCIFZP4Hw9E8H0pB7w==" | ||
}, | ||
"nanoFramework.M2Mqtt": { | ||
"type": "Direct", | ||
"requested": "[5.1.59, 5.1.59]", | ||
"resolved": "5.1.59", | ||
"contentHash": "/q/+sKyASsut6vz9f8V1/BQqdBt8H9WVurabW/WLvxq5I14+Ov8wDt7SnBOv4X4fwys88gfTHsCsX7ZX7Z0BcA==" | ||
}, | ||
"nanoFramework.Runtime.Events": { | ||
"type": "Direct", | ||
"requested": "[1.11.1, 1.11.1]", | ||
"resolved": "1.11.1", | ||
"contentHash": "hHRPhNagq1T0oN9QJfPOqreuWUV42DJamT0f7GrPQvrOYcr9ne4YTZq8MIpudvKtSALs50iYqxJ+raOF2CiNsA==" | ||
}, | ||
"nanoFramework.Runtime.Native": { | ||
"type": "Direct", | ||
"requested": "[1.5.4, 1.5.4]", | ||
"resolved": "1.5.4", | ||
"contentHash": "qfaOY1O5TOEw//MO4AOWRq5CdZXTfd3KnsGTNU2yw+IEYKiQLPkJhtF3ufF/S04xfXL556S2kOFG3/RZrwQ4Qw==" | ||
}, | ||
"nanoFramework.System.Collections": { | ||
"type": "Direct", | ||
"requested": "[1.4.0, 1.4.0]", | ||
"resolved": "1.4.0", | ||
"contentHash": "/yFwxtCFzi+24NuyxcwlH1YyBGOxRX4oHGLwVmFbgbvOyx3ny/Mwyk2YjHTzmTSgUg9C2XxPF+EkXWwCOAkytw==" | ||
}, | ||
"nanoFramework.System.IO.Streams": { | ||
"type": "Direct", | ||
"requested": "[1.1.27, 1.1.27]", | ||
"resolved": "1.1.27", | ||
"contentHash": "9ho/C/ZIQrBw51UnzLVbSc//kE1mDcgykGEZH8p+A5Q4R7JMVwdEKlNQXWr1VHEkGbv2wbyos6nRLqu2rdjpwA==" | ||
}, | ||
"nanoFramework.System.Net": { | ||
"type": "Direct", | ||
"requested": "[1.10.38, 1.10.38]", | ||
"resolved": "1.10.38", | ||
"contentHash": "vMGSqPoJvvXmpJXir/QH7vgj3n3M/705IQtmWRo0a99HdVaXnc0iZmmRtLi8JKNGngwEDZ0ge4+ZBBqqtSsyrw==" | ||
}, | ||
"nanoFramework.System.Text": { | ||
"type": "Direct", | ||
"requested": "[1.2.22, 1.2.22]", | ||
"resolved": "1.2.22", | ||
"contentHash": "vLvU0II3oJfajQ8MgNm8aCkaQ2JhjznzruwksOorbMJf86zLRbA5NUeg9X/KjbAE5pIalitUOqtNLKorYTbYGg==" | ||
}, | ||
"nanoFramework.System.Threading": { | ||
"type": "Direct", | ||
"requested": "[1.1.8, 1.1.8]", | ||
"resolved": "1.1.8", | ||
"contentHash": "oES5GN3KHoDzifRNr06WM7P9NaQf+kDmIYkr1ETR2awmERHz4sRpECduGEatwyo1vMhMvZY/KoBcEpAyKNbDgQ==" | ||
}, | ||
"nanoFramework.TestFramework": { | ||
"type": "Direct", | ||
"requested": "[2.0.60, 2.0.60]", | ||
"resolved": "2.0.60", | ||
"contentHash": "Sl+jB89CV3bAX4lmVoJYF/75a4EOjyfQSgaa6sPlUerUEI24y8KK4+s3EOv9UJFz6MGgJWJkQIas6D0Zv1jELw==" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.