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.Collections.Generic; |
| 20 | using System.Text; |
| 21 | using System.Threading; |
| 22 | using System.Threading.Tasks; |
| 23 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 24 | using Thrift.Protocol; |
| 25 | using Thrift.Protocol.Entities; |
| 26 | using Thrift.Transport; |
| 27 | using Thrift.Transport.Client; |
| 28 | |
| 29 | namespace Thrift.Tests.Protocols |
| 30 | { |
| 31 | // ReSharper disable once InconsistentNaming |
| 32 | [TestClass] |
| 33 | public class TJSONProtocolTests |
| 34 | { |
| 35 | [TestMethod] |
| 36 | public void TJSONProtocol_Can_Create_Instance_Test() |
| 37 | { |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 38 | var httpClientTransport = new THttpTransport( new Uri("http://localhost"), null, null, null); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 39 | |
| 40 | var result = new TJSONProtocolWrapper(httpClientTransport); |
| 41 | |
| 42 | Assert.IsNotNull(result); |
| 43 | Assert.IsNotNull(result.WrappedContext); |
| 44 | Assert.IsNotNull(result.WrappedReader); |
| 45 | Assert.IsNotNull(result.Transport); |
| 46 | Assert.IsTrue(result.WrappedRecursionDepth == 0); |
Jens Geyer | eacd1d4 | 2019-11-20 19:03:14 +0100 | [diff] [blame] | 47 | Assert.IsTrue(result.WrappedRecursionLimit == TConfiguration.DEFAULT_RECURSION_DEPTH); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 48 | |
| 49 | Assert.IsTrue(result.Transport.Equals(httpClientTransport)); |
| 50 | Assert.IsTrue(result.WrappedContext.GetType().Name.Equals("JSONBaseContext", StringComparison.OrdinalIgnoreCase)); |
| 51 | Assert.IsTrue(result.WrappedReader.GetType().Name.Equals("LookaheadReader", StringComparison.OrdinalIgnoreCase)); |
| 52 | } |
| 53 | |
Jens Geyer | 4115e95 | 2023-11-21 23:00:01 +0100 | [diff] [blame] | 54 | private class TJSONProtocolWrapper(TTransport trans) : TJsonProtocol(trans) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 55 | { |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 56 | public object WrappedContext => Context; |
| 57 | public object WrappedReader => Reader; |
| 58 | public int WrappedRecursionDepth => RecursionDepth; |
| 59 | public int WrappedRecursionLimit => RecursionLimit; |
| 60 | } |
| 61 | } |
| 62 | } |