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


C# JArray.ToList方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.ToList方法的具体用法?C# JArray.ToList怎么用?C# JArray.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JArray的用法示例。


在下文中一共展示了JArray.ToList方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RetrievingACustomerAddressByType

        public void RetrievingACustomerAddressByType(JArray addresses)
        {
            const int CustomerId = 346760;

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1])))).Returns((int customerId, AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<int>("OwnerId") == customerId &&
                                                       addressFilter.Type.Contains(n.Value<string>("Type"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'address type for a customer' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "?Type=" + this.AddressTypes[1])).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1])))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then an address is returned".
                f(() => addresses.Count().ShouldEqual(1));
            "Then each address references the queried customer".
                f(() => addresses.ToList().ForEach(address => CustomerId.ShouldEqual(address.Value<int>("OwnerId"))));
            "Then each address references the queried type".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("Type").ShouldEqual(this.AddressTypes[1])));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:44,代码来源:RetrievingCustomerAddresses.cs

示例2: RetrievingAddressesByCity

        public void RetrievingAddressesByCity(JArray addresses)
        {
            const string City = "Denver";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.City == City))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("City").ToLowerInvariant().Contains(City.ToLowerInvariant())
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses by city' request is sent".
                  f(() =>
                  {
                      Response = Client.GetAsync(_addressesUri + "/?City=" + City).Result;
                  });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.City == City))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(3));
            "Then each address's city references the queried city".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("City").ToLowerInvariant().ShouldContain(City.ToLowerInvariant())));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:41,代码来源:RetrievingAddresses.cs

示例3: RetrievingCustomerAddressesByZipCode

        public void RetrievingCustomerAddressesByZipCode(JArray addresses)
        {
            const int CustomerId = 346760;
            const string ZipCode = "802";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))).Returns((int customerId, AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("ZipCode").Contains(addressFilter.Zip) &&
                                                       n.Value<int>("OwnerId") == CustomerId
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses for a customer by zip code' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "/?Zip=" + ZipCode)).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(2));
            "Then the address references the queried customer".
                f(() => addresses.First().Value<int>("OwnerId").ShouldEqual(CustomerId));
            "Then each address references the queried zip code".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("ZipCode").ShouldContain(ZipCode)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:45,代码来源:RetrievingCustomerAddresses.cs

示例4: RetrievingAllCustomerAddresses

        public void RetrievingAllCustomerAddresses(JArray addresses)
        {
            const int CustomerId = 346760;

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.IsAny<AddressesFilter>())).Returns((int customerId, AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where customerId == n.Value<int>("OwnerId")
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'all addresses for a customer' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId))).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.IsAny<AddressesFilter>())));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then all addresses are returned for the owner".
                f(() => addresses.Count().ShouldEqual(3));
            "Then each address references the expected owner id".
                f(() => addresses.ToList().ForEach(address => address.Value<int>("OwnerId").ShouldEqual(CustomerId)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:41,代码来源:RetrievingCustomerAddresses.cs

示例5: RetrievingAnAddressTypeForAnOwner

        public void RetrievingAnAddressTypeForAnOwner(JArray addresses)
        {
            const int OwnerIdTest = 346760;

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerIdTest) && addressFilter.Type.Contains(this.AddressTypes[2])))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.OwnerId.Contains(n.Value<int>("OwnerId")) &&
                                                       addressFilter.Type.Contains(n.Value<string>("Type"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'address for owner id and type' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerId=" + OwnerIdTest + "&Type=" + this.AddressTypes[2])).Result;
                });
            "Then the request is received by the API Controller".
                  f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerIdTest) && addressFilter.Type.Contains(this.AddressTypes[2])))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then an address is returned".
                f(() => addresses.Count().ShouldEqual(1));
            "Then the address references the queried owner id".
                f(() => addresses.ToList().ForEach(address => OwnerIdTest.ShouldEqual(address.Value<int>("OwnerId"))));
            "Then the address references the queried type".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("Type").ShouldEqual(this.AddressTypes[2])));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:44,代码来源:RetrievingAddresses.cs

示例6: RetrievingAllAddressesForOwnerTypes

        public void RetrievingAllAddressesForOwnerTypes(JArray addresses)
        {
            string[] ownerType = { "BUS", "PER" };

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerType.Contains(ownerType[0]) && addressFilter.OwnerType.Contains(ownerType[1])))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.OwnerType.Contains(n.Value<string>("OwnerType"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses for multiple owner types' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerType=" + ownerType[0] + "&OwnerType=" + ownerType[1])).Result;
                });
            "Then the request is received by the API Controller".
                  f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerType.Contains(ownerType[0]) && addressFilter.OwnerType.Contains(ownerType[1])))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then the expected addresses are returned".
                f(() => addresses.Count().ShouldEqual(9));
            "Then each address references a queried owner type".
                f(() => addresses.ToList().ForEach(address => new string[] { ownerType[0], ownerType[1] }.ShouldContain(address.Value<string>("OwnerType"))));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:41,代码来源:RetrievingAddresses.cs

示例7: RetrievingAllAddressesForOwnerName

        public void RetrievingAllAddressesForOwnerName(JArray addresses)
        {
            const string OwnerNameTest = "THE DILLION COMPANY";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerName.Contains(OwnerNameTest)))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.OwnerName.Contains(n.Value<string>("OwnerName"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'all addresses for owner name' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerName=" + OwnerNameTest)).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerName.Contains(OwnerNameTest)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then all addresses are returned for the queried owner name".
                f(() => addresses.Count().ShouldEqual(3));
            "Then each address references the expected owner name".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("OwnerName").ShouldEqual(OwnerNameTest)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:41,代码来源:RetrievingAddresses.cs

示例8: RetrievingAllAddressesForOwnerIds

        public void RetrievingAllAddressesForOwnerIds(JArray addresses)
        {
            const int OwnerId1 = 346760;
            const int OwnerId2 = 42165;

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerId1) && addressFilter.OwnerId.Contains(OwnerId2)))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.OwnerId.Contains(n.Value<int>("OwnerId"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses for multiple owner ids' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerId=" + OwnerId1 + "&OwnerId=" + OwnerId2)).Result;
                });
            "Then the request is received by the API Controller".
                  f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerId1) && addressFilter.OwnerId.Contains(OwnerId2)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then the expected addresses are returned".
                f(() => addresses.Count().ShouldEqual(4));
            "Then each address references a queried owner".
                f(() => addresses.ToList().ForEach(address => new int[] { OwnerId1, OwnerId2 }.ShouldContain(address.Value<int>("OwnerId"))));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:42,代码来源:RetrievingAddresses.cs

示例9: RetrievingAddressesByTypes

        public void RetrievingAddressesByTypes(JArray addresses)
        {
            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[0]) && addressFilter.Type.Contains(this.AddressTypes[1])))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.Type.Contains(n.Value<string>("Type"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses by multiple types' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(_addressesUri + "/?Type=" + this.AddressTypes[0] + "&Type=" + this.AddressTypes[1]).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1]) && addressFilter.Type.Contains(this.AddressTypes[1])))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(6));
            "Then each address references a queried type".
                f(() => addresses.ToList().ForEach(address => new string[] { this.AddressTypes[0], this.AddressTypes[1] }.Contains(address.Value<string>("Type"))));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:39,代码来源:RetrievingAddresses.cs

示例10: RetrievingAddressesByStreet2

        public void RetrievingAddressesByStreet2(JArray addresses)
        {
            const string Street2 = "VOGELWEIHERSTR";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Street2.Contains(Street2)))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("Street2") != null &&
                                                       n.Value<string>("Street2").Contains(addressFilter.Street2)
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses by street2' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(_addressesUri + "/?Street2=" + Street2).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Street2.Contains(Street2)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(1));
            "Then each address references the queried street2".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("Street2").ShouldContain(Street2)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:42,代码来源:RetrievingAddresses.cs

示例11: ArrayDiff

		private JObject ArrayDiff(JArray left, JArray right)
		{
			var result = JObject.Parse(@"{ ""_t"": ""a"" }");

			int commonHead = 0;
			int commonTail = 0;

			if (JToken.DeepEquals(left, right))
				return null;

			// Find common head
			while (commonHead < left.Count()
				&& commonHead < right.Count()
				&& JToken.DeepEquals(left[commonHead], right[commonHead]))
			{
				commonHead++;
			}

			// Find common tail
			while (commonTail + commonHead < left.Count()
				&& commonTail + commonHead < right.Count()
				&& JToken.DeepEquals(left[left.Count() - 1 - commonTail], right[right.Count() - 1 - commonTail]))
			{
				commonTail++;
			}

			if (commonHead + commonTail == left.Count())
			{
				// Trivial case, a block (1 or more consecutive items) was added
				for (int index = commonHead; index < right.Count() - commonTail; ++index)
				{
					result[$"{index}"] = new JArray(right[index]);
				}

				return result;
			}
			if (commonHead + commonTail == right.Count())
			{
				// Trivial case, a block (1 or more consecutive items) was removed
				for (int index = commonHead; index < left.Count() - commonTail; ++index)
				{
					result[$"_{index}"] = new JArray(left[index], 0, (int)DiffOperation.Deleted);
				}

				return result;
			}

			// Complex Diff, find the LCS (Longest Common Subsequence)
			List<JToken> trimmedLeft = left.ToList().GetRange(commonHead, left.Count() - commonTail - commonHead);
			List<JToken> trimmedRight = right.ToList().GetRange(commonHead, right.Count() - commonTail - commonHead);
			Lcs lcs = Lcs.Get(trimmedLeft, trimmedRight);

			for (int index = commonHead; index < left.Count() - commonTail; ++index)
			{
				if (lcs.Indices1.IndexOf(index - commonHead) < 0)
				{
					// Removed
					result[$"_{index}"] = new JArray(left[index], 0, (int)DiffOperation.Deleted);
				}
			}

			for (int index = commonHead; index < right.Count() - commonTail; index++)
			{
				var indexRight = lcs.Indices2.IndexOf(index - commonHead);

				if (indexRight < 0)
				{
					// Added
					result[$"{index}"] = new JArray(right[index]);
				}
				else
				{
					var li = lcs.Indices1[indexRight] + commonHead;
					var ri = lcs.Indices2[indexRight] + commonHead;

					JToken diff = Diff(left[li], right[ri]);

					if (diff != null)
					{
						result[$"{index}"] = diff;
					}
				}
			}

			return result;
		}
开发者ID:wbish,项目名称:jsondiffpatch.net,代码行数:86,代码来源:JsonDiffPatch.cs


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