# WireMock.HttpsCertificate.ClientCertificateHelper - Coverage Report

# Summary

Class: | WireMock.HttpsCertificate.ClientCertificateHelper
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\HttpsCertificate\ClientCertificateHelper.cs
Covered lines: | 0
Uncovered lines: | 17
Coverable lines: | 17
Total lines: | 41
Line coverage: | 0%
Branch coverage: | 0%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
GetCertificate(...) | 3 | 4 | 0 | 0

# File(s)

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\HttpsCertificate\ClientCertificateHelper.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Security.Cryptography.X509Certificates;`
|  | `3` |  | ``
|  | `4` |  | `namespace WireMock.HttpsCertificate`
|  | `5` |  | `{`
|  | `6` |  | `internal static class ClientCertificateHelper`
|  | `7` |  | `{`
|  | `8` |  | `public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName)`
| 0 | `9` |  | `{`
| 0 | `10` |  | `X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);`
|  | `11` |  | `try`
| 0 | `12` |  | `{`
|  | `13` |  | `//Certificate must be in the local machine store`
| 0 | `14` |  | `certStore.Open(OpenFlags.ReadOnly);`
|  | `15` |  | ``
|  | `16` |  | `//Attempt to find by thumbprint first`
| 0 | `17` |  | `var matchingCertificates = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprintOrSubjec`
| 0 | `18` |  | `if (matchingCertificates.Count == 0)`
| 0 | `19` |  | `{`
|  | `20` |  | `//Fallback to subject name`
| 0 | `21` |  | `matchingCertificates = certStore.Certificates.Find(X509FindType.FindBySubjectName, thumbprintOrSubje`
| 0 | `22` |  | `if (matchingCertificates.Count == 0)`
| 0 | `23` |  | `{`
|  | `24` |  | `// No certificates matched the search criteria.`
| 0 | `25` |  | `throw new Exception($"No certificate found with Thumbprint or SubjectName '{thumbprintOrSubjectN`
|  | `26` |  | `}`
| 0 | `27` |  | `}`
|  | `28` |  | `// Use the first matching certificate.`
| 0 | `29` |  | `return matchingCertificates[0];`
|  | `30` |  | `}`
|  | `31` |  | `finally`
| 0 | `32` |  | `{`
|  | `33` |  | `#if NETSTANDARD || NET46`
|  | `34` |  | `certStore.Dispose();`
|  | `35` |  | `#else`
| 0 | `36` |  | `certStore.Close();`
|  | `37` |  | `#endif`
| 0 | `38` |  | `}`
| 0 | `39` |  | `}`
|  | `40` |  | `}`
|  | `41` |  | `}`

# Methods/Properties

GetCertificate(System.String)