Adding roundtripping test for GUID property
This commit is contained in:
parent
dde1a75b80
commit
13757936ad
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue