当将NUnit与可为null的参数一起使用时,应该使用
TestCase(null)
对于可为null的类型。然而,由于
string
是引用类型并且已经可以为null,应该使用
TestCase((string)null)
显式传递
null
价值
[TestCase((string)null)]
public void TestCreateClient_ShouldThrowException_IfPasswordIsNull(string certificatePassword)
{
var clientFactory = new ClientFactory(_mockRepositoryWrapper.Object, _alertService.Object);
var exception = Assert.ThrowsAsync<ArgumentNullException>(() => clientFactory.CreateClientAsync(
certificatePassword,
TestValues.CERTIFICATE_BASE64,
TestValues.APP_ID,
TestValues.DOMAIN,
TestValues.CUSTOMER_ID,
TestValues.ENVIRONMENT_ID,
TestValues.LOCALE));
Assert.That(exception.ParamName, Is.EqualTo("certificatePassword can not be null or empty"));
}