File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
- <Project Sdk =" Microsoft.NET.Sdk" >
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
4
<TargetFrameworks >netcoreapp1.0;netcoreapp1.1;netcoreapp2.0</TargetFrameworks >
7
7
8
8
<ItemGroup >
9
9
<PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.5.0" />
10
+ <PackageReference Include =" Moq" Version =" 4.10.1" />
10
11
<PackageReference Include =" MSTest.TestAdapter" Version =" 1.2.0" />
11
12
<PackageReference Include =" MSTest.TestFramework" Version =" 1.2.0" />
13
+ <PackageReference Include =" RichardSzalay.MockHttp" Version =" 5.0.0" />
12
14
</ItemGroup >
13
15
14
16
<ItemGroup >
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Net ;
5
+ using System . Net . Http ;
6
+ using System . Threading . Tasks ;
4
7
using Microsoft . VisualStudio . TestTools . UnitTesting ;
8
+ using Moq ;
9
+ using RichardSzalay . MockHttp ;
5
10
6
11
namespace WebPush . Test
7
12
{
@@ -109,5 +114,19 @@ public void TestSetVapidDetails()
109
114
Assert . IsTrue ( authorizationHeader . StartsWith ( @"WebPush " ) ) ;
110
115
Assert . IsTrue ( cryptoHeader . Contains ( @"p256ecdsa" ) ) ;
111
116
}
117
+
118
+ [ TestMethod ]
119
+ public void TestPassingHttpClient ( )
120
+ {
121
+ var mockHttp = new MockHttpMessageHandler ( ) ;
122
+ mockHttp . When ( TestFcmEndpoint ) . Respond ( HttpStatusCode . Created ) ;
123
+
124
+ var client = new WebPushClient ( mockHttp . ToHttpClient ( ) ) ;
125
+ client . SetVapidDetails ( "mailto:example@example.com" , TestPublicKey , TestPrivateKey ) ;
126
+
127
+ var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
128
+
129
+ client . SendNotification ( subscription , "123" ) ;
130
+ }
112
131
}
113
132
}
Original file line number Diff line number Diff line change @@ -21,7 +21,17 @@ public class WebPushClient
21
21
private HttpClient _httpClient ;
22
22
private VapidDetails _vapidDetails ;
23
23
24
- public WebPushClient ( HttpClientHandler httpClientHandler = null )
24
+ public WebPushClient ( )
25
+ {
26
+
27
+ }
28
+
29
+ public WebPushClient ( HttpClient httpClient )
30
+ {
31
+ _httpClient = httpClient ;
32
+ }
33
+
34
+ public WebPushClient ( HttpClientHandler httpClientHandler )
25
35
{
26
36
_httpClientHandler = httpClientHandler ;
27
37
}
You can’t perform that action at this time.
0 commit comments