當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。