Exemplo n.º 1
0
		public void QueryExpressionXmlConverterTest()
		{
			Type elementType = typeof(Customer);
			var creator = new QueryCreator(this.FnGetObjects);
			var converter = new QueryExpressionXmlConverter(creator, this.resolver);
			bool success;
			XElement x;
			Expression e;
			MethodCallExpression m;
			ConstantExpression cx;
			IQueryProvider provider;

			//the client Query. IQueryProvider has not real data.
			Query<Customer> query = new Query<Customer>(default(IQueryProvider));
			provider = ((IQueryable)query).Provider;
			IQueryable<Customer> queryable;			
			queryable = from c in query
						where c.ID == null //initialized with properties == null
						select c;

			//serialize to XML
			e = Expression.Constant(queryable);
			success = converter.TrySerialize(e, out x);

			//deserialize to ConstantExpression(Query)			
			success = converter.TryDeserialize(x, out e);
			cx = (ConstantExpression)e;
			Query<Customer> serverquery = (Query<Customer>)cx.Value;
			//upon deserialization, should have a new IQueryProvider
			Assert.AreNotEqual(provider, ((IQueryable)serverquery).Provider);
			provider = ((IQueryable)serverquery).Provider;
			
			//Execute Query on server side.
			int count = serverquery.Count();

		}