blob: 4f14ba792dcb9a7493d25580225a79bff5675d20 [file] [log] [blame]
Jens Geyeraa0c8b32019-01-28 23:27:45 +01001// 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
18using System;
19using System.Collections.Generic;
20using System.Text;
21using System.Threading;
22using System.Threading.Tasks;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
Jens Geyeraa0c8b32019-01-28 23:27:45 +010024using Thrift.Protocol;
25using Thrift.Protocol.Entities;
26using Thrift.Transport;
27using Thrift.Transport.Client;
28
29namespace 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 Geyereacd1d42019-11-20 19:03:14 +010038 var httpClientTransport = new THttpTransport( new Uri("http://localhost"), null, null, null);
Jens Geyeraa0c8b32019-01-28 23:27:45 +010039
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 Geyereacd1d42019-11-20 19:03:14 +010047 Assert.IsTrue(result.WrappedRecursionLimit == TConfiguration.DEFAULT_RECURSION_DEPTH);
Jens Geyeraa0c8b32019-01-28 23:27:45 +010048
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 Geyer4115e952023-11-21 23:00:01 +010054 private class TJSONProtocolWrapper(TTransport trans) : TJsonProtocol(trans)
Jens Geyeraa0c8b32019-01-28 23:27:45 +010055 {
Jens Geyeraa0c8b32019-01-28 23:27:45 +010056 public object WrappedContext => Context;
57 public object WrappedReader => Reader;
58 public int WrappedRecursionDepth => RecursionDepth;
59 public int WrappedRecursionLimit => RecursionLimit;
60 }
61 }
62}