File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
SocketIOClient.Test/SocketIOTests Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System . Collections . Generic ;
3+ using System . Threading . Tasks ;
4+
5+ namespace SocketIOClient . Test . SocketIOTests
6+ {
7+ public abstract class HeadersTest
8+ {
9+ protected abstract ISocketIOCreateable SocketIOCreator { get ; }
10+
11+ public async virtual Task CustomHeader ( )
12+ {
13+ string result = null ;
14+
15+ var client = new SocketIO ( SocketIOCreator . Url , new SocketIOOptions
16+ {
17+ Reconnection = false ,
18+ Query = new List < KeyValuePair < string , string > >
19+ {
20+ new KeyValuePair < string , string > ( "token" , SocketIOCreator . Token )
21+ } ,
22+ ExtraHeaders = new Dictionary < string , string >
23+ {
24+ { "CustomHeader" , "CustomHeader-Value" }
25+ }
26+ } ) ;
27+
28+ client . OnConnected += async ( sender , e ) =>
29+ {
30+ var sio = sender as SocketIO ;
31+ await sio . EmitAsync ( "headers" , response =>
32+ {
33+ result = response . GetValue ( ) . GetProperty ( "customheader" ) . GetString ( ) ;
34+ } ) ;
35+ } ;
36+
37+ await client . ConnectAsync ( ) ;
38+ await Task . Delay ( 400 ) ;
39+
40+ Assert . AreEqual ( result , "CustomHeader-Value" ) ;
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System . Threading . Tasks ;
3+
4+ namespace SocketIOClient . Test . SocketIOTests . V3
5+ {
6+ [ TestClass ]
7+ public class HeadersV3Test : HeadersTest
8+ {
9+ public HeadersV3Test ( )
10+ {
11+ SocketIOCreator = new SocketIOV3Creator ( ) ;
12+ }
13+
14+ protected override ISocketIOCreateable SocketIOCreator { get ; }
15+
16+ [ TestMethod ]
17+ public override async Task CustomHeader ( )
18+ {
19+ await base . CustomHeader ( ) ;
20+ }
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ io.on('connection', socket => {
3232 socket . emit ( 'hi' , prefix + msg ) ;
3333 } ) ;
3434
35+ socket . on ( 'headers' , cb => {
36+ cb ( socket . request . headers )
37+ } ) ;
38+
3539 socket . on ( 'welcome' , ( ) => {
3640 //socket.emit('welcome', Buffer.from("welcome " + socket.id, 'utf8'));
3741 socket . emit ( 'welcome' , Buffer . from ( "a" , 'utf8' ) ) ;
You can’t perform that action at this time.
0 commit comments