11using System ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
23using WebPush . Util ;
3- using Xunit ;
44
55namespace WebPush . Test
66{
7+ [ TestClass ]
78 public class VapidHelperTest
89 {
910 private const string ValidAudience = @"http://example.com" ;
1011 private const string ValidSubject = @"http://example.com/example" ;
1112 private const string ValidSubjectMailto = @"mailto:[email protected] " ; 1213
13- [ Fact ]
14+ private const string TestPublicKey =
15+ @"BCvKwB2lbVUYMFAaBUygooKheqcEU-GDrVRnu8k33yJCZkNBNqjZj0VdxQ2QIZa4kV5kpX9aAqyBKZHURm6eG1A" ;
16+
17+ private const string TestPrivateKey = @"on6X5KmLEFIVvPP3cNX9kE0OF6PV9TJQXVbnKU2xEHI" ;
18+
19+ [ TestMethod ]
1420 public void TestGenerateVapidKeys ( )
1521 {
1622 var keys = VapidHelper . GenerateVapidKeys ( ) ;
1723 var publicKey = UrlBase64 . Decode ( keys . PublicKey ) ;
1824 var privateKey = UrlBase64 . Decode ( keys . PrivateKey ) ;
1925
20- Assert . Equal ( 32 , privateKey . Length ) ;
21- Assert . Equal ( 65 , publicKey . Length ) ;
26+ Assert . AreEqual ( 32 , privateKey . Length ) ;
27+ Assert . AreEqual ( 65 , publicKey . Length ) ;
2228 }
2329
24- [ Fact ]
30+ [ TestMethod ]
2531 public void TestGenerateVapidKeysNoCache ( )
2632 {
2733 var keys1 = VapidHelper . GenerateVapidKeys ( ) ;
2834 var keys2 = VapidHelper . GenerateVapidKeys ( ) ;
2935
30- Assert . NotEqual ( keys1 . PublicKey , keys2 . PublicKey ) ;
31- Assert . NotEqual ( keys1 . PrivateKey , keys2 . PrivateKey ) ;
36+ Assert . AreNotEqual ( keys1 . PublicKey , keys2 . PublicKey ) ;
37+ Assert . AreNotEqual ( keys1 . PrivateKey , keys2 . PrivateKey ) ;
3238 }
3339
34- [ Fact ]
40+ [ TestMethod ]
3541 public void TestGetVapidHeaders ( )
3642 {
37- var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
38- var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
43+ var publicKey = TestPublicKey ;
44+ var privatekey = TestPrivateKey ;
3945 var headers = VapidHelper . GetVapidHeaders ( ValidAudience , ValidSubject , publicKey , privatekey ) ;
4046
41- Assert . True ( headers . ContainsKey ( @"Authorization" ) ) ;
42- Assert . True ( headers . ContainsKey ( @"Crypto-Key" ) ) ;
47+ Assert . IsTrue ( headers . ContainsKey ( @"Authorization" ) ) ;
48+ Assert . IsTrue ( headers . ContainsKey ( @"Crypto-Key" ) ) ;
4349 }
4450
45- [ Fact ]
51+ [ TestMethod ]
4652 public void TestGetVapidHeadersAudienceNotAUrl ( )
4753 {
48- var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
49- var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
50-
51- Assert . Throws ( typeof ( ArgumentException ) ,
52- delegate { VapidHelper . GetVapidHeaders ( @"invalid audience" , ValidSubject , publicKey , privatekey ) ; } ) ;
54+ var publicKey = TestPublicKey ;
55+ var privatekey = TestPrivateKey ;
56+ Assert . ThrowsException < ArgumentException > (
57+ delegate
58+ {
59+ VapidHelper . GetVapidHeaders ( "invalid audience" , ValidSubjectMailto , publicKey , privatekey ) ;
60+ } ) ;
5361 }
5462
55- [ Fact ]
63+ [ TestMethod ]
5664 public void TestGetVapidHeadersInvalidPrivateKey ( )
5765 {
5866 var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
5967 var privatekey = UrlBase64 . Encode ( new byte [ 1 ] ) ;
6068
61- Assert . Throws ( typeof ( ArgumentException ) ,
69+ Assert . ThrowsException < ArgumentException > (
6270 delegate { VapidHelper . GetVapidHeaders ( ValidAudience , ValidSubject , publicKey , privatekey ) ; } ) ;
6371 }
6472
65- [ Fact ]
73+ [ TestMethod ]
6674 public void TestGetVapidHeadersInvalidPublicKey ( )
6775 {
6876 var publicKey = UrlBase64 . Encode ( new byte [ 1 ] ) ;
6977 var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
7078
71- Assert . Throws ( typeof ( ArgumentException ) ,
79+ Assert . ThrowsException < ArgumentException > (
7280 delegate { VapidHelper . GetVapidHeaders ( ValidAudience , ValidSubject , publicKey , privatekey ) ; } ) ;
7381 }
7482
75- [ Fact ]
83+ [ TestMethod ]
7684 public void TestGetVapidHeadersSubjectNotAUrlOrMailTo ( )
7785 {
78- var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
79- var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
86+ var publicKey = TestPublicKey ;
87+ var privatekey = TestPrivateKey ;
8088
81- Assert . Throws ( typeof ( ArgumentException ) ,
89+ Assert . ThrowsException < ArgumentException > (
8290 delegate { VapidHelper . GetVapidHeaders ( ValidAudience , @"invalid subject" , publicKey , privatekey ) ; } ) ;
8391 }
8492
85- [ Fact ]
93+ [ TestMethod ]
8694 public void TestGetVapidHeadersWithMailToSubject ( )
8795 {
88- var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
89- var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
96+ var publicKey = TestPublicKey ;
97+ var privatekey = TestPrivateKey ;
9098 var headers = VapidHelper . GetVapidHeaders ( ValidAudience , ValidSubjectMailto , publicKey ,
9199 privatekey ) ;
92100
93- Assert . True ( headers . ContainsKey ( @"Authorization" ) ) ;
94- Assert . True ( headers . ContainsKey ( @"Crypto-Key" ) ) ;
101+ Assert . IsTrue ( headers . ContainsKey ( @"Authorization" ) ) ;
102+ Assert . IsTrue ( headers . ContainsKey ( @"Crypto-Key" ) ) ;
95103 }
96104 }
97105}
0 commit comments