From 2bf72b7822e823290409f4958fadefc3ee13e26c Mon Sep 17 00:00:00 2001 From: timandella Date: Sat, 23 Sep 2023 15:22:11 +0100 Subject: [PATCH] fix: issue 127 - Do not set first character of query parameter name to lower case --- .../RequestInformationTests.cs | 22 +++++++++++++++++++ src/RequestInformation.cs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs b/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs index 3d7f66a0..dedb0761 100644 --- a/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs +++ b/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs @@ -111,6 +111,26 @@ public void DoesNotSetEmptyCollectionQueryParameters() Assert.False(requestInfo.QueryParameters.ContainsKey("select")); } [Fact] + public void DoesNotSetQueryParametersToLowerCaseFirstCharacter() + { + // Arrange as the request builders would + var requestInfo = new RequestInformation + { + HttpMethod = Method.GET, + UrlTemplate = "http://localhost/me{?%TenantId}" + }; + Action q = x => x.TenantId = "Tenant1"; + var qParams = new GetQueryParameters(); + q.Invoke(qParams); + + // Act + requestInfo.AddQueryParameters(qParams); + + // Assert + Assert.Contains("TenantId", requestInfo.QueryParameters.Keys); + Assert.DoesNotContain("tenantId", requestInfo.QueryParameters.Keys); + } + [Fact] public void SetsPathParametersOfDateTimeOffsetType() { // Arrange as the request builders would @@ -381,5 +401,7 @@ internal class GetQueryParameters /// Search items by search phrases [QueryParameter("%24search")] public string Search { get; set; } + /// Restrict to TenantId + public string TenantId { get; set; } } } diff --git a/src/RequestInformation.cs b/src/RequestInformation.cs index 8be72538..2540d78d 100644 --- a/src/RequestInformation.cs +++ b/src/RequestInformation.cs @@ -109,7 +109,7 @@ public void AddQueryParameters(object source) x => ( Name: x.GetCustomAttributes(false) .OfType() - .FirstOrDefault()?.TemplateName ?? x.Name.ToFirstCharacterLowerCase(), + .FirstOrDefault()?.TemplateName ?? x.Name, Value: x.GetValue(source) ) )