From 7f650fb38a7e84edaa3f8ef63d4899ef9ae7be2e Mon Sep 17 00:00:00 2001 From: yekalkan Date: Wed, 27 Sep 2017 08:40:21 +0300 Subject: [PATCH] Http requests and responses --- .../DynamicProxying/IRegularTestController.cs | 24 +++++ .../DynamicProxying/RegularTestController.cs | 96 ++++++++++++++++++- .../RegularTestControllerClientProxy_Tests.cs | 89 +++++++++++++++++ 3 files changed, 208 insertions(+), 1 deletion(-) diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs index 7a5b2f95f6..cd8c92c66d 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs @@ -9,5 +9,29 @@ namespace Volo.Abp.Http.DynamicProxying Task IncrementValueAsync(int value); Task GetException1Async(); + + Task PostValueWithHeaderAndQueryStringAsync(string headerValue, string qsValue); + + Task PostValueWithBodyAsync(string bodyValue); + + Task PostObjectWithBodyAsync(Car bodyValue); + + Task PostObjectWithQueryAsync(Car bodyValue); + + Task GetObjectWithUrlAsync(Car bodyValue); + + Task GetObjectandIdAsync(int id, Car bodyValue); + + Task GetObjectAndIdWithQueryAsync(int id, Car bodyValue); + + Task PutValueWithBodyAsync(string bodyValue); + + Task PatchValueWithBodyAsync(string bodyValue); + + Task PutValueWithHeaderAndQueryStringAsync(string headerValue, string qsValue); + + Task PatchValueWithHeaderAndQueryStringAsync(string headerValue, string qsValue); + + Task DeleteByIdAsync(int id); } } diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs index 282a04e4b6..89c5806e0c 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Http.DynamicProxying public class RegularTestController : AbpController, IRegularTestController { [HttpGet] - [Route("increment/{value}")] + [Route("increment/{value}")] //full URL: .../api/regular-test-controller/increment/{value} public int IncrementValue(int value) { return value + 1; @@ -31,5 +31,99 @@ namespace Volo.Abp.Http.DynamicProxying { throw new UserFriendlyException("This is an error message!"); } + + [HttpPost] + [Route("post-with-header-and-qs")] + public Task PostValueWithHeaderAndQueryStringAsync([FromHeader] string headerValue, [FromQuery] string qsValue) + { + return Task.FromResult(headerValue + "#" + qsValue); + } + + [HttpPost] + [Route("post-with-body")] + public Task PostValueWithBodyAsync([FromBody] string bodyValue) + { + return Task.FromResult(bodyValue); + } + + [HttpPost] + [Route("post-object-with-body")] + public Task PostObjectWithBodyAsync([FromBody] Car bodyValue) + { + return Task.FromResult(bodyValue); + } + + [HttpPost] + [Route("post-object-with-query")] + public Task PostObjectWithQueryAsync( Car bodyValue) + { + return Task.FromResult(bodyValue); + } + + [HttpGet] + [Route("post-object-with-url/bodyValue")] + public Task GetObjectWithUrlAsync(Car bodyValue) + { + return Task.FromResult(bodyValue); + } + + [HttpGet] + [Route("post-object-and-id-with-url/{id}")] + public Task GetObjectandIdAsync(int id, [FromBody] Car bodyValue) + { + bodyValue.Year = id; + return Task.FromResult(bodyValue); + } + + [HttpGet] + [Route("post-object-and-id-with-url-and-query/{id}")] + public Task GetObjectAndIdWithQueryAsync(int id, Car bodyValue) + { + bodyValue.Year = id; + return Task.FromResult(bodyValue); + } + + [HttpPut] + [Route("put-with-body")] + public Task PutValueWithBodyAsync([FromBody] string bodyValue) + { + return Task.FromResult(bodyValue); + } + + [HttpPut] + [Route("put-with-header-and-qs")] + public Task PutValueWithHeaderAndQueryStringAsync([FromHeader] string headerValue, [FromQuery] string qsValue) + { + return Task.FromResult(headerValue + "#" + qsValue); + } + + [HttpPatch] + [Route("patch-with-header-and-qs")] + public Task PatchValueWithHeaderAndQueryStringAsync([FromHeader] string headerValue, [FromQuery] string qsValue) + { + return Task.FromResult(headerValue + "#" + qsValue); + } + + [HttpPatch] + [Route("patch-with-body")] + public Task PatchValueWithBodyAsync([FromBody] string bodyValue) + { + return Task.FromResult(bodyValue); + } + + [HttpDelete] + [Route("delete-by-id")] + public Task DeleteByIdAsync(int id) + { + return Task.FromResult(id + 1); + } + } + + public class Car + { + [FromQuery] + public int Year { get; set; } + [FromQuery] + public string Model { get; set; } } } \ No newline at end of file diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs index 9c4984d00a..1a59b39614 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs @@ -35,5 +35,94 @@ namespace Volo.Abp.Http.DynamicProxying var exception = await Assert.ThrowsAsync(async () => await _controller.GetException1Async()); exception.Error.Message.ShouldBe("This is an error message!"); } + + [Fact] + public async Task PostValueWithHeaderAndQueryStringAsync() + { + var result = await _controller.PostValueWithHeaderAndQueryStringAsync("myheader", "myqs"); + result.ShouldBe("myheader#myqs"); + } + + [Fact] + public async Task PostValueWithBodyAsync() + { + var result = await _controller.PostValueWithBodyAsync("mybody"); + result.ShouldBe("mybody"); + } + + [Fact] + public async Task PutValueWithBodyAsync() + { + var result = await _controller.PutValueWithBodyAsync("mybody"); + result.ShouldBe("mybody"); + } + + [Fact] + public async Task PostObjectWithBodyAsync() + { + var result = await _controller.PostObjectWithBodyAsync(new Car{Year = 1976, Model = "Ford"}); + result.Year.ShouldBe(1976); + result.Model.ShouldBe("Ford"); + } + + [Fact] + public async Task PostObjectWithQueryAsync() + { + var result = await _controller.PostObjectWithQueryAsync(new Car{Year = 1976, Model = "Ford"}); + result.Year.ShouldBe(1976); + result.Model.ShouldBe("Ford"); + } + + [Fact] + public async Task GetObjectWithUrlAsync() + { + var result = await _controller.GetObjectWithUrlAsync(new Car{Year = 1976, Model = "Ford"}); + result.Year.ShouldBe(1976); + result.Model.ShouldBe("Ford"); + } + + [Fact] + public async Task GetObjectandIdAsync() + { + var result = await _controller.GetObjectandIdAsync(42, new Car{Year = 1976, Model = "Ford"}); + result.Year.ShouldBe(42); + result.Model.ShouldBe("Ford"); + } + + [Fact] + public async Task GetObjectAndIdWithQueryAsync() + { + var result = await _controller.GetObjectAndIdWithQueryAsync(42, new Car{Year = 1976, Model = "Ford"}); + result.Year.ShouldBe(42); + result.Model.ShouldBe("Ford"); + } + + [Fact] + public async Task PatchValueWithBodyAsync() + { + var result = await _controller.PatchValueWithBodyAsync("mybody"); + result.ShouldBe("mybody"); + } + + [Fact] + public async Task PutValueWithHeaderAndQueryStringAsync() + { + var result = await _controller.PutValueWithHeaderAndQueryStringAsync("myheader", "myqs"); + result.ShouldBe("myheader#myqs"); + } + + [Fact] + public async Task PatchValueWithHeaderAndQueryStringAsync() + { + var result = await _controller.PatchValueWithHeaderAndQueryStringAsync("myheader", "myqs"); + result.ShouldBe("myheader#myqs"); + } + + [Fact] + public async Task DeleteByIdAsync() + { + (await _controller.DeleteByIdAsync(42)).ShouldBe(43); + } + } } \ No newline at end of file