Skip to content

Commit

Permalink
Fixing serialisation issue with special characters in Compatibility m…
Browse files Browse the repository at this point in the history
…ode.
  • Loading branch information
TheCodeKing committed Jan 28, 2017
1 parent 126554a commit aa16635
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 11 deletions.
2 changes: 1 addition & 1 deletion License
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
XDMessaging.Net (https://github.com/TheCodeKing/XDMessaging.Net)
--------------------------------------
Copyright (c) 2016 Mike Carlisle
Copyright (c) 2017 Mike Carlisle

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
Binary file modified bin/Messenger.exe
Binary file not shown.
Binary file modified bin/XDMessaging.Lite.dll
Binary file not shown.
Binary file modified bin/XDMessaging.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions nuget/XDMessaging.Lite.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package >
<metadata>
<id>XDMessaging.Lite</id>
<version>5.0.1</version>
<version>5.0.2</version>
<title>XDMessaging Lite Library</title>
<authors>TheCodeKing</authors>
<owners>TheCodeKing</owners>
<licenseUrl>https://github.com/TheCodeKing/XDMessaging.Net/blob/master/License</licenseUrl>
<projectUrl>http://thecodeking.github.com/XDMessaging.Net/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>The XDMessaging library provides an easy-to-use, zero configuration solution to inter-process communication for .NET applications. It provides a simple API for broadcasting and receiving messages across application domain and process. Lite version excludes network propagation functionality.</description>
<copyright>Copyright 2016</copyright>
<copyright>Copyright 2017</copyright>
<tags>IPC crossdomain interprocess communication messaging amazon queuing messaging remoting AWS pubsub</tags>
<references>
<reference file="XDMessaging.Lite.dll" />
Expand Down
4 changes: 2 additions & 2 deletions nuget/XDMessaging.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package >
<metadata>
<id>XDMessaging</id>
<version>5.0.1</version>
<version>5.0.2</version>
<title>XDMessaging Library</title>
<authors>TheCodeKing</authors>
<owners>TheCodeKing</owners>
<licenseUrl>https://github.com/TheCodeKing/XDMessaging.Net/blob/master/License</licenseUrl>
<projectUrl>http://thecodeking.github.com/XDMessaging.Net/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>The XDMessaging library provides an easy-to-use, zero configuration solution to inter-process communication for .NET applications. It provides a simple API for broadcasting and receiving messages across application domain, process, and even network boundaries.</description>
<copyright>Copyright 2016</copyright>
<copyright>Copyright 2017</copyright>
<tags>IPC crossdomain interprocess communication messaging amazon queuing messaging remoting AWS pubsub</tags>
<references>
<reference file="XDMessaging.dll" />
Expand Down
10 changes: 5 additions & 5 deletions src/XDMessaging.Lite/Properties/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
using System.Runtime.CompilerServices;

[assembly: AssemblyCompany("TheCodeKing")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("5.0.1")]
[assembly: AssemblyFileVersion("5.0.1")]
[assembly: AssemblyVersion("5.0.2")]
[assembly: AssemblyFileVersion("5.0.2")]

#if SIGNED
[assembly: InternalsVisibleTo("XDMessaging.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f1061ea0d5d0eb099e3796f495bcfa7b50b9c48085233e18013cadfe86cb8a841547d0a26b0f1ddea1c5759d510032e031caf0925cac3346955127c2e52304bd825186bfb39b7048030549c006fa06070ca8b708c83a77d41a16cff0e43d7b72d2c61739766c048bec598f6ef7d9b0ad19aeaac8854133c0603a740a5f67e9b8")]
[assembly: InternalsVisibleTo("XDMessaging.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f1061ea0d5d0eb099e3796f495bcfa7b50b9c48085233e18013cadfe86cb8a841547d0a26b0f1ddea1c5759d510032e031caf0925cac3346955127c2e52304bd825186bfb39b7048030549c006fa06070ca8b708c83a77d41a16cff0e43d7b72d2c61739766c048bec598f6ef7d9b0ad19aeaac8854133c0603a740a5f67e9b8")]
[assembly: AssemblyKeyFile(@"..\..\..\..\..\thecodeking.snk")]
#else
[assembly: InternalsVisibleTo("XDMessaging.Tests")]
[assembly: InternalsVisibleTo("XDMessaging.Test")]
#endif
2 changes: 1 addition & 1 deletion src/XDMessaging.Lite/Serialization/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public string Serialize<T>(T obj) where T : class
{
var serializer = new DataContractJsonSerializer(typeof (T));
serializer.WriteObject(stream, obj);
return Encoding.Default.GetString(stream.ToArray());
return Encoding.UTF8.GetString(stream.ToArray());
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/XDMessaging.Test/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="AWSAccessKey" value=""/>
<add key="AWSSecretKey" value=""/>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
96 changes: 96 additions & 0 deletions src/XDMessaging.Test/DataGramSerializerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using NUnit.Framework;
using XDMessaging.Messages;
using XDMessaging.Serialization;

namespace XDMessaging.Test
{
[TestFixture]
public class DataGramSerializerTests
{
#region Setup/Teardown

[SetUp]
public void SetUp()
{
serializer = new JsonSerializer();
}

#endregion

private const string channel = "myChannel";
private const string assemblyQualifiedName = "myAssemblyQualifiedName";
private const string message = "myMessage";
private JsonSerializer serializer;

[Test]
public void GivenADatagramWithSpecialCharsWhenSerializedThenSuccess()
{
// arrange
var specialMsg = "汉字";
var dataGram = new DataGram(channel, assemblyQualifiedName, specialMsg);

// act
var result = serializer.Serialize(dataGram);

// assert
Assert.That(result, Is.StringContaining(channel));
Assert.That(result, Is.StringContaining(specialMsg));
Assert.That(result, Is.StringContaining(assemblyQualifiedName));
Assert.That(result, Is.StringContaining("1.1"));
}

[Test]
public void GivenADatagramWhenSerializedThenSuccess()
{
// arrange
var dataGram = new DataGram(channel, assemblyQualifiedName, message);

// act
var result = serializer.Serialize(dataGram);

// assert
Assert.That(result, Is.StringContaining(channel));
Assert.That(result, Is.StringContaining(message));
Assert.That(result, Is.StringContaining(assemblyQualifiedName));
Assert.That(result, Is.StringContaining("1.1"));
}

[Test]
public void GivenASerializedDataGramVer2WhenDeserializedThenSuccess()
{
// arrange
const string msg =
"{\"ver\":\"2.0\",\"type\":\"" + assemblyQualifiedName + "\",\"channel\":\"" + channel +
"\",\"message\":\"" + message + "\"}";

// act
var dataGram = serializer.Deserialize<DataGram>(msg);

// assert
Assert.That(dataGram, Is.Not.Null);
Assert.That(dataGram.Channel, Is.EqualTo(channel));
Assert.That(dataGram.Message, Is.EqualTo(message));
Assert.That(dataGram.AssemblyQualifiedName, Is.EqualTo(assemblyQualifiedName));
Assert.That(dataGram.Version, Is.EqualTo("2.0"));
}

[Test]
public void GivenASerializedDataGramVersion1WhenDeserializedThenSuccess()
{
// arrange
const string msg = "{\"ver\":\"1.0\",\"channel\":\"" + channel + "\",\"message\":\"" + message + "\"}";

// act
var dataGram = serializer.Deserialize<DataGram>(msg);

// assert
Assert.That(dataGram, Is.Not.Null);
Assert.That(dataGram.Channel, Is.EqualTo(channel));
Assert.That(dataGram.Message, Is.EqualTo(message));
Assert.That(dataGram.Version, Is.EqualTo("1.0"));
string result;
Assert.Throws<NotSupportedException>(() => result = dataGram.AssemblyQualifiedName);
}
}
}
15 changes: 15 additions & 0 deletions src/XDMessaging.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("TheCodeKing")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("5.0.2")]
[assembly: AssemblyFileVersion("5.0.2")]
[assembly: ComVisible(false)]
[assembly: Guid("6ca3fc60-ba34-46c0-8550-9a4aa3ce8340")]

#if SIGNED
[assembly: AssemblyKeyFile(@"..\..\..\..\..\thecodeking.snk")]
#endif
78 changes: 78 additions & 0 deletions src/XDMessaging.Test/XDMessaging.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6CA3FC60-BA34-46C0-8550-9A4AA3CE8340}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XDMessaging.Test</RootNamespace>
<AssemblyName>XDMessaging.Test</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.5.30.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.30\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataGramSerializerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XDMessagingClientExtensionTests.cs" />
<Compile Include="XDMessagingClientTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XDMessaging\XDMessaging.csproj">
<Project>{e5a12ed6-6cd9-4758-b508-a6bb8554b7cc}</Project>
<Name>XDMessaging</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
86 changes: 86 additions & 0 deletions src/XDMessaging.Test/XDMessagingClientExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using NUnit.Framework;

namespace XDMessaging.Test
{
[TestFixture]
public class XDMessagingClientExtensionTests
{
[Test]
public void GivenAmazonBroadcastImplThenShouldResolveSuccess()
{
// arrange
var client = new XDMessagingClient();

// act
var instance = client.Broadcasters.GetAmazonBroadcaster();

// assert
Assert.That(instance, Is.Not.Null);
}

[Test]
public void GivenAmazonListenerImplThenShouldResolveInstanceSuccess()
{
// arrange
var client = new XDMessagingClient();

// act
var instance = client.Listeners.GetAmazonListener();

// assert
Assert.That(instance, Is.Not.Null);
}

[Test]
public void GivenIoStreamBroadcastImplThenShouldResolveSuccess()
{
// arrange
var client = new XDMessagingClient();

// act
var instance = client.Broadcasters.GetIOStreamBroadcaster();

// assert
Assert.That(instance, Is.Not.Null);
}

[Test]
public void GivenIoStreamListenerImplThenShouldResolveSuccess()
{
// arrange
var client = new XDMessagingClient();

// act
var instance = client.Listeners.GetIOStreamListener();

// assert
Assert.That(instance, Is.Not.Null);
}

[Test]
public void GivenWindowsMessagingBroadcastImplThenShouldResolveSuccess()
{
// arrange
var client = new XDMessagingClient();

// act
var instance = client.Broadcasters.GetWindowsMessagingBroadcaster();

// assert
Assert.That(instance, Is.Not.Null);
}

[Test]
public void GivenWindowsMessagingListenerImplThenShouldResolveInstanceSuccess()
{
// arrange
var client = new XDMessagingClient();

// act
var instance = client.Listeners.GetWindowsMessagingListener();

// assert
Assert.That(instance, Is.Not.Null);
}
}
}
Loading

0 comments on commit aa16635

Please sign in to comment.