Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public class X509Authentication : IClientAuthenticator
  2. {
  3. protected readonly X509Certificate2 Certificate;
  4.  
  5. public X509Authentication(X509Certificate2 certificate)
  6. {
  7. if (certificate == null) throw new ArgumentNullException("certificate");
  8. Certificate = certificate;
  9. }
  10.  
  11. public HttpClient GenerateClient()
  12. {
  13. var clientHandler = new WebRequestHandler();
  14. clientHandler.ClientCertificates.Add(Certificate);
  15. var request = new HttpClient(clientHandler);
  16. return request;
  17. }
  18. public void Dispose()
  19. {
  20. //nothing to do here.
  21. }
  22. }
  23.  
  24. [TestMethod]
  25. public void HttpClientCreationIncludesCertificate()
  26. {
  27. using (var auth = new X509Authentication(_certificate))
  28. using (var client = auth.GenerateClient())
  29. {
  30. Assert...what? The certificate(s) are not visible here.
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement