Ejemplo n.º 1
0
        public void should_add_value_array_elements_with_explicit_values()
        {
            var element = new JElement(ElementType.Array);
            element.AddArrayValueElement(true);
            element.AddArrayValueElement(5);
            element.AddArrayValueElement("hai");
            element.AddArrayValueElement(null);

            element.Count().ShouldEqual(4);
            var elements = element.ToList();
            elements[0].ShouldBeAJsonBoolValueArrayElement(true);
            elements[1].ShouldBeAJsonNumberValueArrayElement(5);
            elements[2].ShouldBeAJsonStringValueArrayElement("hai");
            elements[3].ShouldBeAJsonNullValueArrayElement();
        }
Ejemplo n.º 2
0
        public void should_add_fields_with_default_values()
        {
            var element = new JElement(ElementType.Object);
            element.AddMember("field1", ElementType.Boolean);
            element.AddMember("field2", ElementType.Number);
            element.AddMember("field3", ElementType.String);
            element.AddMember("field4", ElementType.Null);
            element.AddMember("field5", ElementType.Object);
            element.AddMember("field6", ElementType.Array);

            element.Count().ShouldEqual(6);
            var fields = element.ToList();
            fields[0].ShouldBeAJsonBoolValueField("field1", false);
            fields[1].ShouldBeAJsonNumberValueField("field2", 0);
            fields[2].ShouldBeAJsonStringValueField("field3", "");
            fields[3].ShouldBeAJsonNullValueField("field4");
            fields[4].ShouldBeAJsonObjectField("field5");
            fields[5].ShouldBeAJsonArrayField("field6");
        }
Ejemplo n.º 3
0
        public void should_add_array_elements_with_default_values()
        {
            var element = new JElement(ElementType.Array);
            element.AddArrayElement(ElementType.Boolean);
            element.AddArrayElement(ElementType.Number);
            element.AddArrayElement(ElementType.String);
            element.AddArrayElement(ElementType.Null);
            element.AddArrayElement(ElementType.Object);
            element.AddArrayElement(ElementType.Array);

            element.Count().ShouldEqual(6);
            var elements = element.ToList();
            elements[0].ShouldBeAJsonBoolValueArrayElement(false);
            elements[1].ShouldBeAJsonNumberValueArrayElement(0);
            elements[2].ShouldBeAJsonStringValueArrayElement("");
            elements[3].ShouldBeAJsonNullValueArrayElement();
            elements[4].ShouldBeAJsonObjectArrayElement();
            elements[5].ShouldBeAJsonArrayArrayElement();
        }
Ejemplo n.º 4
0
        public void should_add_value_fields_with_explicit_values()
        {
            var element = new JElement(ElementType.Object);
            element.AddValueMember("field1", true);
            element.AddValueMember("field2", 5);
            element.AddValueMember("field3", "hai");
            element.AddValueMember("field4", null);

            element.Count().ShouldEqual(4);
            var fields = element.ToList();
            fields[0].ShouldBeAJsonBoolValueField("field1", true);
            fields[1].ShouldBeAJsonNumberValueField("field2", 5);
            fields[2].ShouldBeAJsonStringValueField("field3", "hai");
            fields[3].ShouldBeAJsonNullValueField("field4");
        }
Ejemplo n.º 5
0
        public void should_insert_value_fields_with_explicit_values()
        {
            var element = new JElement(ElementType.Object);

            var boolElement = new JElement("field1", true, ValueElementType.Boolean);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(boolElement);

            var numberElement = new JElement("field2", 5, ValueElementType.Number);
            element.CanInsert(numberElement).ShouldBeTrue();
            element.Insert(numberElement);

            var stringElement = new JElement("field3", "hai", ValueElementType.String);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(stringElement);

            element.Count().ShouldEqual(3);
            var fields = element.ToList();

            fields[0].ShouldBeAJsonBoolValueField("field1", true);
            fields[0].Parent.ShouldBeSameAs(element);

            fields[1].ShouldBeAJsonNumberValueField("field2", 5);
            fields[1].Parent.ShouldBeSameAs(element);

            fields[2].ShouldBeAJsonStringValueField("field3", "hai");
            fields[2].Parent.ShouldBeSameAs(element);
        }
Ejemplo n.º 6
0
        public void should_insert_value_array_elements_with_explicit_values()
        {
            var element = new JElement(ElementType.Array);

            var boolElement = new JElement(true, ValueElementType.Boolean);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(boolElement);

            var numberElement = new JElement(5, ValueElementType.Number);
            element.CanInsert(numberElement).ShouldBeTrue();
            element.Insert(numberElement);

            var stringElement = new JElement("hai", ValueElementType.String);
            element.CanInsert(stringElement).ShouldBeTrue();
            element.Insert(stringElement);

            element.Count().ShouldEqual(3);
            var elements = element.ToList();

            elements[0].ShouldBeAJsonBoolValueArrayElement(true);
            elements[0].Parent.ShouldBeSameAs(element);

            elements[1].ShouldBeAJsonNumberValueArrayElement(5);
            elements[1].Parent.ShouldBeSameAs(element);

            elements[2].ShouldBeAJsonStringValueArrayElement("hai");
            elements[2].Parent.ShouldBeSameAs(element);
        }
Ejemplo n.º 7
0
        public void should_insert_fields_with_default_values()
        {
            var element = new JElement(ElementType.Object);

            var boolElement = new JElement("field1", ElementType.Boolean);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(boolElement);

            var numberElement = new JElement("field2", ElementType.Number);
            element.CanInsert(numberElement).ShouldBeTrue();
            element.Insert(numberElement);

            var stringElement = new JElement("field3", ElementType.String);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(stringElement);

            var nullElement = new JElement("field4", ElementType.Null);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(nullElement);

            var objectElement = new JElement("field5", ElementType.Object);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(objectElement);

            var arrayElement = new JElement("field6", ElementType.Array);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(arrayElement);

            element.Count().ShouldEqual(6);
            var fields = element.ToList();

            fields[0].ShouldBeAJsonBoolValueField("field1");
            fields[0].Parent.ShouldBeSameAs(element);

            fields[1].ShouldBeAJsonNumberValueField("field2");
            fields[1].Parent.ShouldBeSameAs(element);

            fields[2].ShouldBeAJsonStringValueField("field3");
            fields[2].Parent.ShouldBeSameAs(element);

            fields[3].ShouldBeAJsonNullValueField("field4");
            fields[3].Parent.ShouldBeSameAs(element);

            fields[4].ShouldBeAJsonObjectField("field5");
            fields[4].Parent.ShouldBeSameAs(element);

            fields[5].ShouldBeAJsonArrayField("field6");
            fields[5].Parent.ShouldBeSameAs(element);
        }
Ejemplo n.º 8
0
        public void should_insert_array_elements_with_default_values()
        {
            var element = new JElement(ElementType.Array);

            var boolElement = new JElement(ElementType.Boolean);
            element.CanInsert(boolElement).ShouldBeTrue();
            element.Insert(boolElement);

            var numberElement = new JElement(ElementType.Number);
            element.CanInsert(numberElement).ShouldBeTrue();
            element.Insert(numberElement);

            var stringElement = new JElement(ElementType.String);
            element.CanInsert(stringElement).ShouldBeTrue();
            element.Insert(stringElement);

            var nullElement = new JElement(ElementType.Null);
            element.CanInsert(nullElement).ShouldBeTrue();
            element.Insert(nullElement);

            var objectElement = new JElement(ElementType.Object);
            element.CanInsert(objectElement).ShouldBeTrue();
            element.Insert(objectElement);

            var arrayElement = new JElement(ElementType.Array);
            element.CanInsert(arrayElement).ShouldBeTrue();
            element.Insert(arrayElement);

            element.Count().ShouldEqual(6);
            var elements = element.ToList();

            elements[0].ShouldBeAJsonBoolValueArrayElement();
            elements[0].Parent.ShouldBeSameAs(element);

            elements[1].ShouldBeAJsonNumberValueArrayElement();
            elements[1].Parent.ShouldBeSameAs(element);

            elements[2].ShouldBeAJsonStringValueArrayElement();
            elements[2].Parent.ShouldBeSameAs(element);

            elements[3].ShouldBeAJsonNullValueArrayElement();
            elements[3].Parent.ShouldBeSameAs(element);

            elements[4].ShouldBeAJsonObjectArrayElement();
            elements[4].Parent.ShouldBeSameAs(element);

            elements[5].ShouldBeAJsonArrayArrayElement();
            elements[5].Parent.ShouldBeSameAs(element);
        }