Skip to content

Commit

Permalink
- fixes array of numbers serialization for url template parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Feb 1, 2024
1 parent fcf9d68 commit d93edae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void SetsIntValuesInQueryParameters()
UrlTemplate = "http://localhost/me{?items}"
};
// Act
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object []{1,2}});
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { 1, 2 } });
// Assert
Assert.Equal("http://localhost/me?items=1,2", requestInfo.URI.ToString());
}
Expand All @@ -544,15 +544,15 @@ public void SetsBooleanValuesInQueryParameters()
UrlTemplate = "http://localhost/me{?items}"
};
// Act
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object [] { true, false } });
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { true, false } });
// Assert
Assert.Equal("http://localhost/me?items=true,false", requestInfo.URI.ToString());
}

[Fact]
public void SetsDateTimeOffsetValuesInQueryParameters()
{
var requestInfo = new RequestInformation
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
Expand Down Expand Up @@ -615,7 +615,7 @@ public void SetsTimeValuesInQueryParameters()
};

// Act
var date1 = new Time(10,0,0);
var date1 = new Time(10, 0, 0);
var date2 = new Time(11, 1, 1);

requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { date1, date2 } });
Expand Down Expand Up @@ -654,15 +654,15 @@ public void DoesNotExpandSecondLayerArrays()
};

// Act
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[]{new int[]{1,2,3,4} } });
requestInfo.AddQueryParameters(new GetQueryParameters { Items = [new int[] { 1, 2, 3, 4 }] });
// Assert
Assert.Equal("http://localhost/me?items=System.Int32%5B%5D", requestInfo.URI.OriginalString);
Assert.Throws<ArgumentException>(() => requestInfo.URI.OriginalString);
}


}



/// <summary>The messages in a mailbox or folder. Read-only. Nullable.</summary>
internal class GetQueryParameters
Expand Down
8 changes: 4 additions & 4 deletions src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ public void AddQueryParameters<T>(T source)
}
}

private static string[] ExpandArray(Array collection)
private static object[] ExpandArray(Array collection)
{
var passedArray = new string[collection.Length];
var passedArray = new object[collection.Length];
for(var i = 0; i < collection.Length; i++)
{
passedArray[i] = GetSanitizedValue(collection.GetValue(i)!).ToString()!;
passedArray[i] = GetSanitizedValue(collection.GetValue(i)!);
}
return passedArray;
}
Expand All @@ -188,7 +188,7 @@ private static object ReplaceEnumValueByStringRepresentation(object source)
{
return enumValueName;
}

return source;
}
#if NET5_0_OR_GREATER
Expand Down

0 comments on commit d93edae

Please sign in to comment.