public void ToQueryString_WithObjectContainingCollection_ReturnsQuery() { string queryString = "names=" + "%5B" + "%22John%20Smith%22%2C" + "%22David%20Jones%22%2C" + "%22Sam%20Smith%22" + "%5D" + "&dob=2000-01-01T00%3A00%3A00"; var query = new { names = new[] { "John Smith", "David Jones", "Sam Smith" }, dob = new DateTime(2000, 1, 1) }; var formattedUrl = UrlSerializer.ToQueryString(query); Assert.AreEqual(queryString, formattedUrl); }
private object CraeteRequestFromUrl(Type targetType) { UriTemplateMatch templateMatch = _webOperationContext.IncomingRequest.UriTemplateMatch; NameValueCollection queryParams = templateMatch.QueryParameters; return(UrlSerializer.FromQueryParams(queryParams).GetRequestValue(targetType)); }
public void FromType_Type_Ok() { Type actualType = typeof(string); IUrlSerializer urlSerializer = UrlSerializer.FromType(actualType); Assert.Equal(1, urlSerializer.QueryParams.Count); Assert.Equal(actualType.Name, urlSerializer.GetTypeValue()); }
public void ToUrl_WithTemplateRequirementsThatAreNotInParameters_Ignores() { string template = "test/{test}"; var formattedUrl = UrlSerializer.ToUrl(template, new object()); Assert.AreEqual(template, formattedUrl); }
public void ToUrl_WithNullParameters_ReturnsTemplate() { string template = "test/{test}"; var formattedUrl = UrlSerializer.ToUrl(template, null); Assert.AreEqual(template, formattedUrl); }
public void SerializeForUrl_WhenValueIsNull_ReturnsEmptyString() { var expected = string.Empty; var result = UrlSerializer.SerializeForUrl <object>(null); Assert.AreEqual(expected, result); }
public void SerializeForUrl_WhenValueIsDateTime_Serializes() { var expected = "2001-01-01T00%3A00%3A00"; var result = UrlSerializer.SerializeForUrl(new DateTime(2001, 1, 1, 0, 0, 0)); Assert.AreEqual(expected, result); }
public void SerializeForUrl_WhenValueIsString_Serializes() { var expected = "test%20URL"; var result = UrlSerializer.SerializeForUrl("test URL"); Assert.AreEqual(expected, result); }
public void ToUrl_WithNullSegments_ReturnsEmptyString() { IEnumerable <string> segments = null; var formattedUrl = UrlSerializer.ToUrl(segments, true); Assert.AreEqual(string.Empty, formattedUrl); }
public void ToQueryString_WithNull_ReturnsEmptyString() { string expected = string.Empty; var result = UrlSerializer.ToQueryString(null); Assert.AreEqual(expected, result); }
public void ToUrl_WithNullTemplate_ReturnsEmptyString() { string template = null; var formattedUrl = UrlSerializer.ToUrl(template, new object()); Assert.AreEqual(string.Empty, formattedUrl); }
internal RequestMetadata FromRestMessage(Message message) { UriTemplateMatch templateMatch = WebOperationContext.Current.IncomingRequest.UriTemplateMatch; NameValueCollection queryParams = templateMatch.QueryParameters; string typeName = UrlSerializer.FromQueryParams(queryParams).GetTypeValue(); Type targetType = GetRequestType(typeName); return(RequestMetadata.FromRestMessage(message, targetType)); }
public Bootstrapper() { UrlSerializer = new UrlSerializer("journal://", new List <Route> { new Route("settings", typeof(SettingsPage), typeof(SettingsTarget), () => new SettingsPageViewModel()), new Route("lists/{listid}", typeof(MainPage), typeof(ListTarget), () => new MainPageViewModel(_navigator, _lists, _todos)), new Route("", typeof(MainPage), typeof(HomeTarget), () => new MainPageViewModel(_navigator, _lists, _todos)) }); _navigator = new Navigator(UrlSerializer); }
public void ToUrl_WithParametersThatAreNotInTemplate_Skips() { string template = "test"; var formattedUrl = UrlSerializer.ToUrl(template, new { test = "as df" }); Assert.AreEqual(template, formattedUrl); }
public void ToUrl_WithParametersThatNeedSerializing_Serialize() { string template = "test/{test}"; string expected = "test/as%20df"; var formattedUrl = UrlSerializer.ToUrl(template, new { test = "as df" }); Assert.AreEqual(expected, formattedUrl); }
public void FromQueryParams_QueryParams_Ok() { const string TypeValue = "GetClientRequest"; string query = string.Format("?type={0}&id=4DA2F891-953F-4637-AE83-6791688EAFA2&country=NL", TypeValue); NameValueCollection queryParams = HttpUtility.ParseQueryString(query); IUrlSerializer urlSerializer = UrlSerializer.FromQueryParams(queryParams); string actualType = urlSerializer.GetTypeValue(); Assert.Equal(TypeValue, actualType); Assert.Equal(queryParams.Count, urlSerializer.QueryParams.Count); }
/// <summary> /// Use an url-encoded form format body content, with a specified body /// </summary> /// <param name="body">The data to send as body content</param> /// <param name="encoding">The text encoding to use</param> /// <returns>The source <see cref="FluentRequest"/></returns> /// <exception cref="ArgumentNullException"><paramref name="encoding"/> is <see langword="null"/></exception> public FluentRequest Form(object body, Encoding encoding) { if (encoding is null) { throw new ArgumentNullException(nameof(encoding)); } var bodyAsQueryString = UrlSerializer.ToQueryString(body); ToContent(ContentType.Application.Form, bodyAsQueryString, encoding); return(_request); }
public void ToQueryString_WithSimpleObject_ReturnsQuery() { string queryString = "name=John%20Smith&dob=2000-01-01T00%3A00%3A00"; var query = new { name = "John Smith", dob = new DateTime(2000, 1, 1) }; var formattedUrl = UrlSerializer.ToQueryString(query); Assert.AreEqual(queryString, formattedUrl); }
public void ToUrl_WithValidSegments_ReturnsUrl() { var segments = new[] { "asdf", "goog", "wo2" }; string finalUrl = string.Join("/", segments); var formattedUrl = UrlSerializer.ToUrl(segments, true); Assert.AreEqual(finalUrl, formattedUrl); }
public void ToUrl_WithInvalidSegments_ReturnsEscapedUrl() { var segments = new[] { "as d f", "g oog", "wo2" }; string finalUrl = "as%20d%20f/g%20oog/wo2"; var formattedUrl = UrlSerializer.ToUrl(segments, true); Assert.AreEqual(finalUrl, formattedUrl); }
public void Form_WithData_AddsHeaderAndContent() { var form = new { q = "test" }; var expected = UrlSerializer.ToQueryString(form); var request = Mock.CreateRequest(); request .WithBody() .Form(form); Assert.AreEqual(expected, GetBodyOfRequest(request)); Assert.AreEqual("application/x-www-form-urlencoded", GetContentType(request)); }
public void FromValue_Value_Ok() { var request = new Request { Id = 1, Name = "Nelibur" }; IUrlSerializer urlSerializer = UrlSerializer.FromValue(request); NameValueCollection actual = urlSerializer.QueryParams; Assert.Equal(3, urlSerializer.QueryParams.Count); var expected = new NameValueCollection { { RestServiceMetadata.ParamName.Type, "Request" }, { "Id", "1" }, { "Name", "Nelibur" } }; Assert.Equal(ToKeyValue(expected), ToKeyValue(actual)); }
internal static string ToUrl(this object value, Uri serviceAddress, string operationType, bool responseRequired = true) { var builder = new UriBuilder(serviceAddress); switch (operationType) { case OperationType.Post: builder = (responseRequired ? builder.AddPath(RestServiceMetadata.Path.Post) : builder.AddPath(RestServiceMetadata.Path.PostOneWay)) .AddQuery(UrlSerializer.FromType(value.GetType()).QueryParams); break; case OperationType.Put: builder = (responseRequired ? builder.AddPath(RestServiceMetadata.Path.Put) : builder.AddPath(RestServiceMetadata.Path.PutOneWay)) .AddQuery(UrlSerializer.FromType(value.GetType()).QueryParams); break; case OperationType.Get: builder = (responseRequired ? builder.AddPath(RestServiceMetadata.Path.Get) : builder.AddPath(RestServiceMetadata.Path.GetOneWay)) .AddQuery(UrlSerializer.FromValue(value).QueryParams); break; case OperationType.Delete: builder = (responseRequired ? builder.AddPath(RestServiceMetadata.Path.Delete) : builder.AddPath(RestServiceMetadata.Path.DeleteOneWay)) .AddQuery(UrlSerializer.FromValue(value).QueryParams); break; default: string errorMessage = string.Format( "OperationType {0} with void return is absent", operationType); throw Error.InvalidOperation(errorMessage); } return(builder.Uri.ToString()); }
public FrameNavigator( SerializableFrame frame, Bootstrapper bootstrapper) { _frame = frame; _navigator = bootstrapper.Navigator; _urlSerializer = bootstrapper.UrlSerializer; _navigator.Navigated += OnNavigated; SystemNavigationManager.GetForCurrentView().BackRequested += (sender, e) => { if (_frame.CanGoBack) { _frame.GoBack(); e.Handled = true; } }; _frame.Navigated += OnFrameNavigated; }
public void FromType_NullQueryParams_ThrowException() { Assert.Throws(typeof(ArgumentNullException), () => UrlSerializer.FromType(null)); }
public Navigator(UrlSerializer router) { _urlSerializer = router; }
/// <summary> /// Set the relative path for the request /// </summary> /// <param name="sanitiseSegments">Whether to Uri sanitise each of the path segments</param> /// <param name="pathSegments">The path segments to use</param> /// <returns>This <see cref="FluentRequestUrl"/></returns> public FluentRequestUrl Path(bool sanitiseSegments, IEnumerable <string> pathSegments) { pathUrl = UrlSerializer.ToUrl(pathSegments, sanitiseSegments); return(this); }
/// <summary> /// Set the relative path for the request /// </summary> /// <param name="pathTemplate">The path template to use (such as "api/people/{id}")</param> /// <param name="parameters">The object to overlay onto the path template</param> /// <returns>This <see cref="FluentRequestUrl"/></returns> public FluentRequestUrl Path(string pathTemplate, object parameters) { pathUrl = UrlSerializer.ToUrl(pathTemplate, parameters); return(this); }
/// <summary> /// Use a query string for the request /// </summary> /// <param name="query">The object to convert and use as the query string</param> /// <returns>This <see cref="FluentRequestUrl"/></returns> public FluentRequestUrl Query(object query) { return(Query(UrlSerializer.ToQueryString(query))); }