コード例 #1
0
        public void Can_Read_Add_Find_Remove_And_FindNot()
        {
            //read
            var certFromFile = CertUtil.GetFromFile(_certPath, _certPassword);

            certFromFile.Should().NotBeNull("Failed to read");
            var serial = certFromFile.SerialNumber;

            //add
            CertUtil.AddCertificate(certFromFile);
            CertUtil.AddCertificate(certFromFile, System.Security.Cryptography.X509Certificates.StoreName.TrustedPublisher);

            //find
            var cert1 = CertUtil.GetBySerial(serial);

            cert1.Should().NotBeNull("Failed to add");
            cert1.SerialNumber.Should().BeEquivalentTo(serial);

            //remove
            CertUtil.RemoveCertificate(serial);
            CertUtil.RemoveCertificate(serial, System.Security.Cryptography.X509Certificates.StoreName.TrustedPublisher);

            //find-not
            var cert2 = CertUtil.GetBySerial(serial);

            cert2.Should().BeNull("Failed to remove");
        }