Skip to content

Commit

Permalink
Add support for dynamic objects that are not nested in any container …
Browse files Browse the repository at this point in the history
…type (e.g. array or map).
  • Loading branch information
Louis Somers committed Feb 26, 2021
1 parent 8f9edaa commit 87979ec
Show file tree
Hide file tree
Showing 18 changed files with 705 additions and 234 deletions.
16 changes: 9 additions & 7 deletions LightUnitTests/LightUnitTests.csproj
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" />
<Import Project="..\packages\NUnit.3.13.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.13.1\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LightUnitTests</RootNamespace>
<AssemblyName>LightUnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,8 +34,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.13.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.13.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -58,6 +59,7 @@
<Compile Include="MpIntTest.cs" />
<Compile Include="MpMapTest.cs" />
<Compile Include="MpNullTest.cs" />
<Compile Include="MpRootTests.cs" />
<Compile Include="MpStringTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializingObjects.cs" />
Expand All @@ -69,17 +71,17 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.10.1\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit.3.13.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.1\build\NUnit.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
29 changes: 29 additions & 0 deletions LightUnitTests/MpRootTests.cs
@@ -0,0 +1,29 @@
using LsMsgPack;
using NUnit.Framework;

namespace LsMsgPackUnitTests {
[TestFixture]
public class MpRootTests {

[TestCase(7, 1, "hello")]
[TestCase(13, new object[] { (byte)0, new object[] { (short)597, (short)492 }, new object[0], (byte)0, (byte)0, "\u0001" })]
public void RoundTripTest(int expectedLength, params object[] items) {
MpRoot root = MsgPackItem.PackMultiple(items);
byte[] bytes = root.ToBytes();

Assert.AreEqual(expectedLength, bytes.Length, string.Concat("Expected ", expectedLength, " serialized bytes items but got ", bytes.Length, " bytes."));

MpRoot result = MsgPackItem.UnpackMultiple(bytes);

Assert.AreEqual(items.Length, result.Count, string.Concat("Expected ",items.Length," items but got ", result.Count, " items after round trip."));

for (int t = 0; t < result.Count; t++) {
object expected = items[t];
object actual = result[t].Value;

Assert.AreEqual(expected, actual, "The returned value ", actual, " differs from the input value ", expected);
}
}

}
}
2 changes: 1 addition & 1 deletion LightUnitTests/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.10.1" targetFramework="net452" />
<package id="NUnit" version="3.13.1" targetFramework="net461" />
</packages>
1 change: 1 addition & 0 deletions LsMsgPack/LsMsgPack.csproj
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Types\MpMap.cs" />
<Compile Include="Types\MpArray.cs" />
<Compile Include="Types\MpBin.cs" />
<Compile Include="Types\MpRoot.cs" />
<Compile Include="Types\MpString.cs" />
<Compile Include="MsgPackVarLen.cs" />
<Compile Include="Types\MpFloat.cs" />
Expand Down

0 comments on commit 87979ec

Please sign in to comment.