Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 1 | // Licensed to the Apache Software Foundation(ASF) under one |
| 2 | // or more contributor license agreements.See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership.The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | using System; |
| 19 | using System.IO; |
| 20 | using System.Text; |
| 21 | using System.Threading.Tasks; |
| 22 | using KellermanSoftware.CompareNetObjects; |
| 23 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 24 | using Thrift.Protocol; |
| 25 | using Thrift.Protocol.Entities; |
| 26 | using Thrift.Transport.Client; |
| 27 | |
| 28 | namespace Thrift.IntegrationTests.Protocols |
| 29 | { |
| 30 | [TestClass] |
| 31 | public class ProtocolsOperationsTests |
| 32 | { |
| 33 | private readonly CompareLogic _compareLogic = new CompareLogic(); |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 34 | private static readonly TConfiguration Configuration = null; // or new TConfiguration() if needed |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 35 | |
| 36 | [DataTestMethod] |
| 37 | [DataRow(typeof(TBinaryProtocol), TMessageType.Call)] |
| 38 | [DataRow(typeof(TBinaryProtocol), TMessageType.Exception)] |
| 39 | [DataRow(typeof(TBinaryProtocol), TMessageType.Oneway)] |
| 40 | [DataRow(typeof(TBinaryProtocol), TMessageType.Reply)] |
| 41 | [DataRow(typeof(TCompactProtocol), TMessageType.Call)] |
| 42 | [DataRow(typeof(TCompactProtocol), TMessageType.Exception)] |
| 43 | [DataRow(typeof(TCompactProtocol), TMessageType.Oneway)] |
| 44 | [DataRow(typeof(TCompactProtocol), TMessageType.Reply)] |
| 45 | [DataRow(typeof(TJsonProtocol), TMessageType.Call)] |
| 46 | [DataRow(typeof(TJsonProtocol), TMessageType.Exception)] |
| 47 | [DataRow(typeof(TJsonProtocol), TMessageType.Oneway)] |
| 48 | [DataRow(typeof(TJsonProtocol), TMessageType.Reply)] |
| 49 | public async Task WriteReadMessage_Test(Type protocolType, TMessageType messageType) |
| 50 | { |
| 51 | var expected = new TMessage(nameof(TMessage), messageType, 1); |
| 52 | |
| 53 | try |
| 54 | { |
| 55 | var tuple = GetProtocolInstance(protocolType); |
| 56 | using (var stream = tuple.Item1) |
| 57 | { |
| 58 | var protocol = tuple.Item2; |
| 59 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 60 | await protocol.WriteMessageBeginAsync(expected, default); |
| 61 | await protocol.WriteMessageEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 62 | |
| 63 | stream.Seek(0, SeekOrigin.Begin); |
| 64 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 65 | var actualMessage = await protocol.ReadMessageBeginAsync(default); |
| 66 | await protocol.ReadMessageEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 67 | |
| 68 | var result = _compareLogic.Compare(expected, actualMessage); |
| 69 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 70 | } |
| 71 | } |
| 72 | catch (Exception e) |
| 73 | { |
| 74 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | [DataTestMethod] |
| 79 | [DataRow(typeof(TBinaryProtocol))] |
| 80 | [DataRow(typeof(TCompactProtocol))] |
| 81 | [DataRow(typeof(TJsonProtocol))] |
| 82 | [ExpectedException(typeof(Exception))] |
| 83 | public async Task WriteReadStruct_Test(Type protocolType) |
| 84 | { |
| 85 | var expected = new TStruct(nameof(TStruct)); |
| 86 | |
| 87 | try |
| 88 | { |
| 89 | var tuple = GetProtocolInstance(protocolType); |
| 90 | using (var stream = tuple.Item1) |
| 91 | { |
| 92 | var protocol = tuple.Item2; |
| 93 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 94 | await protocol.WriteStructBeginAsync(expected, default); |
| 95 | await protocol.WriteStructEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 96 | |
| 97 | stream?.Seek(0, SeekOrigin.Begin); |
| 98 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 99 | var actual = await protocol.ReadStructBeginAsync(default); |
| 100 | await protocol.ReadStructEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 101 | |
| 102 | var result = _compareLogic.Compare(expected, actual); |
| 103 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 104 | } |
| 105 | |
| 106 | } |
| 107 | catch (Exception e) |
| 108 | { |
| 109 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | [DataTestMethod] |
| 114 | [DataRow(typeof(TBinaryProtocol))] |
| 115 | [DataRow(typeof(TCompactProtocol))] |
| 116 | [DataRow(typeof(TJsonProtocol))] |
| 117 | [ExpectedException(typeof(Exception))] |
| 118 | public async Task WriteReadField_Test(Type protocolType) |
| 119 | { |
| 120 | var expected = new TField(nameof(TField), TType.String, 1); |
| 121 | |
| 122 | try |
| 123 | { |
| 124 | var tuple = GetProtocolInstance(protocolType); |
| 125 | using (var stream = tuple.Item1) |
| 126 | { |
| 127 | var protocol = tuple.Item2; |
| 128 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 129 | await protocol.WriteFieldBeginAsync(expected, default); |
| 130 | await protocol.WriteFieldEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 131 | |
| 132 | stream?.Seek(0, SeekOrigin.Begin); |
| 133 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 134 | var actual = await protocol.ReadFieldBeginAsync(default); |
| 135 | await protocol.ReadFieldEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 136 | |
| 137 | var result = _compareLogic.Compare(expected, actual); |
| 138 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 139 | } |
| 140 | } |
| 141 | catch (Exception e) |
| 142 | { |
| 143 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | [DataTestMethod] |
| 148 | [DataRow(typeof(TBinaryProtocol))] |
| 149 | [DataRow(typeof(TCompactProtocol))] |
| 150 | [DataRow(typeof(TJsonProtocol))] |
| 151 | public async Task WriteReadMap_Test(Type protocolType) |
| 152 | { |
| 153 | var expected = new TMap(TType.String, TType.String, 1); |
| 154 | |
| 155 | try |
| 156 | { |
| 157 | var tuple = GetProtocolInstance(protocolType); |
| 158 | using (var stream = tuple.Item1) |
| 159 | { |
| 160 | var protocol = tuple.Item2; |
| 161 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 162 | await protocol.WriteMapBeginAsync(expected, default); |
| 163 | await protocol.WriteMapEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 164 | |
| 165 | stream?.Seek(0, SeekOrigin.Begin); |
| 166 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 167 | var actual = await protocol.ReadMapBeginAsync(default); |
| 168 | await protocol.ReadMapEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 169 | |
| 170 | var result = _compareLogic.Compare(expected, actual); |
| 171 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 172 | } |
| 173 | } |
| 174 | catch (Exception e) |
| 175 | { |
| 176 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 177 | } |
| 178 | |
| 179 | } |
| 180 | |
| 181 | [DataTestMethod] |
| 182 | [DataRow(typeof(TBinaryProtocol))] |
| 183 | [DataRow(typeof(TCompactProtocol))] |
| 184 | [DataRow(typeof(TJsonProtocol))] |
| 185 | public async Task WriteReadList_Test(Type protocolType) |
| 186 | { |
| 187 | var expected = new TList(TType.String, 1); |
| 188 | |
| 189 | try |
| 190 | { |
| 191 | var tuple = GetProtocolInstance(protocolType); |
| 192 | using (var stream = tuple.Item1) |
| 193 | { |
| 194 | var protocol = tuple.Item2; |
| 195 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 196 | await protocol.WriteListBeginAsync(expected, default); |
| 197 | await protocol.WriteListEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 198 | |
| 199 | stream?.Seek(0, SeekOrigin.Begin); |
| 200 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 201 | var actual = await protocol.ReadListBeginAsync(default); |
| 202 | await protocol.ReadListEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 203 | |
| 204 | var result = _compareLogic.Compare(expected, actual); |
| 205 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 206 | } |
| 207 | } |
| 208 | catch (Exception e) |
| 209 | { |
| 210 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | [DataTestMethod] |
| 215 | [DataRow(typeof(TBinaryProtocol))] |
| 216 | [DataRow(typeof(TCompactProtocol))] |
| 217 | [DataRow(typeof(TJsonProtocol))] |
| 218 | public async Task WriteReadSet_Test(Type protocolType) |
| 219 | { |
| 220 | var expected = new TSet(TType.String, 1); |
| 221 | |
| 222 | try |
| 223 | { |
| 224 | var tuple = GetProtocolInstance(protocolType); |
| 225 | using (var stream = tuple.Item1) |
| 226 | { |
| 227 | var protocol = tuple.Item2; |
| 228 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 229 | await protocol.WriteSetBeginAsync(expected, default); |
| 230 | await protocol.WriteSetEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 231 | |
| 232 | stream?.Seek(0, SeekOrigin.Begin); |
| 233 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 234 | var actual = await protocol.ReadSetBeginAsync(default); |
| 235 | await protocol.ReadSetEndAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 236 | |
| 237 | var result = _compareLogic.Compare(expected, actual); |
| 238 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 239 | } |
| 240 | } |
| 241 | catch (Exception e) |
| 242 | { |
| 243 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | [DataTestMethod] |
| 248 | [DataRow(typeof(TBinaryProtocol))] |
| 249 | [DataRow(typeof(TCompactProtocol))] |
| 250 | [DataRow(typeof(TJsonProtocol))] |
| 251 | public async Task WriteReadBool_Test(Type protocolType) |
| 252 | { |
| 253 | var expected = true; |
| 254 | |
| 255 | try |
| 256 | { |
| 257 | var tuple = GetProtocolInstance(protocolType); |
| 258 | using (var stream = tuple.Item1) |
| 259 | { |
| 260 | var protocol = tuple.Item2; |
| 261 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 262 | await protocol.WriteBoolAsync(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 263 | |
| 264 | stream?.Seek(0, SeekOrigin.Begin); |
| 265 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 266 | var actual = await protocol.ReadBoolAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 267 | |
| 268 | var result = _compareLogic.Compare(expected, actual); |
| 269 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 270 | } |
| 271 | } |
| 272 | catch (Exception e) |
| 273 | { |
| 274 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | [DataTestMethod] |
| 279 | [DataRow(typeof(TBinaryProtocol))] |
| 280 | [DataRow(typeof(TCompactProtocol))] |
| 281 | [DataRow(typeof(TJsonProtocol))] |
| 282 | public async Task WriteReadByte_Test(Type protocolType) |
| 283 | { |
| 284 | var expected = sbyte.MaxValue; |
| 285 | |
| 286 | try |
| 287 | { |
| 288 | var tuple = GetProtocolInstance(protocolType); |
| 289 | using (var stream = tuple.Item1) |
| 290 | { |
| 291 | var protocol = tuple.Item2; |
| 292 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 293 | await protocol.WriteByteAsync(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 294 | |
| 295 | stream?.Seek(0, SeekOrigin.Begin); |
| 296 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 297 | var actual = await protocol.ReadByteAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 298 | |
| 299 | var result = _compareLogic.Compare(expected, actual); |
| 300 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 301 | } |
| 302 | } |
| 303 | catch (Exception e) |
| 304 | { |
| 305 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | [DataTestMethod] |
| 310 | [DataRow(typeof(TBinaryProtocol))] |
| 311 | [DataRow(typeof(TCompactProtocol))] |
| 312 | [DataRow(typeof(TJsonProtocol))] |
| 313 | public async Task WriteReadI16_Test(Type protocolType) |
| 314 | { |
| 315 | var expected = short.MaxValue; |
| 316 | |
| 317 | try |
| 318 | { |
| 319 | var tuple = GetProtocolInstance(protocolType); |
| 320 | using (var stream = tuple.Item1) |
| 321 | { |
| 322 | var protocol = tuple.Item2; |
| 323 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 324 | await protocol.WriteI16Async(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 325 | |
| 326 | stream?.Seek(0, SeekOrigin.Begin); |
| 327 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 328 | var actual = await protocol.ReadI16Async(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 329 | |
| 330 | var result = _compareLogic.Compare(expected, actual); |
| 331 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 332 | } |
| 333 | } |
| 334 | catch (Exception e) |
| 335 | { |
| 336 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | [DataTestMethod] |
| 341 | [DataRow(typeof(TBinaryProtocol))] |
| 342 | [DataRow(typeof(TCompactProtocol))] |
| 343 | [DataRow(typeof(TJsonProtocol))] |
| 344 | public async Task WriteReadI32_Test(Type protocolType) |
| 345 | { |
| 346 | var expected = int.MaxValue; |
| 347 | |
| 348 | try |
| 349 | { |
| 350 | var tuple = GetProtocolInstance(protocolType); |
| 351 | using (var stream = tuple.Item1) |
| 352 | { |
| 353 | var protocol = tuple.Item2; |
| 354 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 355 | await protocol.WriteI32Async(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 356 | |
| 357 | stream?.Seek(0, SeekOrigin.Begin); |
| 358 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 359 | var actual = await protocol.ReadI32Async(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 360 | |
| 361 | var result = _compareLogic.Compare(expected, actual); |
| 362 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 363 | } |
| 364 | } |
| 365 | catch (Exception e) |
| 366 | { |
| 367 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | [DataTestMethod] |
| 372 | [DataRow(typeof(TBinaryProtocol))] |
| 373 | [DataRow(typeof(TCompactProtocol))] |
| 374 | [DataRow(typeof(TJsonProtocol))] |
| 375 | public async Task WriteReadI64_Test(Type protocolType) |
| 376 | { |
| 377 | var expected = long.MaxValue; |
| 378 | |
| 379 | try |
| 380 | { |
| 381 | var tuple = GetProtocolInstance(protocolType); |
| 382 | using (var stream = tuple.Item1) |
| 383 | { |
| 384 | var protocol = tuple.Item2; |
| 385 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 386 | await protocol.WriteI64Async(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 387 | |
| 388 | stream?.Seek(0, SeekOrigin.Begin); |
| 389 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 390 | var actual = await protocol.ReadI64Async(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 391 | |
| 392 | var result = _compareLogic.Compare(expected, actual); |
| 393 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 394 | } |
| 395 | } |
| 396 | catch (Exception e) |
| 397 | { |
| 398 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | [DataTestMethod] |
| 403 | [DataRow(typeof(TBinaryProtocol))] |
| 404 | [DataRow(typeof(TCompactProtocol))] |
| 405 | [DataRow(typeof(TJsonProtocol))] |
| 406 | public async Task WriteReadDouble_Test(Type protocolType) |
| 407 | { |
| 408 | var expected = double.MaxValue; |
| 409 | |
| 410 | try |
| 411 | { |
| 412 | var tuple = GetProtocolInstance(protocolType); |
| 413 | using (var stream = tuple.Item1) |
| 414 | { |
| 415 | var protocol = tuple.Item2; |
| 416 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 417 | await protocol.WriteDoubleAsync(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 418 | |
| 419 | stream?.Seek(0, SeekOrigin.Begin); |
| 420 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 421 | var actual = await protocol.ReadDoubleAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 422 | |
| 423 | var result = _compareLogic.Compare(expected, actual); |
| 424 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 425 | } |
| 426 | } |
| 427 | catch (Exception e) |
| 428 | { |
| 429 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | [DataTestMethod] |
| 434 | [DataRow(typeof(TBinaryProtocol))] |
| 435 | [DataRow(typeof(TCompactProtocol))] |
| 436 | [DataRow(typeof(TJsonProtocol))] |
| 437 | public async Task WriteReadString_Test(Type protocolType) |
| 438 | { |
| 439 | var expected = nameof(String); |
| 440 | |
| 441 | try |
| 442 | { |
| 443 | var tuple = GetProtocolInstance(protocolType); |
| 444 | using (var stream = tuple.Item1) |
| 445 | { |
| 446 | var protocol = tuple.Item2; |
| 447 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 448 | await protocol.WriteStringAsync(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 449 | |
| 450 | stream?.Seek(0, SeekOrigin.Begin); |
| 451 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 452 | var actual = await protocol.ReadStringAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 453 | |
| 454 | var result = _compareLogic.Compare(expected, actual); |
| 455 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 456 | } |
| 457 | } |
| 458 | catch (Exception e) |
| 459 | { |
| 460 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | [DataTestMethod] |
| 465 | [DataRow(typeof(TBinaryProtocol))] |
| 466 | [DataRow(typeof(TCompactProtocol))] |
| 467 | [DataRow(typeof(TJsonProtocol))] |
| 468 | public async Task WriteReadBinary_Test(Type protocolType) |
| 469 | { |
| 470 | var expected = Encoding.UTF8.GetBytes(nameof(String)); |
| 471 | |
| 472 | try |
| 473 | { |
| 474 | var tuple = GetProtocolInstance(protocolType); |
| 475 | using (var stream = tuple.Item1) |
| 476 | { |
| 477 | var protocol = tuple.Item2; |
| 478 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 479 | await protocol.WriteBinaryAsync(expected, default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 480 | |
| 481 | stream?.Seek(0, SeekOrigin.Begin); |
| 482 | |
Jens Geyer | dce2299 | 2020-05-16 23:02:27 +0200 | [diff] [blame^] | 483 | var actual = await protocol.ReadBinaryAsync(default); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 484 | |
| 485 | var result = _compareLogic.Compare(expected, actual); |
| 486 | Assert.IsTrue(result.AreEqual, result.DifferencesString); |
| 487 | } |
| 488 | } |
| 489 | catch (Exception e) |
| 490 | { |
| 491 | throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | private static Tuple<Stream, TProtocol> GetProtocolInstance(Type protocolType) |
| 496 | { |
| 497 | var memoryStream = new MemoryStream(); |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 498 | var streamClientTransport = new TStreamTransport(memoryStream, memoryStream,Configuration); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 499 | var protocol = (TProtocol) Activator.CreateInstance(protocolType, streamClientTransport); |
| 500 | return new Tuple<Stream, TProtocol>(memoryStream, protocol); |
| 501 | } |
| 502 | } |
| 503 | } |