Ejemplo n.º 1
0
        public void IsNullOrEmptyReturnsTrueWhenInstanceWritesTimeSpanPropertyWithNullValue()
        {
            var writer       = new TestableJsonWriter(null);
            var serializable = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", (TimeSpan?)null)
            };

            Assert.True(writer.IsNullOrEmpty(serializable));
        }
 public void WriteStringEscapesHorizontalTab()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WriteProperty("name", "Test\tValue");
         Assert.Contains("Test\\tValue", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
Ejemplo n.º 3
0
        public void IsNullOrEmptyReturnsFalseWhenInstanceWritesDateTimeOffsetProperty()
        {
            var writer       = new TestableJsonWriter(null);
            var serializable = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", DateTimeOffset.UtcNow)
            };

            Assert.False(writer.IsNullOrEmpty(serializable));
        }
 public void WriteStringEscapesFormFeed()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WriteString("Test\fValue");
         Assert.Contains("Test\\fValue", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
Ejemplo n.º 5
0
        public void IsNullOrEmptyReturnsFalseWhenInstanceWritesStringProperty()
        {
            var writer       = new TestableJsonWriter(null);
            var serializable = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", "value")
            };

            Assert.False(writer.IsNullOrEmpty(serializable));
        }
Ejemplo n.º 6
0
        public void IsNullOrEmptyReturnsTrueWhenInstanceWritesStringPropertyWithEmptyValue()
        {
            var writer       = new TestableJsonWriter(null);
            var serializable = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", string.Empty)
            };

            Assert.True(writer.IsNullOrEmpty(serializable));
        }
Ejemplo n.º 7
0
        public void IsNullOrEmptyReturnsTrueWhenInstanceWritesRawObjectValueWithNullValue()
        {
            var writer       = new TestableJsonWriter(null);
            var serializable = new StubIJsonSerializable {
                OnSerialize = w => w.WriteRawValue(null)
            };

            Assert.True(writer.IsNullOrEmpty(serializable));
        }
Ejemplo n.º 8
0
        public void IsNullOrEmptyReturnsTrueWhenInstanceWritesIJsonSerializablePropertyWithNullValue()
        {
            var writer = new TestableJsonWriter(null);
            var parent = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("child", (IJsonSerializable)null)
            };

            Assert.True(writer.IsNullOrEmpty(parent));
        }
Ejemplo n.º 9
0
        public void IsNullOrEmptyReturnsTrueWhenInstanceWritesIDictionaryStringStringWithNullValue()
        {
            var writer   = new TestableJsonWriter(null);
            var instance = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", (IDictionary <string, string>)null)
            };

            Assert.True(writer.IsNullOrEmpty(instance));
        }
Ejemplo n.º 10
0
        public void IsNullOrEmptyReturnsFalseWhenInstanceWritesTimeSpanProperty()
        {
            var writer       = new TestableJsonWriter(null);
            var serializable = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", TimeSpan.FromSeconds(0.0))
            };

            Assert.False(writer.IsNullOrEmpty(serializable));
        }
 public void WritePropertyNamePrependsPropertyNameWithComaWhenCurrentObjectAlreadyHasProperties()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WritePropertyName("Property1");
         jsonWriter.WritePropertyName("Property2");
         Assert.Contains(",\"Property2\"", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
Ejemplo n.º 12
0
        public void IsNullOrEmptyReturnsFalseWhenInstanceWritesIDictionaryStringStringProperty()
        {
            var writer   = new TestableJsonWriter(null);
            var instance = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", new Dictionary <string, string> {
                    { "name", "value" }
                })
            };

            Assert.False(writer.IsNullOrEmpty(instance));
        }
 public void WritePropertyNameDoesNotPrependPropertyNameWithComaWhenNewObjectWasStarted()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WritePropertyName("Property1");
         jsonWriter.WriteStartObject();
         jsonWriter.WritePropertyName("Property2");
         Assert.Contains("{\"Property2\"", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
Ejemplo n.º 14
0
        public void IsNullOrEmptyReturnsFalseWhenInstanceWritesIJsonSerializableProperty()
        {
            var writer = new TestableJsonWriter(null);
            var child  = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("name", "value")
            };
            var parent = new StubIJsonSerializable {
                OnSerialize = w => w.WriteProperty("child", child)
            };

            Assert.False(writer.IsNullOrEmpty(parent));
        }
Ejemplo n.º 15
0
        public void IsNullOrEmptyReturnsTrueWhenGivenIJsonSerializableInstanceIsNull()
        {
            var writer = new TestableJsonWriter(null);

            Assert.True(writer.IsNullOrEmpty(null));
        }
 public void IsNullOrEmptyReturnsFalseWhenInstanceWritesIDictionaryStringStringProperty()
 {
     var writer = new TestableJsonWriter(null);
     var instance = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", new Dictionary<string, string> { { "name", "value" } }) };
     Assert.False(writer.IsNullOrEmpty(instance));
 }
 public void WriteStringEscapesFormFeed()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WriteString("Test\fValue");
         Assert.Contains("Test\\fValue", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }            
 }
 public void WriteStringEscapesHorizontalTab()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WriteProperty("name", "Test\tValue");
         Assert.Contains("Test\\tValue", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
 public void WritePropertyNamePrependsPropertyNameWithComaWhenCurrentObjectAlreadyHasProperties()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WritePropertyName("Property1");
         jsonWriter.WritePropertyName("Property2");
         Assert.Contains(",\"Property2\"", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
 public void WritePropertyNameDoesNotPrependPropertyNameWithComaWhenNewObjectWasStarted()
 {
     using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         var jsonWriter = new TestableJsonWriter(stringWriter);
         jsonWriter.WritePropertyName("Property1");
         jsonWriter.WriteStartObject();
         jsonWriter.WritePropertyName("Property2");
         Assert.Contains("{\"Property2\"", stringWriter.ToString(), StringComparison.OrdinalIgnoreCase);
     }
 }
 public void IsNullOrEmptyReturnsTrueWhenInstanceWritesBoolPropertyWithNullValue()
 {
     var writer = new TestableJsonWriter(null);
     var serializable = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", (bool?)null) };
     Assert.True(writer.IsNullOrEmpty(serializable));
 }
 public void IsNullOrEmptyReturnsFalseWhenInstanceWritesDateTimeOffsetProperty()
 {
     var writer = new TestableJsonWriter(null);
     var serializable = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", DateTimeOffset.UtcNow) };
     Assert.False(writer.IsNullOrEmpty(serializable));
 }
 public void IsNullOrEmptyReturnsTrueWhenGivenIJsonSerializableInstanceDoesNotWriteAnyProperties()
 {
     var writer = new TestableJsonWriter(null);
     Assert.True(writer.IsNullOrEmpty(new StubIJsonSerializable()));
 }
 public void IsNullOrEmptyReturnsFalseWhenInstanceWritesStringProperty()
 {
     var writer = new TestableJsonWriter(null);
     var serializable = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", "value") };
     Assert.False(writer.IsNullOrEmpty(serializable));
 }
 public void IsNullOrEmptyReturnsTrueWhenGivenIJsonSerializableInstanceIsNull()
 {
     var writer = new TestableJsonWriter(null);
     Assert.True(writer.IsNullOrEmpty(null));
 }
Ejemplo n.º 26
0
        public void IsNullOrEmptyReturnsTrueWhenGivenIJsonSerializableInstanceDoesNotWriteAnyProperties()
        {
            var writer = new TestableJsonWriter(null);

            Assert.True(writer.IsNullOrEmpty(new StubIJsonSerializable()));
        }
 public void IsNullOrEmptyReturnsFalseWhenInstanceWritesTimeSpanProperty()
 {
     var writer = new TestableJsonWriter(null);
     var serializable = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", TimeSpan.FromSeconds(0.0)) };
     Assert.False(writer.IsNullOrEmpty(serializable));
 }
 public void IsNullOrEmptyReturnsFalseWhenInstanceWritesIJsonSerializableProperty()
 {
     var writer = new TestableJsonWriter(null);
     var child = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", "value") };
     var parent = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("child", child) };
     Assert.False(writer.IsNullOrEmpty(parent));
 }
 public void IsNullOrEmptyReturnsTrueWhenInstanceWritesIJsonSerializablePropertyWithEmptyValue()
 {
     var writer = new TestableJsonWriter(null);
     var child = new StubIJsonSerializable();
     var parent = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", child) };
     Assert.True(writer.IsNullOrEmpty(parent));
 }
 public void IsNullOrEmptyReturnsTrueWhenInstanceWritesIDictionaryStringStringWithNullValue()
 {
     var writer = new TestableJsonWriter(null);
     var instance = new StubIJsonSerializable { OnSerialize = w => w.WriteProperty("name", (IDictionary<string, string>)null) };
     Assert.True(writer.IsNullOrEmpty(instance));
 }
 public void IsNullOrEmptyReturnsTrueWhenInstanceWritesRawObjectValueWithNullValue()
 {
     var writer = new TestableJsonWriter(null);
     var serializable = new StubIJsonSerializable { OnSerialize = w => w.WriteRawValue(null) };
     Assert.True(writer.IsNullOrEmpty(serializable));
 }