Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion CoreRemoting.Tests/BsonHashtableRpcTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections;
using CoreRemoting.Serialization.Bson;
using Xunit;
using CoreRemoting.DependencyInjection;
using Newtonsoft.Json.Linq;

namespace CoreRemoting.Tests
{
Expand Down Expand Up @@ -62,4 +65,97 @@ public void BsonSerializerAdapter_should_preserve_Hashtable_types_without_Envelo
Assert.True(deserializedHashtable["IntValue"] is int);
}
}
}

#region Hashtable Deserialization Bug - RPC Roundtrip Test

public interface IHashtableEchoService
{
Hashtable Echo(Hashtable input);
}

public class HashtableEchoService : IHashtableEchoService
{
public Hashtable Echo(Hashtable input)
{
if (input != null)
{
foreach (DictionaryEntry entry in input)
{
if (entry.Value is JObject)
{
throw new InvalidOperationException(
$"BUG REPRODUCED: Parameter '{entry.Key}' deserialized as JObject. " +
$"Original type was lost during deserialization.");
}
}
}

return input;
}
}

public class HashtableDeserializationBugTest : IDisposable
{
private readonly RemotingServer _server;
private readonly RemotingClient _client;

public HashtableDeserializationBugTest()
{
var serverConfig = new ServerConfig
{
HostName = "localhost",
NetworkPort = 9099,
RegisterServicesAction = container =>
{
container.RegisterService<IHashtableEchoService, HashtableEchoService>(
lifetime: ServiceLifetime.Singleton);
}
};

_server = new RemotingServer(serverConfig);
_server.Start();

var clientConfig = new ClientConfig
{
ServerHostName = "localhost",
ServerPort = 9099,
ConnectionTimeout = 5000
};

_client = new RemotingClient(clientConfig);
_client.Connect();
}

[Fact]
public void Hashtable_ShouldSurviveRoundtrip_WithoutBecomingJObject()
{
var proxy = _client.CreateProxy<IHashtableEchoService>();
var original = new Hashtable
{
{ "@param1", "test_value" },
{ "@param2", 123 },
{ "@param3", true }
};

var exception = Record.Exception(() =>
{
var result = proxy.Echo(original);

foreach (DictionaryEntry entry in result)
{
Assert.IsNotType<JObject>(entry.Value);
}
});

Assert.Null(exception);
}

public void Dispose()
{
_client?.Dispose();
_server?.Dispose();
}
}

#endregion
}
Loading