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" >
22
33 <PropertyGroup >
44 <TargetFrameworks >netcoreapp1.0;netcoreapp1.1;netcoreapp2.0</TargetFrameworks >
77
88 <ItemGroup >
99 <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.5.0" />
10+ <PackageReference Include =" Moq" Version =" 4.10.1" />
1011 <PackageReference Include =" MSTest.TestAdapter" Version =" 1.2.0" />
1112 <PackageReference Include =" MSTest.TestFramework" Version =" 1.2.0" />
13+ <PackageReference Include =" RichardSzalay.MockHttp" Version =" 5.0.0" />
1214 </ItemGroup >
1315
1416 <ItemGroup >
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using System . Net ;
5+ using System . Net . Http ;
6+ using System . Threading . Tasks ;
47using Microsoft . VisualStudio . TestTools . UnitTesting ;
8+ using Moq ;
9+ using RichardSzalay . MockHttp ;
510
611namespace WebPush . Test
712{
@@ -109,5 +114,19 @@ public void TestSetVapidDetails()
109114 Assert . IsTrue ( authorizationHeader . StartsWith ( @"WebPush " ) ) ;
110115 Assert . IsTrue ( cryptoHeader . Contains ( @"p256ecdsa" ) ) ;
111116 }
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+ }
112131 }
113132}
Original file line number Diff line number Diff line change @@ -21,7 +21,17 @@ public class WebPushClient
2121 private HttpClient _httpClient ;
2222 private VapidDetails _vapidDetails ;
2323
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 )
2535 {
2636 _httpClientHandler = httpClientHandler ;
2737 }
You can’t perform that action at this time.
0 commit comments