Http requests and responses

pull/113/head
yekalkan 7 years ago
parent fcc4c6269d
commit 7f650fb38a

@ -9,5 +9,29 @@ namespace Volo.Abp.Http.DynamicProxying
Task<int> IncrementValueAsync(int value);
Task GetException1Async();
Task<string> PostValueWithHeaderAndQueryStringAsync(string headerValue, string qsValue);
Task<string> PostValueWithBodyAsync(string bodyValue);
Task<Car> PostObjectWithBodyAsync(Car bodyValue);
Task<Car> PostObjectWithQueryAsync(Car bodyValue);
Task<Car> GetObjectWithUrlAsync(Car bodyValue);
Task<Car> GetObjectandIdAsync(int id, Car bodyValue);
Task<Car> GetObjectAndIdWithQueryAsync(int id, Car bodyValue);
Task<string> PutValueWithBodyAsync(string bodyValue);
Task<string> PatchValueWithBodyAsync(string bodyValue);
Task<string> PutValueWithHeaderAndQueryStringAsync(string headerValue, string qsValue);
Task<string> PatchValueWithHeaderAndQueryStringAsync(string headerValue, string qsValue);
Task<int> DeleteByIdAsync(int id);
}
}

@ -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<string> PostValueWithHeaderAndQueryStringAsync([FromHeader] string headerValue, [FromQuery] string qsValue)
{
return Task.FromResult(headerValue + "#" + qsValue);
}
[HttpPost]
[Route("post-with-body")]
public Task<string> PostValueWithBodyAsync([FromBody] string bodyValue)
{
return Task.FromResult(bodyValue);
}
[HttpPost]
[Route("post-object-with-body")]
public Task<Car> PostObjectWithBodyAsync([FromBody] Car bodyValue)
{
return Task.FromResult(bodyValue);
}
[HttpPost]
[Route("post-object-with-query")]
public Task<Car> PostObjectWithQueryAsync( Car bodyValue)
{
return Task.FromResult(bodyValue);
}
[HttpGet]
[Route("post-object-with-url/bodyValue")]
public Task<Car> GetObjectWithUrlAsync(Car bodyValue)
{
return Task.FromResult(bodyValue);
}
[HttpGet]
[Route("post-object-and-id-with-url/{id}")]
public Task<Car> 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<Car> GetObjectAndIdWithQueryAsync(int id, Car bodyValue)
{
bodyValue.Year = id;
return Task.FromResult(bodyValue);
}
[HttpPut]
[Route("put-with-body")]
public Task<string> PutValueWithBodyAsync([FromBody] string bodyValue)
{
return Task.FromResult(bodyValue);
}
[HttpPut]
[Route("put-with-header-and-qs")]
public Task<string> PutValueWithHeaderAndQueryStringAsync([FromHeader] string headerValue, [FromQuery] string qsValue)
{
return Task.FromResult(headerValue + "#" + qsValue);
}
[HttpPatch]
[Route("patch-with-header-and-qs")]
public Task<string> PatchValueWithHeaderAndQueryStringAsync([FromHeader] string headerValue, [FromQuery] string qsValue)
{
return Task.FromResult(headerValue + "#" + qsValue);
}
[HttpPatch]
[Route("patch-with-body")]
public Task<string> PatchValueWithBodyAsync([FromBody] string bodyValue)
{
return Task.FromResult(bodyValue);
}
[HttpDelete]
[Route("delete-by-id")]
public Task<int> DeleteByIdAsync(int id)
{
return Task.FromResult(id + 1);
}
}
public class Car
{
[FromQuery]
public int Year { get; set; }
[FromQuery]
public string Model { get; set; }
}
}

@ -35,5 +35,94 @@ namespace Volo.Abp.Http.DynamicProxying
var exception = await Assert.ThrowsAsync<AbpRemoteCallException>(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);
}
}
}
Loading…
Cancel
Save