Skip to content

Commit 2c29f50

Browse files
committed
AddHttpApiTest
1 parent 3171b39 commit 2c29f50

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

WebApiClient.Test/HttpApiFactoryTest.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace WebApiClient.Test
1010
{
1111
public class HttpApiFactoryTest
1212
{
13+
[Fact]
14+
public void AddHttpApiTest()
15+
{
16+
var factory = new HttpApiFactory();
17+
factory.AddHttpApi<IMyApi>(null, null);
18+
19+
Assert.Throws<InvalidOperationException>(() => factory.AddHttpApi<IMyApi>(null, null));
20+
}
21+
1322
[Fact]
1423
public void CreateHttpApiTest()
1524
{
@@ -18,24 +27,22 @@ public void CreateHttpApiTest()
1827

1928
var api1 = factory.CreateHttpApi<IMyApi>();
2029
var api2 = factory.CreateHttpApi<IMyApi>();
21-
Assert.True(IsHandlerEquals(api1, api2));
30+
Assert.True(IsHttpApiConfigEquals(api1, api2));
2231
Assert.False(api1 == api2);
2332

2433
Thread.Sleep(TimeSpan.FromMilliseconds(150));
2534

2635
var api3 = factory.CreateHttpApi<IMyApi>();
27-
Assert.False(IsHandlerEquals(api1, api3));
36+
Assert.False(IsHttpApiConfigEquals(api1, api3));
2837
}
2938

30-
private bool IsHandlerEquals(IHttpApiClient x, IHttpApiClient y)
39+
private bool IsHttpApiConfigEquals(IHttpApiClient x, IHttpApiClient y)
3140
{
3241
var xInterceptor = x.ApiInterceptor as ApiInterceptor;
3342
var yInterceptor = y.ApiInterceptor as ApiInterceptor;
3443

35-
var xHandler = xInterceptor.HttpApiConfig.HttpHandler.SourceHanlder as DelegatingHandler;
36-
var yHandler = yInterceptor.HttpApiConfig.HttpHandler.SourceHanlder as DelegatingHandler;
37-
38-
return xHandler.InnerHandler == yHandler.InnerHandler;
44+
return xInterceptor.HttpApiConfig == yInterceptor.HttpApiConfig &&
45+
xInterceptor.HttpApiConfig.HttpClient == yInterceptor.HttpApiConfig.HttpClient;
3946
}
4047

4148
public interface IMyApi : IHttpApiClient

0 commit comments

Comments
 (0)