Skip to content

Commit

Permalink
Fix for broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Oct 27, 2021
1 parent 2d571a1 commit 26e21b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
12 changes: 10 additions & 2 deletions abstractions/dotnet/src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ public Uri URI {
{
var parsedUrlTemplate = new UriTemplate(UrlTemplate);
foreach(var urlTemplateParameter in PathParameters)
parsedUrlTemplate.SetParameter(urlTemplateParameter.Key, urlTemplateParameter.Value);
{
// if the value is boolean, lets pass in a lowercase string as the final url will be uppercase due to the way ToString() works for booleans
var sanitizedValue = (urlTemplateParameter.Value is bool boolValue) ? boolValue.ToString().ToLower() : urlTemplateParameter.Value;
parsedUrlTemplate.SetParameter(urlTemplateParameter.Key, sanitizedValue);
}

foreach(var queryStringParameter in QueryParameters)
if(queryStringParameter.Value != null)
parsedUrlTemplate.SetParameter(queryStringParameter.Key, queryStringParameter.Value);
{
// if the value is boolean, lets pass in a lowercase string as the final url will be uppercase due to the way ToString() works for booleans
var sanitizedValue = (queryStringParameter.Value is bool boolValue) ? boolValue.ToString().ToLower() : queryStringParameter.Value;
parsedUrlTemplate.SetParameter(queryStringParameter.Key, sanitizedValue);
}
return new Uri(parsedUrlTemplate.Resolve());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public void EnablesBackingStore()
[InlineData("select", new[] { "id", "displayName" }, "select=id,displayName")]
[InlineData("count", true, "count=true")]
[InlineData("skip", 10, "skip=10")]
[InlineData("skip", null, "skip")]
[InlineData("skip", null, "")]// query parameter no placed
public void GetRequestMessageFromRequestInformationSetsQueryParametersCorrectlyWithSelect(string queryParam, object queryParamObject, string expectedString)
{
// Arrange
var requestInfo = new RequestInformation
{
HttpMethod = HttpMethod.GET,
UrlTemplate = "http://localhost/me{?top,skip,search,filter,count,orderby,select}"
};
requestInfo.SetURI("http://localhost/me", "", true);
requestInfo.QueryParameters.Add(queryParam, queryParamObject);

// Act
Expand Down
17 changes: 1 addition & 16 deletions http/dotnet/httpclient/src/HttpClientRequestAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

Expand Down Expand Up @@ -220,21 +220,6 @@ internal static HttpRequestMessage GetRequestMessageFromRequestInformation(Reque
return message;
}

private static string GetStringForQueryParameter(object value)
{
return value switch
{
null => string.Empty,
bool booleanValue =>
// ToString returns True/False with the first character in uppercase
booleanValue.ToString().ToFirstCharacterLowerCase(),
IEnumerable<object> collection =>
// the collection could be of booleans for all we know, make sure its cleaned up as well by this same function
string.Join(',', collection.Select(GetStringForQueryParameter)),
_ => value.ToString()
};
}

/// <summary>
/// Enable the backing store with the provided <see cref="IBackingStoreFactory"/>
/// </summary>
Expand Down

0 comments on commit 26e21b1

Please sign in to comment.