Browse Source

Merge pull request #4978 from abpframework/maliming/arrayinquerystring

Support IEnumerable when adding query strings.
pull/4999/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
3988354d78
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs
  2. 24
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs
  3. 5
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs
  4. 11
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs

16
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -100,7 +101,20 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
urlBuilder.Append(isFirstParam ? "?" : "&"); 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) private static string ConvertValueToString([NotNull] object value)

24
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -40,12 +41,29 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact] [Fact]
public async Task GetList() public async Task GetList()
{ {
var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto()) var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto());
;
people.TotalCount.ShouldBeGreaterThan(0); people.TotalCount.ShouldBeGreaterThan(0);
people.Items.Count.ShouldBe((int) people.TotalCount); 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<Guid>
{
id1,
id2
}, new[] {"name1", "name2"});
@params.ShouldContain(id1.ToString("N"));
@params.ShouldContain(id2.ToString("N"));
@params.ShouldContain("name1");
@params.ShouldContain("name2");
}
[Fact] [Fact]
public async Task Delete() public async Task Delete()
{ {
@ -151,4 +169,4 @@ namespace Volo.Abp.Http.DynamicProxying
result.Inner1.Inner2.Value3.ShouldBe("value three"); result.Inner1.Inner2.Value3.ShouldBe("value three");
} }
} }
} }

5
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPeopleAppService.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
@ -10,6 +11,8 @@ namespace Volo.Abp.TestApp.Application
{ {
Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter); Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter);
Task<List<string>> GetParams(IEnumerable<Guid> ids, string[] names);
Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto); Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto);
Task RemovePhone(Guid id, string number); Task RemovePhone(Guid id, string number);
@ -18,4 +21,4 @@ namespace Volo.Abp.TestApp.Application
Task<GetWithComplexTypeInput> GetWithComplexType(GetWithComplexTypeInput input); Task<GetWithComplexTypeInput> GetWithComplexType(GetWithComplexTypeInput input);
} }
} }

11
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs

@ -18,18 +18,25 @@ namespace Volo.Abp.TestApp.Application
{ {
} }
public async Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter) public async Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter)
{ {
var phones = (await GetEntityByIdAsync(id)).Phones var phones = (await GetEntityByIdAsync(id)).Phones
.WhereIf(filter.Type.HasValue, p => p.Type == filter.Type) .WhereIf(filter.Type.HasValue, p => p.Type == filter.Type)
.ToList(); .ToList();
return new ListResultDto<PhoneDto>( return new ListResultDto<PhoneDto>(
ObjectMapper.Map<List<Phone>, List<PhoneDto>>(phones) ObjectMapper.Map<List<Phone>, List<PhoneDto>>(phones)
); );
} }
public Task<List<string>> GetParams(IEnumerable<Guid> ids, string[] names)
{
var @params = ids.Select(id => id.ToString("N")).ToList();
@params.AddRange(names);
return Task.FromResult(@params.ToList());
}
public async Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto) public async Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto)
{ {
var person = await GetEntityByIdAsync(id); var person = await GetEntityByIdAsync(id);

Loading…
Cancel
Save