diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/ComplexObject.cs b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/ComplexObject.cs index 8624b6d246..7ae481c348 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/ComplexObject.cs +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/ComplexObject.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.SignalR.Test.Server { public class ComplexObject @@ -8,5 +10,6 @@ namespace Microsoft.AspNetCore.SignalR.Test.Server public string String { get; set; } public int[] IntArray { get; set; } public byte[] ByteArray { get; set; } + public Guid GUID { get; set; } } } \ No newline at end of file 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 84eadbbc97..68d4698959 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 @@ -301,17 +301,30 @@ describe('hubConnection', function () { IntArray: [0x01, 0x02, 0x03, 0xff], ByteArray: protocol.name == "json" ? btoa([0xff, 0x03, 0x02, 0x01]) - : new Uint8Array([0xff, 0x03, 0x02, 0x01]) + : new Uint8Array([0xff, 0x03, 0x02, 0x01]), + GUID: protocol.name == "json" + ? "00010203-0405-0607-0706-050403020100" + : new Uint8Array([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00]) }; hubConnection.start().then(function () { return hubConnection.invoke('EchoComplexObject', complexObject); }) .then(function (value) { - // msgpack creates a Buffer for byte arrays and jasmine fails to compare a Buffer - // and a Uint8Array even though Buffer instances are also Uint8Array instances if (protocol.name == "messagepack") { + // msgpack creates a Buffer for byte arrays and jasmine fails to compare a Buffer + // and a Uint8Array even though Buffer instances are also Uint8Array instances value.ByteArray = new Uint8Array(value.ByteArray); + + // GUIDs are serialized as raw type which is a string containing bytes which need to + // be extracted. Note that with msgpack5 the original bytes will be encoded with utf8 + // and needs to be decoded. To not go into utf8 encoding intricacies the test uses values + // less than 0x80. + let guidBytes = []; + for (let i = 0; i < value.GUID.length; i++) { + guidBytes.push(value.GUID.charCodeAt(i)); + } + value.GUID = new Uint8Array(guidBytes); } expect(value).toEqual(complexObject); })