コード例 #1
0
        public void Test_WriteJson_WorksForNull()
        {
            IRpcId id = null;

            jsonRpcIdConverter.WriteJson(writer, id, Mock.Of <JsonSerializer>());

            stringBuilder.ToString().Should().Be("null");
        }
コード例 #2
0
        public bool HasError(IRpcId id)
        {
            if (!TryGetValue(id, out var response))
            {
                throw new JsonRpcException($"Expected response id [{id}], got nothing", context);
            }

            return(response is UntypedErrorResponse);
        }
コード例 #3
0
 public T AsResponse <T>(IRpcId id)
 {
     TryGetValue(id, out var response);
     if (response is UntypedResponse untypedResponse)
     {
         return(untypedResponse.Result.ToObject <T>(serializer.Serializer));
     }
     return(default(T));
 }
コード例 #4
0
        public Error <JToken> AsAnyError(IRpcId id)
        {
            TryGetValue(id, out var response);
            if (response is UntypedErrorResponse untypedErrorResponse)
            {
                return(untypedErrorResponse.Error);
            }

            return(null);
        }
コード例 #5
0
        public Error <T> AsTypedError <T>(IRpcId id)
        {
            TryGetValue(id, out var response);
            if (response is UntypedErrorResponse untypedErrorResponse)
            {
                var error = untypedErrorResponse.Error;
                var data  = GetData <T>(error);
                return(new Error <T>()
                {
                    Code = error.Code,
                    Message = error.Message,
                    Data = data
                });
            }

            return(null);
        }
コード例 #6
0
        public T GetResponseOrThrow <T>(IRpcId id)
        {
            if (!TryGetValue(id, out var response))
            {
                throw new JsonRpcException($"Expected successful response id [{id}] with [{typeof(T).Name}] params, got nothing", context);
            }

            switch (response)
            {
            case UntypedResponse untypedResponse:
                return(untypedResponse.Result.ToObject <T>(serializer.Serializer));

            case UntypedErrorResponse untypedErrorResponse:
                context.WithError(untypedErrorResponse.Error);
                throw new JsonRpcException($"Expected successful response id [{id}] with [{typeof(T).Name}] params, got error", context);

            default:
                throw new ArgumentOutOfRangeException(nameof(response), response.GetType().Name);
            }
        }
コード例 #7
0
 public bool Equals(IRpcId other)
 {
     return(Equals(other as NullRpcId));
 }
コード例 #8
0
 private bool TryGetValue(IRpcId id, out IResponse response)
 {
     return(responses.TryGetValue(id ?? NullId, out response));
 }
コード例 #9
0
 public Error <ExceptionInfo> AsErrorWithExceptionInfo(IRpcId id)
 {
     return(AsTypedError <ExceptionInfo>(id));
 }
コード例 #10
0
 /// <inheritdoc />
 public virtual async Task <ISingleJsonRpcResult> SendRequest <T>(IRpcId id, string method, T parameters, CancellationToken cancellationToken)
 {
     return(await SendRequest(null, id, method, parameters, cancellationToken));
 }
コード例 #11
0
        /// <inheritdoc />
        public virtual async Task <ISingleJsonRpcResult> SendRequest <T>(string requestUrl, IRpcId id, string method, T parameters, CancellationToken cancellationToken)
        {
            var request = new Request <T>
            {
                Id     = id,
                Method = method,
                Params = parameters
            };

            return(await SendRequest(requestUrl, request, cancellationToken));
        }
コード例 #12
0
 public bool Equals(IRpcId other)
 {
     return(Equals(other as StringRpcId));
 }
コード例 #13
0
 public override IRpcId ReadJson(JsonReader reader, Type objectType, IRpcId existingValue, bool hasExistingValue, JsonSerializer serializer)
 {
     JToken.Load(reader);
     return(Mock.Of <IRpcId>());
 }
コード例 #14
0
 public override void WriteJson(JsonWriter writer, IRpcId value, JsonSerializer serializer)
 {
     throw new NotImplementedException();
 }