From 736446f983c79c6904a584e7c06a4e59be474e32 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Thu, 6 Aug 2020 21:22:13 +0800 Subject: [PATCH] The AddQueryStringParameter method supports values of array type. Resolve #4969 --- .../Http/Client/DynamicProxying/UrlBuilder.cs | 16 ++++++++++++- .../PersonAppServiceClientProxy_Tests.cs | 24 ++++++++++++++++--- .../TestApp/Application/IPeopleAppService.cs | 5 +++- .../TestApp/Application/PeopleAppService.cs | 11 +++++++-- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs index 162da88f16..e4b82b21e1 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -100,7 +101,20 @@ namespace Volo.Abp.Http.Client.DynamicProxying { urlBuilder.Append(isFirstParam ? "?" : "&"); - urlBuilder.Append(name + "=" + System.Net.WebUtility.UrlEncode(ConvertValueToString(value))); + if (value.GetType().IsArray || (value.GetType().IsGenericType && value is IEnumerable)) + { + var index = 0; + foreach (var item in (IEnumerable) value) + { + urlBuilder.Append(name + $"[{index++}]=" + System.Net.WebUtility.UrlEncode(ConvertValueToString(item)) + "&"); + } + //remove & at the end of the urlBuilder. + urlBuilder.Remove(urlBuilder.Length - 1, 1); + } + else + { + urlBuilder.Append(name + "=" + System.Net.WebUtility.UrlEncode(ConvertValueToString(value))); + } } private static string ConvertValueToString([NotNull] object value) diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs index 5fa3d4ab66..e53e3cabbf 100644 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs +++ b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; @@ -40,12 +41,29 @@ namespace Volo.Abp.Http.DynamicProxying [Fact] public async Task GetList() { - var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto()) - ; + var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto()); people.TotalCount.ShouldBeGreaterThan(0); people.Items.Count.ShouldBe((int) people.TotalCount); } + [Fact] + public async Task GetParams() + { + var id1 = Guid.NewGuid(); + var id2 = Guid.NewGuid(); + + var @params = await _peopleAppService.GetParams(new List + { + id1, + id2 + }, new[] {"name1", "name2"}); + + @params.ShouldContain(id1.ToString("N")); + @params.ShouldContain(id2.ToString("N")); + @params.ShouldContain("name1"); + @params.ShouldContain("name2"); + } + [Fact] public async Task Delete() { @@ -151,4 +169,4 @@ namespace Volo.Abp.Http.DynamicProxying result.Inner1.Inner2.Value3.ShouldBe("value three"); } } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs index 38b0e87787..a34cd19ebb 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -10,6 +11,8 @@ namespace Volo.Abp.TestApp.Application { Task> GetPhones(Guid id, GetPersonPhonesFilter filter); + Task> GetParams(IEnumerable ids, string[] names); + Task AddPhone(Guid id, PhoneDto phoneDto); Task RemovePhone(Guid id, string number); @@ -18,4 +21,4 @@ namespace Volo.Abp.TestApp.Application Task GetWithComplexType(GetWithComplexTypeInput input); } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs index 522f8d9794..cff72c7869 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs @@ -18,18 +18,25 @@ namespace Volo.Abp.TestApp.Application { } - + public async Task> GetPhones(Guid id, GetPersonPhonesFilter filter) { var phones = (await GetEntityByIdAsync(id)).Phones .WhereIf(filter.Type.HasValue, p => p.Type == filter.Type) .ToList(); - + return new ListResultDto( ObjectMapper.Map, List>(phones) ); } + public Task> GetParams(IEnumerable ids, string[] names) + { + var @params = ids.Select(id => id.ToString("N")).ToList(); + @params.AddRange(names); + return Task.FromResult(@params.ToList()); + } + public async Task AddPhone(Guid id, PhoneDto phoneDto) { var person = await GetEntityByIdAsync(id);