From d93edae8eb3df7e47dc35cf377a75222124beb66 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 1 Feb 2024 07:51:22 -0500 Subject: [PATCH] - fixes array of numbers serialization for url template parameters --- .../RequestInformationTests.cs | 14 +++++++------- src/RequestInformation.cs | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs b/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs index e2e1d872..89e701b2 100644 --- a/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs +++ b/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs @@ -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()); } @@ -544,7 +544,7 @@ 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()); } @@ -552,7 +552,7 @@ public void SetsBooleanValuesInQueryParameters() [Fact] public void SetsDateTimeOffsetValuesInQueryParameters() { - var requestInfo = new RequestInformation + var requestInfo = new RequestInformation { HttpMethod = Method.GET, UrlTemplate = "http://localhost/me{?items}" @@ -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 } }); @@ -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(() => requestInfo.URI.OriginalString); } } - + /// The messages in a mailbox or folder. Read-only. Nullable. internal class GetQueryParameters diff --git a/src/RequestInformation.cs b/src/RequestInformation.cs index 1fbd25a7..16ddf283 100644 --- a/src/RequestInformation.cs +++ b/src/RequestInformation.cs @@ -172,12 +172,12 @@ public void AddQueryParameters(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; } @@ -188,7 +188,7 @@ private static object ReplaceEnumValueByStringRepresentation(object source) { return enumValueName; } - + return source; } #if NET5_0_OR_GREATER