public void Test_WriteJson_WorksForNull()
        {
            IRpcId id = null;

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

            stringBuilder.ToString().Should().Be("null");
        }
        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);
        }
 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));
 }
        public Error <JToken> AsAnyError(IRpcId id)
        {
            TryGetValue(id, out var response);
            if (response is UntypedErrorResponse untypedErrorResponse)
            {
                return(untypedErrorResponse.Error);
            }

            return(null);
        }
        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);
        }
        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);
            }
        }
 public bool Equals(IRpcId other)
 {
     return(Equals(other as NullRpcId));
 }
 private bool TryGetValue(IRpcId id, out IResponse response)
 {
     return(responses.TryGetValue(id ?? NullId, out response));
 }
 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();
 }