public void SetToNull_JsonContainsNullProperty()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("property", SetTo.Null());

            Assert.Equal(@"{""property"":null}", document);
        }
        public void SettingEmptyStringProperty_JsonContainsEmptyPropertyName()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("", SetTo.Value(""));

            Assert.Equal(@"{"""":""""}", document);
        }
示例#3
0
        public void WithoutThenWith_PropertyAppearsInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .Without("first")
                              .With("first", SetTo.Value("There"));

            Assert.Equal(@"{""first"":""There""}", document);
        }
示例#4
0
        public void SetToEmptyArrayFunc_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnEmptyArray)
                              .And("second", SetTo.Value("test2"));

            Assert.Equal($@"{{""first"":[],""second"":""test2""}}", document);
        }
示例#5
0
        public void AddingPropertiesUsingSetToFalse_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.False())
                              .And("second", SetTo.Value("test2"));

            Assert.Equal($@"{{""first"":false,""second"":""test2""}}", document);
        }
示例#6
0
        public void SetToCollectionWithOneEmptyObject_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(item => { }))
                              .And("second", SetTo.Value("test2"));

            Assert.Equal($@"{{""first"":[{{}}],""second"":""test2""}}", document);
        }
        public void AddingPropertiesWithValues_PropertiesAppearInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .And("second", SetTo.Value("test2"))
                              .With("third", SetTo.Value(true));

            Assert.Equal(@"{""first"":""test1"",""second"":""test2"",""third"":true}", document);
        }
示例#8
0
        public void AddingEmptyProperties_PropertiesAppearInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first")
                              .With("second")
                              .With("third");

            Assert.Equal(@"{""first"":null,""second"":null,""third"":null}", document);
        }
示例#9
0
        public void UpdateAllowsToModifyExistingSetValue()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .With("first", Updated.By(v => v + " and test2"))
                              .And("second", SetTo.Value(true));

            Assert.Equal(@"{""first"":""test1 and test2"",""second"":true}", document);
        }
示例#10
0
        public void UpdateAllowsToModifyExistingSetValueUsingStrongTyping()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .And("second", SetTo.Value(true))
                              .And("second", Updated.By <bool>(v => !v));

            Assert.Equal(@"{""first"":""test1"",""second"":false}", document);
        }
示例#11
0
        public void WithThenWithout_PropertyDoesNotAppearInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first")
                              .With("second")
                              .Without("first");

            Assert.Equal(@"{""second"":null}", document);
        }
        public void AddingPropertiesUsingSetToRandomGuid_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.RandomGuid())
                              .And("second", SetTo.Value("test2"));

            var guidRegex = @"[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}";

            Assert.True(Regex.IsMatch(document, $@"{{""first"":""{guidRegex}"",""second"":""test2""}}"));
        }
示例#13
0
        public void SetToCollectionWithTwoComplexObjects_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(
                                        item => { item.With("first", SetTo.Value("hasValue")); },
                                        item => { item.With("second", SetTo.Value("alsoHasAValue")); }))
                              .And("second", SetTo.Value("test2"));

            Assert.Equal(
                $@"{{""first"":[{{""first"":""hasValue""}},{{""second"":""alsoHasAValue""}}],""second"":""test2""}}",
                document);
        }
示例#14
0
        public void SetToCollectionThenUpdatedByRemoving_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(
                                        item => item.With("aProperty", SetTo.Value("AValue")),
                                        item => { }))
                              .And("second", SetTo.Value("test2"))
                              .With("first", Updated.ByRemovingAtIndex(0))
                              .With("first", Updated.AtIndex(0,
                                                             item => item.With("second", SetTo.Value("NewValue"))));

            Assert.Equal($@"{{""first"":[{{""second"":""NewValue""}}],""second"":""test2""}}", document);
        }
示例#15
0
        public void SetToCollectionThenInsertAtIndex0_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(
                                        item => item.With("number", SetTo.Value("one")),
                                        item => { }))
                              .And("second", SetTo.Value("test2"))
                              .With("first", Updated.WithArrayItemsInsertedAtIndex(0,
                                                                                   item => item.With("number", SetTo.Value("zero"))))
                              .With("first", Updated.AtIndex(2,
                                                             item => item.With("aNother", SetTo.Value("NewValue"))));

            Assert.Equal($@"{{""first"":[{{""number"":""zero""}},{{""number"":""one""}},{{""aNother"":""NewValue""}}],""second"":""test2""}}", document);
        }
示例#16
0
        public void AddingPropertiesUsingWithAndAnd_PropertiesAppearInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .And("second", SetTo.Value("test2"))
                              .With("third", SetTo.Null)
                              .And("fourth", SetTo.Null)
                              .With("fifth", SetTo.Null())
                              .And("sixth", SetTo.Null())
                              .With("seventh")
                              .And("eighth");

            Assert.Equal(
                @"{""first"":""test1"",""second"":""test2"",""third"":null,""fourth"":null,""fifth"":null,""sixth"":null,""seventh"":null,""eighth"":null}",
                document);
        }
        public void ImplicitCastOnAssignmentWorksCorrectly()
        {
            string document = JsonBuilder.CreateObject();

            Assert.Equal("{}", document);
        }
        public void ImplicitCastInAssertWorksCorrectly()
        {
            var document = JsonBuilder.CreateObject();

            Assert.Equal("{}", document);
        }