我对UnitTest有以下方法:
public MessageMediaSoapClient client { get; set; }
public uint[] CheckSMSDeliveryReports()
{
try
{
client = GetSMSSoapClient();
var deliveryReports = client.CheckReports();
var delieveredMessageIds =
deliveryReports
.reports
.Where(delivery => delivery.status == DeliveryStatusType.delivered)
.Select(message => message.uid)
.ToArray()
;
if (deliveryReports != default(CheckReportsResultType) && deliveryReports.reports.Count() != 0)
{
client.ConfirmReports(
deliveryReports
.reports
.Where(delivery=> delivery.status == DeliveryStatusType.delivered)
.Select(messages => messages.receiptId).
ToList()
);
}
return delieveredMessageIds;
}
catch (Exception)
{
throw;
}
}
我已尝试设置mu Unit Test以进行初始使用,如下所示:
[TestMethod]
public void CheckDeliverReports_ReportCountGreaterThanZeo_ConfirmReportsGetCalled()
{
//Arrange
Mock<SmsSoapClient> mockSoapClient = new Mock<SmsSoapClient>();
mockSoapClient.Setup(x => x.Authenticate()).Returns(true);
mockSoapClient.SetupAllProperties();
//Act
//Assert
}
如何为公共MessageMediaSoapClient client { get; set; }
设置假冒,然后验证其方法是否被调用。