示例#1
0
        public void ODataGrammar_Test()
        {
            var queryable = _pocoClient.Context <Car>().Take(20).ToList();

            Assert.AreEqual(
                "http://non-existent-server/api/Cars?$top=20",
                _requestUri.ToString());
        }
		public void GetCars()
		{
			var pocoClient = new PocoClient()
				{BaseAddress = new Uri("http://localhost:56572/api/")};
			var list = pocoClient.Context<Car>()
				.Where(x=>x.Make == "Fiat").OrderBy(x=>x.Price).ToList();
			Console.WriteLine(list[1].Model);
		}
示例#3
0
        public void GetCars()
        {
            var pocoClient = new PocoClient()
            {
                BaseAddress = new Uri("http://localhost:56572/api/")
            };
            var list = pocoClient.Context <Car>()
                       .Where(x => x.Make == "Fiat").OrderBy(x => x.Price).ToList();

            Console.WriteLine(list[1].Model);
        }
示例#4
0
        static void Main(string[] args)
        {
            var pocoClient = new PocoClient()
            {
                BaseAddress = new Uri("http://localhost:12889/api/")
            };
            var list = pocoClient.Context <Car>()
                       .Where(x => x.Make == "BMW").Take(1).ToList();

            Console.WriteLine(list[0]);

            Console.Read();
        }
示例#5
0
		private static List<Customer> Test_OData_V1_And_V2(int skip, int count)
		{
			var pocoClient = new PocoClient(new PocoConfiguration()
			{
				RequestSetup = (request) => request.Headers.Add("Accept", "application/json"),
				ResponseReader = (response, formatters, type) =>
				{
					var versionHeader = response.Headers.FirstOrDefault(x=>x.Key == "DataServiceVersion");
					object result = null;
					if(versionHeader.Value.Any(x=> x!=null && x.Contains("1.0")))
					{
						result = ReadFromV1(response, formatters, type);
					}
					else if(versionHeader.Value.Any(x=> x!=null && x.Contains("2.0")))
					{
						result = ReadFromV2(response, formatters, type);						
					}
					else
					{
						throw new NotSupportedException("DataServiceVersion not supported.");
					}

					var taskCompletionSource = new TaskCompletionSource<object>();
					try
					{
						taskCompletionSource.SetResult(result);
					}
					catch (Exception e)
					{
						taskCompletionSource.SetException(e);
					}
					return taskCompletionSource.Task;
				}
			})
			{
				BaseAddress = new Uri("http://services.odata.org/Northwind/Northwind.svc/")
			};

			return pocoClient.Context<Customer>()
				.Skip(skip).Take(count).ToList();
		}
示例#6
0
        private static List <Customer> Test_OData_V1_And_V2(int skip, int count)
        {
            var pocoClient = new PocoClient(new PocoConfiguration()
            {
                RequestSetup   = (request) => request.Headers.Add("Accept", "application/json"),
                ResponseReader = (response, formatters, type) =>
                {
                    var versionHeader = response.Headers.FirstOrDefault(x => x.Key == "DataServiceVersion");
                    object result     = null;
                    if (versionHeader.Value.Any(x => x != null && x.Contains("1.0")))
                    {
                        result = ReadFromV1(response, formatters, type);
                    }
                    else if (versionHeader.Value.Any(x => x != null && x.Contains("2.0")))
                    {
                        result = ReadFromV2(response, formatters, type);
                    }
                    else
                    {
                        throw new NotSupportedException("DataServiceVersion not supported.");
                    }

                    var taskCompletionSource = new TaskCompletionSource <object>();
                    try
                    {
                        taskCompletionSource.SetResult(result);
                    }
                    catch (Exception e)
                    {
                        taskCompletionSource.SetException(e);
                    }
                    return(taskCompletionSource.Task);
                }
            })
            {
                BaseAddress = new Uri("http://services.odata.org/Northwind/Northwind.svc/")
            };

            return(pocoClient.Context <Customer>()
                   .Skip(skip).Take(count).ToList());
        }