当前位置: 首页>>代码示例>>C#>>正文


C# Xunit.JsonObject类代码示例

本文整理汇总了C#中Xunit.JsonObject的典型用法代码示例。如果您正苦于以下问题:C# JsonObject类的具体用法?C# JsonObject怎么用?C# JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonObject类属于Xunit命名空间,在下文中一共展示了JsonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetFieldsAddsKeyValuePairs

        public void SetFieldsAddsKeyValuePairs()
        {
            dynamic person = new JsonObject();

            person.FirstName = "Mikael";
            person.LastName = "Waltersson";
            person.Age = 30;
            
            
            Assert.Equal(new[] { "FirstName", "LastName", "Age" }, person.GetDynamicMemberNames());
            Assert.Equal(
                new Dictionary<string, object>
                {
                    { "FirstName", "Mikael" },
                    { "LastName", "Waltersson" },
                    { "Age", 30 }
                },
                (IEnumerable<KeyValuePair<string, object>>)person);

            

            Assert.Equal("Mikael", person.FirstName);
            Assert.Equal("Waltersson", person.LastName);
            Assert.Equal(30, person.Age);            
        }
开发者ID:mikaelwaltersson,项目名称:Simple.Json,代码行数:25,代码来源:JsonObjectTests.cs

示例2: NonExistingFieldsHasUndefinedValue

        public void NonExistingFieldsHasUndefinedValue()
        {
            dynamic person = new JsonObject();

            person.FirstName = "Mikael";

            Assert.Equal(Undefined.Value, person.LastName);
        }
开发者ID:mikaelwaltersson,项目名称:Simple.Json,代码行数:8,代码来源:JsonObjectTests.cs

示例3: JsonObject_ToString_OrderingMaintained

 public void JsonObject_ToString_OrderingMaintained()
 {
     var obj = new JsonObject();
     obj["a"] = 1;
     obj["c"] = 3;
     obj["b"] = 2;
     Assert.Equal("{\"a\": 1, \"b\": 2, \"c\": 3}", obj.ToString());
 }
开发者ID:shmao,项目名称:corefx,代码行数:8,代码来源:JsonValueTests.cs

示例4: convert_large_number_to_json

        public void convert_large_number_to_json()
        {
            var obj = new JsonObject();
            obj["value"] = new JsonValue(long.MaxValue);

            var json = obj.ToString();

            obj = JsonObject.Parse(json);
            ((JsonValue)obj["value"]).Value.ShouldEqual(long.MaxValue);
        }
开发者ID:slavashar,项目名称:SimpleJson,代码行数:10,代码来源:JsonValueFacts.cs

示例5: SettingUndefinedAsFieldValueRemovesField

        public void SettingUndefinedAsFieldValueRemovesField()
        {
            dynamic person = new JsonObject();

            person.FirstName = "Mikael";
            person.LastName = "Waltersson";

            person.FirstName = Undefined.Value;

            Assert.Equal(new[] { "LastName" }, person.GetPropertyNames());
        }
开发者ID:mikaelwaltersson,项目名称:Simple.Json,代码行数:11,代码来源:JsonObjectTests.cs

示例6: dynamic_case

        public void dynamic_case()
        {
            dynamic jobject = new JsonObject();
            jobject.name = "test";
            jobject.value = 1;
            jobject.list = new object[] { 5, "test" };

            string json = jobject.ToString();

            json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}");
        }
开发者ID:slavashar,项目名称:SimpleJson,代码行数:11,代码来源:JsonUsabilityFacts.cs

示例7: general_case

        public void general_case()
        {
            var jobject = new JsonObject();
            jobject["name"] = new JsonValue("test");
            jobject["value"] = new JsonValue(1);
            jobject["list"] = new JsonArray { new JsonValue(5), new JsonValue("test") };

            var json = jobject.ToString();

            json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}");
        }
开发者ID:slavashar,项目名称:SimpleJson,代码行数:11,代码来源:JsonUsabilityFacts.cs

示例8: anonymous_case

        public void anonymous_case()
        {
            var obj = new
                {
                    name = "test",
                    value = 1,
                    list = new object[] { 5, "test" }
                };

            var json = new JsonObject(obj).ToString();

            json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}");
        }
开发者ID:slavashar,项目名称:SimpleJson,代码行数:13,代码来源:JsonUsabilityFacts.cs

示例9: opIndexer_int

        public void opIndexer_int()
        {
            var expected = new JsonObject();

            var document = new JsonDocument
                               {
                                   expected
                               };

            var actual = document[0];

            Assert.Equal(expected, actual);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:13,代码来源:JsonDocument.Facts.cs

示例10: opIndexer_int

        public void opIndexer_int()
        {
            var expected = new JsonPair("name", "value");

            var document = new JsonObject
                               {
                                   expected
                               };

            var actual = document[0];

            Assert.Equal(expected, actual);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:13,代码来源:JsonObject.Facts.cs

示例11: op_Add_JsonObject

        public void op_Add_JsonObject()
        {
            var expected = new JsonObject();

            var document = new JsonDocument
                               {
                                   expected
                               };

            var actual = document.First();

            Assert.Equal(expected, actual);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:13,代码来源:JsonDocument.Facts.cs

示例12: op_GetEnumerator

        public void op_GetEnumerator()
        {
            var expected = new JsonObject();

            IEnumerable document = new JsonDocument
                                       {
                                           expected
                                       };

            foreach (var actual in document)
            {
                Assert.Equal(expected, actual);
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:14,代码来源:JsonDocument.Facts.cs

示例13: opIndexer_string

        public void opIndexer_string()
        {
            const string name = "name";
            var expected = new JsonPair(name, "value");

            var document = new JsonObject
                               {
                                   expected
                               };

            var actual = document[name];

            Assert.Equal(expected, actual);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:14,代码来源:JsonObject.Facts.cs

示例14: ShouldCastToDynamicAsRawJson

        public void ShouldCastToDynamicAsRawJson()
        {
            var jsonObject = new JsonObject("{\"_id\":\"8A7FD19B\",\"_rev\":\"1-42\",\"type\":\"simpleEntity\",\"name\":\"John\"}");
            dynamic dynamicObject = jsonObject;

            Assert.Null((string)dynamicObject.Id);
            Assert.Null((string)dynamicObject.Revision);
            Assert.Null((string)dynamicObject.Type);

            Assert.Equal("8A7FD19B",     (string)dynamicObject._id);
            Assert.Equal("1-42",         (string)dynamicObject._rev);
            Assert.Equal("simpleEntity", (string)dynamicObject.type);
            Assert.Equal("John",         (string)dynamicObject.name);
        }
开发者ID:artikh,项目名称:CouchDude,代码行数:14,代码来源:JsonObjectTests.cs

示例15: Ctor_IEnumerable

        public void Ctor_IEnumerable()
        {
            // Workaround xunit/xunit#987: InvalidOperationException thrown if this is in MemberData
            KeyValuePair<string, JsonValue>[] items = new KeyValuePair<string, JsonValue>[] { new KeyValuePair<string, JsonValue>("key", new JsonPrimitive(true)) };
            JsonObject obj = new JsonObject((IEnumerable<KeyValuePair<string, JsonValue>>)items);

            Assert.Equal(items.Length, obj.Count);
            for (int i = 0; i < items.Length; i++)
            {
                Assert.Equal(items[i].Value.ToString(), obj[items[i].Key].ToString());

                JsonValue value;
                Assert.True(obj.TryGetValue(items[i].Key, out value));
                Assert.Equal(items[i].Value.ToString(), value.ToString());
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:16,代码来源:JsonObjectTests.cs


注:本文中的Xunit.JsonObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。