You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

93 lines
2.3 KiB

using System;
using System.IO;
using System.Security.Cryptography;
using System.Xml.Serialization;
using NUnit.Framework;
namespace BWP.ABCClient
{
[TestFixture]
public class CertManagerTest
{
[SetUp]
public void Setup()
{
var manager = new CertManager();
manager.ClearAll();
}
[Test]
public void SetupLocation()
{
var manager = new CertManager();
const string fileName = "Certs/asB.pfx";
const string password = "14814622";
manager.SetupPfx(fileName, password);
var cert = manager.Fetch("337100000000066");
var rsa = cert.PrivateKey as RSACryptoServiceProvider;
}
[Test]
public void ClearAll()
{
var manager = new CertManager();
const string fileName = "Certs/asB.pfx";
const string password = "14814622";
manager.SetupPfx(fileName, password);
manager.ClearAll();
var certs = manager.FetchAll();
Assert.IsTrue(certs.Count == 0);
}
[Test]
public void SetupPfxFile()
{
var manager = new CertManager();
const string fileName = "Certs/asB.pfx";
const string password = "14814622";
manager.SetupPfx(fileName, password);
var cert = manager.Fetch("337100000000066");
Assert.AreEqual("7B97CA10275A0121D1B9", cert.SerialNumber);
}
[Test]
public void Remove()
{
var manager = new CertManager();
const string fileName = "Certs/asB.pfx";
const string password = "14814622";
manager.SetupPfx(fileName, password);
manager.Remove("337100000000066");
try {
manager.Fetch("337100000000066");
Assert.Fail("error");
} catch (Exception e) {
Assert.AreEqual("找不到商户号对应的证书", e.Message);
}
}
[Test]
public void SetupPfxStream()
{
var manager = new CertManager();
using (var stream = File.OpenRead("Certs/asB.pfx")) {
const string password = "14814622";
manager.SetupPfx(stream, password);
}
var cert = manager.Fetch("337100000000066");
Assert.AreEqual("7B97CA10275A0121D1B9", cert.SerialNumber);
}
[Test]
public void ExportCert()
{
var manager = new CertManager();
const string fileName = "Certs/asB.pfx";
const string password = "14814622";
manager.SetupPfx(fileName, password);
using (var stream = File.OpenWrite("Certs/asBclone.pfx")) {
manager.Export("337100000000066", password, stream);
}
}
}
}