我必须在此单元测试中检查重复的电子邮件和用户名。与另一位开发人员交谈时,他说我应该在嵌套的 try catch 中检查重复的电子邮件和用户名。我不确定我是否正确理解了他,但这就是我所拥有的。其他开发者现在不可用,所以我不能要求验证。我认为这种格式不正确。有什么建议吗?
try
{
AsaMembershipProvider prov = this.GetMembershipProvider();
MembershipCreateStatus status;
MembershipUser user = prov.CreateUser("UserX", "12345", "UserX@abc.com", "", "", true, null, out status);
user = prov.GetUser("UserX", false);
var isAuthenticated = prov.ValidateUser(user.UserName, "12345");
Assert.IsTrue(isAuthenticated);
Assert.AreEqual(user.UserName, "UserX");
Assert.AreEqual(user.Email, "userx@abc.com");
try
{
prov.DeleteUser("UserX", true);
user = prov.GetUser("UserX", false);
Assert.AreEqual(null, user);
user = prov.GetUser("UserX", false);
Assert.AreEqual(status, MembershipCreateStatus.Success);
}
catch (Exception ex)
{
LogMessage(ex);
Assert.Fail(ex.Message);
}
prov.DeleteUser("UserX", true);
user = prov.GetUser("UserX", false);
Assert.AreEqual(null, user);
}
catch (Exception ex)
{
LogMessage(ex);
Assert.Fail(ex.Message);
}
}