@@ -89,6 +89,57 @@ public async Task TestCommands(Type hostConfiguratorType)
89
89
}
90
90
}
91
91
92
+ [ Theory ]
93
+ [ InlineData ( typeof ( RegularHostConfigurator ) ) ]
94
+ [ InlineData ( typeof ( SecureHostConfigurator ) ) ]
95
+ public async Task TestUnknownCommands ( Type hostConfiguratorType )
96
+ {
97
+ var hostConfigurator = CreateObject < IHostConfigurator > ( hostConfiguratorType ) ;
98
+ using ( var server = CreateSocketServerBuilder < StringPackageInfo , CommandLinePipelineFilter > ( hostConfigurator )
99
+ . UseCommand ( commandOptions =>
100
+ {
101
+ // register commands one by one
102
+ commandOptions . AddCommand < ADD > ( ) ;
103
+ commandOptions . RegisterUnknownPackageHandler < StringPackageInfo > ( async ( session , package , cancellationToken ) =>
104
+ {
105
+ await session . SendAsync ( Encoding . UTF8 . GetBytes ( "X\r \n " ) ) ;
106
+ } ) ;
107
+
108
+ // register all commands in one assembly
109
+ //commandOptions.AddCommandAssembly(typeof(SUB).GetTypeInfo().Assembly);
110
+ } )
111
+ . BuildAsServer ( ) )
112
+ {
113
+
114
+ Assert . Equal ( "TestServer" , server . Name ) ;
115
+
116
+ Assert . True ( await server . StartAsync ( ) ) ;
117
+ OutputHelper . WriteLine ( "Server started." ) ;
118
+
119
+
120
+ var client = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
121
+ await client . ConnectAsync ( hostConfigurator . GetServerEndPoint ( ) ) ;
122
+ OutputHelper . WriteLine ( "Connected." ) ;
123
+
124
+ using ( var stream = await hostConfigurator . GetClientStream ( client ) )
125
+ using ( var streamReader = new StreamReader ( stream , Utf8Encoding , true ) )
126
+ using ( var streamWriter = new StreamWriter ( stream , Utf8Encoding , 1024 * 1024 * 4 ) )
127
+ {
128
+ await streamWriter . WriteAsync ( "ADD 1 2 3\r \n " ) ;
129
+ await streamWriter . FlushAsync ( ) ;
130
+ var line = await streamReader . ReadLineAsync ( ) ;
131
+ Assert . Equal ( "6" , line ) ;
132
+
133
+ await streamWriter . WriteAsync ( "MULT 2 5\r \n " ) ;
134
+ await streamWriter . FlushAsync ( ) ;
135
+ line = await streamReader . ReadLineAsync ( ) ;
136
+ Assert . Equal ( "X" , line ) ;
137
+ }
138
+
139
+ await server . StopAsync ( ) ;
140
+ }
141
+ }
142
+
92
143
[ Theory ]
93
144
[ InlineData ( typeof ( RegularHostConfigurator ) ) ]
94
145
[ InlineData ( typeof ( SecureHostConfigurator ) ) ]
0 commit comments