-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
222 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using WebApiClient.Contexts; | ||
using Xunit; | ||
|
||
namespace WebApiClient.Test.Contexts | ||
{ | ||
public class ApiActionDescriptorTest | ||
{ | ||
[Fact] | ||
public void NewTest() | ||
{ | ||
var m = typeof(IUserApi).GetMethod("Get1"); | ||
var d = new ApiActionDescriptor(m); | ||
|
||
Assert.True(d.Attributes.Count == 3); | ||
Assert.True(d.Filters.Count == 1); | ||
Assert.True(d.Parameters.Count == 2); | ||
Assert.True(d.Name == m.Name); | ||
Assert.True(d.Member == m); | ||
Assert.True(d.Return.ReturnType == m.ReturnType); | ||
} | ||
|
||
[Fact] | ||
public void CloneTest() | ||
{ | ||
var m = typeof(IUserApi).GetMethod("Get1"); | ||
var d = new ApiActionDescriptor(m); | ||
var d2 = d.Clone(new object[] { null, null }); | ||
|
||
Assert.True(d.Attributes == d2.Attributes); | ||
Assert.True(d.Name == d2.Name); | ||
Assert.True(d.Filters == d2.Filters); | ||
Assert.True(d.Member == d2.Member); | ||
Assert.True(d.Parameters != d2.Parameters); | ||
Assert.True(d.Parameters.Count == d2.Parameters.Count); | ||
Assert.True(d.Return == d2.Return); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using WebApiClient.Contexts; | ||
using Xunit; | ||
|
||
namespace WebApiClient.Test.Contexts | ||
{ | ||
public class ApiParameterDescriptorTest | ||
{ | ||
[Fact] | ||
public void NewTest() | ||
{ | ||
var p1 = typeof(IUserApi).GetMethod("Get2").GetParameters()[0]; | ||
var m1 = new ApiParameterDescriptor(p1); | ||
Assert.True(m1.Attributes.Count == 1); | ||
Assert.True(m1.Index == 0); | ||
Assert.True(m1.Member == p1); | ||
Assert.True(m1.Name == p1.Name); | ||
Assert.True(m1.ParameterType == p1.ParameterType); | ||
Assert.True(m1.ValidationAttributes.Count == 1); | ||
Assert.True(m1.Value == null); | ||
|
||
|
||
var p2 = typeof(IUserApi).GetMethod("Get2").GetParameters()[1]; | ||
var m2 = new ApiParameterDescriptor(p2); | ||
Assert.True(m2.Attributes.Count == 1); | ||
Assert.True(m2.Index == 1); | ||
Assert.True(m2.Member == p2); | ||
Assert.True(m2.Name == p2.Name); | ||
Assert.True(m2.ParameterType == p2.ParameterType); | ||
Assert.True(m2.ValidationAttributes.Count == 0); | ||
Assert.True(m2.Value == null); | ||
} | ||
|
||
|
||
[Fact] | ||
public void CloneTest() | ||
{ | ||
var p1 = typeof(IUserApi).GetMethod("Get2").GetParameters()[0]; | ||
var m1 = new ApiParameterDescriptor(p1); | ||
var m2 = m1.Clone(10); | ||
|
||
Assert.True(m1.Attributes == m2.Attributes); | ||
Assert.True(m1.Name == m2.Name); | ||
Assert.True(m1.Index == m2.Index); | ||
Assert.True(m1.ParameterType == m2.ParameterType); | ||
Assert.True(m1.Member == m2.Member); | ||
Assert.True(m1.ValidationAttributes == m2.ValidationAttributes); | ||
Assert.True((int)m2.Value == 10); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using WebApiClient.Attributes; | ||
using WebApiClient.Contexts; | ||
using Xunit; | ||
|
||
namespace WebApiClient.Test.Contexts | ||
{ | ||
public class ApiReturnDescriptorTest | ||
{ | ||
[Fact] | ||
public void NewTest() | ||
{ | ||
var m1 = new ApiReturnDescriptor(typeof(IUserApi).GetMethod("Get1")); | ||
var m2 = new ApiReturnDescriptor(typeof(IUserApi).GetMethod("Get2")); | ||
|
||
Assert.True(m1.IsTaskDefinition); | ||
Assert.True(m1.Attribute.GetType() == typeof(AutoReturnAttribute)); | ||
|
||
Assert.True(m2.IsITaskDefinition); | ||
Assert.True(m2.Attribute.GetType() == typeof(JsonReturnAttribute)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Linq; | ||
using WebApiClient.Contexts; | ||
using Xunit; | ||
|
||
namespace WebApiClient.Test.Contexts | ||
{ | ||
public class DataTypeDescriptorTest | ||
{ | ||
private DataTypeDescriptor Create(string methodName) | ||
{ | ||
var method = typeof(IUserApi).GetMethod(methodName); | ||
var dataType = method.ReturnType.GetGenericArguments().FirstOrDefault(); | ||
return new DataTypeDescriptor(dataType); | ||
} | ||
|
||
[Fact] | ||
public void NewTest() | ||
{ | ||
var m1 = Create("Get1"); | ||
var m2 = Create("Get2"); | ||
var m3 = Create("Get3"); | ||
var m4 = Create("Get4"); | ||
var m5 = Create("Get5"); | ||
var m6 = Create("Get6"); | ||
|
||
Assert.True(m1.IsString); | ||
Assert.True(m2.IsHttpResponseMessage); | ||
Assert.True(m3.IsStream); | ||
Assert.True(m4.IsHttpResponseWrapper); | ||
Assert.True(m6.IsByteArray); | ||
Assert.False(m5.IsString || m5.IsStream || m5.IsByteArray || m5.IsHttpResponseMessage || m5.IsHttpResponseWrapper); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using WebApiClient.Attributes; | ||
using WebApiClient.Parameterables; | ||
|
||
namespace WebApiClient.Test.Contexts | ||
{ | ||
/// <summary> | ||
/// 用户操作接口 | ||
/// </summary> | ||
[TraceFilter] | ||
[HttpHost("http://localhost")] | ||
public interface IUserApi : IHttpApi | ||
{ | ||
[HttpGet] | ||
[Timeout(10 * 1000)] | ||
Task<string> Get1([Uri] string url, string something); | ||
|
||
[HttpGet] | ||
[JsonReturn] | ||
ITask<HttpResponseMessage> Get2([Required]string id, CancellationToken token); | ||
|
||
[HttpGet] | ||
ITask<Stream> Get3([Required]string account, CancellationToken token); | ||
|
||
[HttpGet] | ||
ITask<HttpResponseFile> Get4([Uri, Required] string uri); | ||
|
||
|
||
[HttpGet] | ||
ITask<object> Get5(string nickName); | ||
|
||
[HttpGet] | ||
ITask<byte[]> Get6(string nickName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters