1. Joe Roney
  2. Linq2Rest

Commits

Jacob Reimers  committed 985f1a8

Changed rest clients back to use Uri.

  • Participants
  • Parent commits 7b7a158
  • Branches default

Comments (0)

Files changed (18)

File Linq2Rest.Reactive.SL.IntegrationTests/FakeAsyncRestClientFactory.cs

View file
 			}
 		}
 
-		public IAsyncRestClient Create(string source)
+		public IAsyncRestClient Create(Uri source)
 		{
 			return new FakeAsyncResultClient(_responseDelay);
 		}

File Linq2Rest.Reactive.Tests/Fakes/FakeAsyncRestClientFactory.cs

View file
 			}
 		}
 
-		public IAsyncRestClient Create(string source)
+		public IAsyncRestClient Create(Uri source)
 		{
 			return new FakeAsyncResultClient(_responseDelay);
 		}

File Linq2Rest.Reactive.Tests/RequestTests.cs

View file
 
 			_mockClientFactory = new Mock<IAsyncRestClientFactory>();
 			_mockClientFactory.SetupGet(x => x.ServiceBase).Returns(new Uri("http://localhost"));
-			_mockClientFactory.Setup(x => x.Create(It.IsAny<string>())).Returns(_mockRestClient.Object);
+			_mockClientFactory.Setup(x => x.Create(It.IsAny<Uri>())).Returns(_mockRestClient.Object);
 
 			_observable = new RestObservable<FakeItem>(_mockClientFactory.Object, new TestSerializerFactory());
 		}
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$filter=IntValue+le+3";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=IntValue+le+3");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			_mockClientFactory.Verify(x => x.Create(It.IsAny<string>()), Times.Once());
+			_mockClientFactory.Verify(x => x.Create(It.IsAny<Uri>()), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$filter=(IntValue+le+3)+and+(StringValue+eq+'blah')";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=(IntValue+le+3)+and+(StringValue+eq+'blah')");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne(2000);
 
-			const string RequestUri = "http://localhost/?$filter=Children/any(y:+y/Text+eq+'blah')";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=Children%2fany(y:+y%2fText+eq+'blah')");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne(2000);
 
-			const string RequestUri = "http://localhost/?$filter=Children/all(y:+y/Text+eq+'blah')";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=Children%2fall(y:+y%2fText+eq+'blah')");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne(2000);
 
-			const string RequestUri = "http://localhost/?$filter=Children/all(y:+y/Descendants/any(z:+z/Text+eq+'blah'))";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=Children%2fall(y:+y%2fDescendants%2fany(z:+z%2fText+eq+'blah'))");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$filter=IntValue+le+3";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=IntValue+le+3");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$top=1";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$top=1");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$top=1";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$top=1");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$skip=1";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$skip=1");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$select=StringValue,IntValue";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$select=StringValue,IntValue");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 
 		[Test]
 
 			waitHandle.WaitOne();
 
-			const string RequestUri = "http://localhost/?$filter=IntValue+le+3";
-			_mockClientFactory.Verify(x => x.Create(RequestUri), Times.Once());
+			var requestUri = new Uri("http://localhost/?$filter=IntValue+le+3");
+			_mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
 		}
 	}
 }

File Linq2Rest.Reactive.Tests/RestObservableTests.cs

View file
 
 			var mockClientFactory = new Mock<IAsyncRestClientFactory>();
 			mockClientFactory.SetupGet(x => x.ServiceBase).Returns(new Uri("http://localhost"));
-			mockClientFactory.Setup(x => x.Create(It.IsAny<string>())).Returns(mockRestClient.Object);
+			mockClientFactory.Setup(x => x.Create(It.IsAny<Uri>())).Returns(mockRestClient.Object);
 
 			new RestObservable<FakeItem>(mockClientFactory.Object, new TestSerializerFactory())
 				.Where(x => x.StringValue == "blah")

File Linq2Rest.Reactive.WP7Sample/FakeAsyncRestClientFactory.cs

View file
 			}
 		}
 
-		public IAsyncRestClient Create(string source)
+		public IAsyncRestClient Create(Uri source)
 		{
 			return new FakeAsyncResultClient(_responseDelay);
 		}

File Linq2Rest.Reactive/IAsyncRestClientFactory.cs

View file
 		/// </summary>
 		/// <param name="source">The <see cref="Uri"/> to download from.</param>
 		/// <returns>An <see cref="IAsyncRestClient"/> instance.</returns>
-		IAsyncRestClient Create(string source);
+		IAsyncRestClient Create(Uri source);
 	}
 
 #if !SILVERLIGHT
 			}
 		}
 
-		public IAsyncRestClient Create(string source)
+		public IAsyncRestClient Create(Uri source)
 		{
 			Contract.Requires<ArgumentNullException>(source != null);
 

File Linq2Rest.Reactive/Implementations/AsyncJsonRestClientFactory.cs

View file
 		/// </summary>
 		/// <param name="source">The <see cref="Uri"/> to download from.</param>
 		/// <returns>An <see cref="IAsyncRestClient"/> instance.</returns>
-		public IAsyncRestClient Create(string source)
+		public IAsyncRestClient Create(Uri source)
 		{
-			return new AsyncJsonRestClient(new Uri(source));
+			return new AsyncJsonRestClient(source);
 		}
 
 		private class AsyncJsonRestClient : IAsyncRestClient

File Linq2Rest.Reactive/Implementations/AsyncXmlRestClientFactory.cs

View file
 		/// </summary>
 		/// <param name="source">The <see cref="Uri"/> to download from.</param>
 		/// <returns>An <see cref="IAsyncRestClient"/> instance.</returns>
-		public IAsyncRestClient Create(string source)
+		public IAsyncRestClient Create(Uri source)
 		{
-			return new AsyncXmlRestClient(new Uri(source));
+			return new AsyncXmlRestClient(source);
 		}
 
 		private class AsyncXmlRestClient : IAsyncRestClient

File Linq2Rest.Tests/Provider/RestContextTests.cs

View file
 				.Query
 				.FirstOrDefault(x => x.Child.Name == "Foo");
 
-			var uri = new Uri("http://localhost/?$filter=Child/Name+eq+'Foo'&$top=1");
+			var uri = new Uri("http://localhost/?$filter=Child%2fName+eq+'Foo'&$top=1");
 
 			_mockComplexClient.Verify(x => x.Get(uri), Times.Once());
 		}

File Linq2Rest/Parser/FilterExpressionFactory.cs

View file
 				case "year":
 					return Expression.Property(left, MethodProvider.YearProperty);
 				case "round":
-					Contract.Assume(left != null);
-
 					return Expression.Call(left.Type == typeof(double) ? MethodProvider.DoubleRoundMethod : MethodProvider.DecimalRoundMethod, left);
 				case "floor":
-					Contract.Assume(left != null);
-
 					return Expression.Call(left.Type == typeof(double) ? MethodProvider.DoubleFloorMethod : MethodProvider.DecimalFloorMethod, left);
 				case "ceiling":
-					Contract.Assume(left != null);
-
 					return Expression.Call(left.Type == typeof(double) ? MethodProvider.DoubleCeilingMethod : MethodProvider.DecimalCeilingMethod, left);
 				case "any":
 					{
-						Contract.Assume(left != null);
+						Contract.Assume(right != null);
 
 						return CreateAnyAllExpression(
 													  left,
 
 				case "all":
 					{
-						Contract.Assume(left != null);
+						Contract.Assume(right != null);
 
 						return CreateAnyAllExpression(
 													  left,
 
 			public IEnumerable<ParameterExpression> GetParameters(Expression expr)
 			{
+				Contract.Requires(expr != null);
+				Contract.Ensures(Contract.Result<IEnumerable<ParameterExpression>>() != null);
+
 				_parameters = new List<ParameterExpression>();
 				Visit(expr);
 				return _parameters;

File Linq2Rest/Parser/Readers/IValueExpressionFactory.cs

View file
 namespace Linq2Rest.Parser.Readers
 {
 	using System;
+	using System.Diagnostics.Contracts;
 	using System.Linq.Expressions;
 
+	[ContractClass(typeof(ValueExpressionFactoryContracts))]
 	internal interface IValueExpressionFactory
 	{
 		Type Handles { get; }
 
 		ConstantExpression Convert(string token);
 	}
+
+	[ContractClassFor(typeof(IValueExpressionFactory))]
+	internal abstract class ValueExpressionFactoryContracts : IValueExpressionFactory
+	{
+		public Type Handles
+		{
+			get
+			{
+				Contract.Ensures(Contract.Result<Type>() != null);
+				throw new NotImplementedException();
+			}
+		}
+
+		public ConstantExpression Convert(string token)
+		{
+			Contract.Requires(token != null);
+			throw new NotImplementedException();
+		}
+	}
 }

File Linq2Rest/Parser/Readers/ParameterValueReader.cs

View file
 		public static Expression Read(Type type, string token, IFormatProvider formatProvider)
 		{
 			Contract.Requires(token != null);
+			Contract.Requires(type != null);
 
 			if (string.Equals(token, "null", StringComparison.OrdinalIgnoreCase))
 			{
 		private static Expression GetKnownConstant(Type type, string token, IFormatProvider formatProvider)
 		{
 			Contract.Requires(token != null);
+			Contract.Requires(type != null);
 
 			if (type.IsEnum)
 			{

File Linq2Rest/Parser/Readers/StreamExpressionFactory.cs

View file
 			}
 		}
 
+		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
 		public override ConstantExpression Convert(string token)
 		{
 			var baseResult = base.Convert(token);

File Linq2Rest/Provider/ExpressionVisitor.cs

View file
 		{
 #if !SILVERLIGHT
 			Contract.Requires(expression != null);
+			Contract.Requires(type != null);
 #endif
 
 			if (expression is LambdaExpression)

File Linq2Rest/Provider/ParameterBuilder.cs

View file
 
 		public string ExpandParameter { get; set; }
 
-		public string GetFullUri()
+		public Uri GetFullUri()
 		{
 #if !SILVERLIGHT
-			Contract.Ensures(Contract.Result<string>() != null);
+			Contract.Ensures(Contract.Result<Uri>() != null);
 #endif
 			var parameters = new List<string>();
 			if (!string.IsNullOrWhiteSpace(FilterParameter))
 			var builder = new UriBuilder(_serviceBase);
 			builder.Query = (string.IsNullOrEmpty(builder.Query) ? string.Empty : "&") + string.Join("&", parameters);
 
-			return builder.Uri.ToString();
+			return builder.Uri;
 		}
 
 		private static string BuildParameter(string name, string value)

File Linq2Rest/Provider/RestQueryProvider.cs

View file
 			Contract.Ensures(Contract.Result<IList<T>>() != null);
 
 			var fullUri = builder.GetFullUri();
-			var response = _client.Get(new Uri(fullUri));
+			var response = _client.Get(fullUri);
 			var serializer = _serializerFactory.Create<T>();
 			var resultSet = serializer.DeserializeList(response);
 
 		private IEnumerable GetIntermediateResults(Type type, ParameterBuilder builder)
 		{
 			var fullUri = builder.GetFullUri();
-			var response = _client.Get(new Uri(fullUri));
+			var response = _client.Get(fullUri);
 			var genericMethod = CreateMethod.MakeGenericMethod(type);
 			dynamic serializer = genericMethod.Invoke(_serializerFactory, null);
 			var resultSet = serializer.DeserializeList(response);

File Linq2Rest/Provider/Writers/IValueWriter.cs

View file
 namespace Linq2Rest.Provider.Writers
 {
 	using System;
+#if !SILVERLIGHT
+	using System.Diagnostics.Contracts;
+#endif
 
+#if !SILVERLIGHT
+	[ContractClass(typeof(ValueWriterContracts))]
+#endif
 	internal interface IValueWriter
 	{
 		Type Handles { get; }
 
 		string Write(object value);
 	}
+
+#if !SILVERLIGHT
+	[ContractClassFor(typeof(IValueWriter))]
+	internal abstract class ValueWriterContracts : IValueWriter
+	{
+		public Type Handles
+		{
+			get
+			{
+				Contract.Ensures(Contract.Result<Type>() != null);
+
+				throw new NotImplementedException();
+			}
+		}
+
+		public string Write(object value)
+		{
+			Contract.Requires(value != null);
+			throw new NotImplementedException();
+		}
+	}
+#endif
 }

File Linq2Rest/Provider/Writers/RationalValueWriter.cs

View file
 
 		public string Write(object value)
 		{
-			return string.Format(
-								 CultureInfo.InvariantCulture,
-								 "{0}",
-								 value);
+			return string.Format(CultureInfo.InvariantCulture, "{0}", value);
 		}
 	}
 }