如何设置MOQ以设置属性对象并验证方法

时间:2017-03-29 01:14:38

标签: c# .net moq

我对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; }设置假冒,然后验证其方法是否被调用。

0 个答案:

没有答案