Exemplo n.º 1
0
 /// <inheritdoc />
 public bool Equals(JsonBatch <T> other)
 {
     if (Object.ReferenceEquals(other, null) ||      // When 'other' is null
         other.GetType() != this.GetType())          // or of a different type
     {
         return(false);                              // they are not equal.
     }
     return(ListComparer <T> .Default.Equals(this.Messages, other.Messages) &&
            this.IsSingleton == other.IsSingleton);
 }
Exemplo n.º 2
0
        public void MultipleRequests_ShouldSerializeTwiceToSameJson()
        {
            // Arrange
            var batch = new JsonBatch <JsonRequest>(new[] { new JsonRequest(null, "foo"), new JsonRequest(null, "bar") });

            // Act
            var json1 = JsonConvert.SerializeObject(batch, new JsonBatch <JsonRequest> .Converter());
            var json2 = JsonConvert.SerializeObject(JsonConvert.DeserializeObject <JsonBatch <JsonRequest> >(json1, new JsonBatch <JsonRequest> .Converter()), new JsonBatch <JsonRequest> .Converter());

            // Assert
            Assert.That(json2, Is.EqualTo(json1));
        }
Exemplo n.º 3
0
        public void MultipleRequests_ShouldSerializeThenDeserializeBackToEqualBatch()
        {
            // Arrange
            var batch = new JsonBatch <JsonRequest>(new[] { new JsonRequest(null, "foo"), new JsonRequest(null, "bar") });

            // Act
            var json   = JsonConvert.SerializeObject(batch, new JsonBatch <JsonRequest> .Converter());
            var result = JsonConvert.DeserializeObject <JsonBatch <JsonRequest> >(json, new JsonBatch <JsonRequest> .Converter());

            // Assert
            Assert.That(result, Is.EqualTo(batch));
        }
Exemplo n.º 4
0
        public void SingleRequest_ShouldDeserializeCorrectly()
        {
            // Arrange
            string json = @"{
                'jsonrpc': '2.0',
                'method': 'foobar'
            }";

            // Act
            var result = JsonConvert.DeserializeObject <JsonBatch <JsonRequest> >(json, new JsonBatch <JsonRequest> .Converter());

            // Assert
            var expected = new JsonBatch <JsonRequest>(new[] { new JsonRequest(null, "foobar") });

            Assert.That(result, Is.EqualTo(expected));
        }