Adding JS tests that send and receive structural objects

This commit is contained in:
Pawel Kadluczka 2017-09-22 14:28:30 -07:00 committed by Pawel Kadluczka
parent 8743723ece
commit 1686878035
2 changed files with 46 additions and 0 deletions

View File

@ -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<string> Stream()
{
return new string[] { "a", "b", "c" }.ToObservable();

View File

@ -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 = {