// Returns 'true' if the client certificate is installed and // can be used. Precedence based on the current value of this // condition is: // blank: attempt to install certificate and return the result // 'true': attempt to install certificate and return true // 'false': bypass certificate installation and return false public static bool Client_Certificate_Installed() { // If the condition is unknown, attempt to install and use the // results of that install attempt as the value to return. bool result = GetConditionValue(nameof(Client_Certificate_Installed), ConditionalTestDetectors.IsClientCertificateInstalled); // Regardless whether the value was 'true' on entry or was detected // to be true, ensure we have attempted to install and verify the // certificate is installed. This guarantees installation errors // are captured and reported in both cases. if (result) { try { ServiceUtilHelper.EnsureClientCertificateInstalled(); } catch { // Errors in certificate installation are caught and reported // when an attempt is made to access it. But for the purposes // of this conditional test, an error does not affect the result. } } return(result); }
// Detector used by [ConditionalFact(nameof(Client_Certificate_Installed)]. // It will attempt to install the client certificate in the certificate store if // is not already present, and then it will check whether the install // succeeded. A 'true' return is a guarantee a client certificate is // installed in the certificate store. public static bool IsClientCertificateInstalled() { try { ServiceUtilHelper.EnsureClientCertificateInstalled(); return(true); } catch { // Errors installing the certificate are captured and will be // reported when an attempt is made to use it. But for the // purposes of this detector, a failure only propagates as // a 'false' return. return(false); } }