• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Xunit.JsonObject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: PropertyOrderIsSetByFirstSetFieldInvocation

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

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

            Assert.Equal(
                new Dictionary<string, object>
                {
                    { "LastName", "Waltersson" },
                    { "FirstName", "Mikael" }                 
                },
                (IEnumerable<KeyValuePair<string, object>>)person);
        }
开发者ID:mikaelwaltersson,项目名称:Simple.Json,代码行数:16,代码来源:JsonObjectTests.cs


示例17: Item_NoSuchKey_ThrowsKeyNotFoundException

 public void Item_NoSuchKey_ThrowsKeyNotFoundException()
 {
     JsonObject obj = new JsonObject();
     Assert.Throws<KeyNotFoundException>(() => obj["no-such-key"]);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:5,代码来源:JsonObjectTests.cs


示例18: DeserializesStarredEventCorrectly

        public async Task DeserializesStarredEventCorrectly()
        {
            var jsonObj = new JsonObject
            {
                { "type", "WatchEvent" },
                {
                    "payload", new
                    {
                        action = "started"
                    }
                }
            };

            var client = GetTestingEventsClient(jsonObj);
            var activities = await client.GetAll();
            Assert.Equal(1, activities.Count);

            var payload = activities.FirstOrDefault().Payload as StarredEventPayload;
            Assert.Equal("started", payload.Action);
        }
开发者ID:octokit,项目名称:octokit.net,代码行数:20,代码来源:EventsClientTests.cs


示例19: GetTestingEventsClient

        private EventsClient GetTestingEventsClient(JsonObject response)
        {
            var responseString = response.ToString();
            var httpClientMock = Substitute.For<IHttpClient>();
            httpClientMock.Send(Arg.Is((IRequest r) => r.Endpoint.ToString().Contains("events")), Arg.Any<CancellationToken>()).Returns(Task.FromResult(
                new Response(HttpStatusCode.Accepted, responseString, new Dictionary<string, string>(), "application/json") as IResponse));

            return new EventsClient(new ApiConnection(new Connection(new ProductHeaderValue("mock"), httpClientMock)));
        }
开发者ID:octokit,项目名称:octokit.net,代码行数:9,代码来源:EventsClientTests.cs


示例20: DeserializesPullRequestCommentEventCorrectly

        public async Task DeserializesPullRequestCommentEventCorrectly()
        {
            var jsonObj = new JsonObject
            {
                { "type", "PullRequestReviewCommentEvent" },
                {
                    "payload", new
                    {
                        action = "assigned",
                        pull_request = new
                        {
                            title = "PR Title"
                        },
                        comment = new
                        {
                            id = 1337
                        }
                    }
                }
            };

            var client = GetTestingEventsClient(jsonObj);
            var activities = await client.GetAll();
            Assert.Equal(1, activities.Count);

            var payload = activities.FirstOrDefault().Payload as PullRequestCommentPayload;
            Assert.Equal("assigned", payload.Action);
            Assert.Equal("PR Title", payload.PullRequest.Title);
            Assert.Equal(1337, payload.Comment.Id);
        }
开发者ID:octokit,项目名称:octokit.net,代码行数:30,代码来源:EventsClientTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Sdk.ExceptionAggregator类代码示例发布时间:2022-05-26
下一篇:
C# Xunit.JsonDeserializer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap