String() 类型的值不能转换成 ArrayList

Value of type String() cannot be converted into ArrayList

我正在尝试自动测试一些代码,但我似乎无法在 ListObject 上运行它。

如果我 运行 测试失败并出现错误:

Value of type String() cannot be converted into ArrayList.

这是我正在尝试的:

C# 代码:

public string[] GetUserIdsFromPassId(string organisationId, string @PassId)
    {
        DbParameterCollection parameters = new DbParameterCollection();
        parameters.Add(new DbParameter("@OrganisationId", SqlDbType.NVarChar, organisationId));
        parameters.Add(new DbParameter("@PassId", SqlDbType.NVarChar, @PassId));

        string sql = "SELECT UserId FROM Orchestra WHERE OrganisationId=@OrganisationId AND PassId=@PassId";

        ListObject list = new ListObject(_Accessor);
        list.Read(sql, parameters);

        List<string> userIds = new List<string>();
        foreach (DataRow dataRow in list.Table.Rows)
            userIds.Add(dataRow["UserId"].ToString());

        return userIds.ToArray();
    }

自动测试代码:

<TestClass()> Public Class Check_UserIdsFromPassId
    <TestMethod()> Public Sub GetUserIdsFromPassId()

        Dim organisationId As String = "1123"
        Dim PassId As String = "8110004"

        Dim UserId As string = String.Empty

        Dim ExpUserId As String = "00044"

        Dim DataServer As New DataServer()
        Dim Accessor = DataServer.GetAccessor()
        Dim _StandardHeader = New StandardHeader
        Dim _AuditProvider = New Audit.AuditProvider(_StandardHeader)
        Dim AD As New Ceridian.Administration.Authentication.AuthenticationData(Accessor, _AuditProvider)
        UserId = AD.GetUserIdsFromPassId(organisationId, PassId)
        Assert.AreEqual(ExpUserId, UserId)
        Console.WriteLine(ExpUserId)
        Console.WriteLine(UserId)

    End Sub
End Class

如果您希望被测函数 return 具有单个 UserId (ExpUserId) 的字符串数组,您可以只测试数组的长度和第一个值。

例如,删除这一行:

Dim UserId As string = String.Empty

将执行被测函数的行改为:

Dim UserId = AD.GetUserIdsFromPassId(organisationId, PassId)

然后确认 returned 数组有一个正确的值:

Assert.AreEqual(1, UserId.Count)
Assert.AreEqual(ExpUserId, UserId(0))