diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/TestHub.cs b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/TestHub.cs index d4f6fb94b4..3821a03b02 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/TestHub.cs +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/TestHub.cs @@ -8,6 +8,13 @@ using System.Threading.Tasks; namespace Microsoft.AspNetCore.SignalR.Test.Server { + public class CustomObject + { + public string Name { get; set; } + + public int Value { get; set; } + } + public class TestHub : Hub { public string Echo(string message) @@ -25,6 +32,11 @@ namespace Microsoft.AspNetCore.SignalR.Test.Server return Clients.Client(Context.Connection.ConnectionId).InvokeAsync("Message", message); } + public Task SendCustomObject(CustomObject customObject) + { + return Clients.Client(Context.ConnectionId).InvokeAsync("CustomObject", customObject); + } + public IObservable Stream() { return new string[] { "a", "b", "c" }.ToObservable(); diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js index fc428da7af..a5b7fcaec7 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js @@ -37,6 +37,40 @@ describe('hubConnection', function () { }); }); + it('can invoke server method structural object and receive structural result', function (done) { + var options = { + transport: transportType, + protocol: protocol, + logging: signalR.LogLevel.Trace + }; + var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options); + + hubConnection.on('CustomObject', function (customObject) { + // messageapack does not have a setting to use camelCasing + if (protocol.name == 'messagepack') { + expect(customObject.Name).toBe('test'); + expect(customObject.Value).toBe(42); + } + else { + expect(customObject.name).toBe('test'); + expect(customObject.value).toBe(42); + } + hubConnection.stop(); + }); + + hubConnection.onclose(function (error) { + expect(error).toBe(undefined); + done(); + }); + + hubConnection.start().then(function () { + hubConnection.send('SendCustomObject', { Name: "test", Value: 42}); + }).catch(function (e) { + fail(e); + done(); + }); + }); + it('can stream server method and receive result', function (done) { var options = {