Пример #1
0
 /// <inheritdoc />
 public bool Equals(JsonErrorObject other)
 {
     if (Object.ReferenceEquals(other, null))
     {
         return(false);
     }
     return(this.Code == other.Code &&
            this.Message == other.Message &&
            JToken.DeepEquals(this.Data, other.Data));
 }
        public void SimpleError_ShouldSerializeTwiceToSameJson()
        {
            // Arrange
            var error = new JsonErrorObject(-32600, "Invalid Request", null);

            // Act
            var json1 = JsonConvert.SerializeObject(error);
            var json2 = JsonConvert.SerializeObject(JsonConvert.DeserializeObject <JsonErrorObject>(json1));

            // Assert
            Assert.That(json2, Is.EqualTo(json1));
        }
Пример #3
0
        internal JsonError([CanBeNull] string id, JsonErrorObject error, string jsonrpc)
            : base(id, jsonrpc)
        {
            #region Contract
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }
            #endregion

            this.Error = error;
        }
        public void SimpleError_ShouldSerializeThenDeserializeBackToEqualObject()
        {
            // Arrange
            var error = new JsonErrorObject(-32600, "Invalid Request", null);

            // Act
            var json   = JsonConvert.SerializeObject(error);
            var result = JsonConvert.DeserializeObject <JsonErrorObject>(json);

            // Assert
            Assert.That(result, Is.EqualTo(error));
        }
        public void SimpleError_ShouldDeserializeCorrectly()
        {
            // Arrange
            string json = @"{
                code: -32600,
                message: 'Invalid Request'
            }";

            // Act
            var result = JsonConvert.DeserializeObject <JsonErrorObject>(json);

            // Assert
            var expected = new JsonErrorObject(-32600, "Invalid Request", null);

            Assert.That(result, Is.EqualTo(expected));
        }
        public void ErrorWithComplexData_ShouldSerializeTwiceToSameJson()
        {
            // Arrange
            var error = new JsonErrorObject(3, "Execution Error", new JArray
            {
                new JObject
                {
                    { "code", 102 },
                    { "message", "Insufficient gas" },
                },
                new JObject
                {
                    { "code", 103 },
                    { "message", "Gas limit exceeded" },
                },
            });

            // Act
            var json1 = JsonConvert.SerializeObject(error);
            var json2 = JsonConvert.SerializeObject(JsonConvert.DeserializeObject <JsonErrorObject>(json1));

            // Assert
            Assert.That(json2, Is.EqualTo(json1));
        }
        public void ErrorWithComplexData_ShouldSerializeThenDeserializeBackToEqualObject()
        {
            // Arrange
            var error = new JsonErrorObject(3, "Execution Error", new JArray
            {
                new JObject
                {
                    { "code", 102 },
                    { "message", "Insufficient gas" },
                },
                new JObject
                {
                    { "code", 103 },
                    { "message", "Gas limit exceeded" },
                },
            });

            // Act
            var json   = JsonConvert.SerializeObject(error);
            var result = JsonConvert.DeserializeObject <JsonErrorObject>(json);

            // Assert
            Assert.That(result, Is.EqualTo(error));
        }
        public void ErrorWithComplexData_ShouldDeserializeCorrectly()
        {
            // Arrange
            string json = @"{
                code: 3,
                message: 'Execution Error',
                data: [{
                    code: 102,
                    message: 'Insufficient gas'
                },
                {
                    code: 103,
                    message: 'Gas limit exceeded'
                }]
            }";

            // Act
            var result = JsonConvert.DeserializeObject <JsonErrorObject>(json);

            // Assert
            var expected = new JsonErrorObject(3, "Execution Error", new JArray
            {
                new JObject
                {
                    { "code", 102 },
                    { "message", "Insufficient gas" },
                },
                new JObject
                {
                    { "code", 103 },
                    { "message", "Gas limit exceeded" },
                },
            });

            Assert.That(result, Is.EqualTo(expected));
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonError"/> class.
 /// </summary>
 /// <param name="id">The message identifier string; or <see langword="null"/>.</param>
 /// <param name="error">The error object.</param>
 internal JsonError([CanBeNull] string id, JsonErrorObject error)
     : this(id, error, DefaultProtocolVersion)
 {
     // Nothing to do.
 }