我希望Session超时以进行测试

时间:2010-10-09 08:34:46

标签: c# nunit

当我在我的数据库中调用某个存储过程时,我正在尝试获取会话超时(我的数据库中的返回代码为3)。我想这样做,以便我可以成功地向我的数据库断言。我尝试让线程休眠几分钟,但我确信有更实用(更快)的方法来获得会话超时错误。

以下代码是断言“无效会话”返回代码(即2)我想做类似的事情来获得3(会话超时)作为返回代码。

    [Test, Description("Tests Possible Return Codes for the AcquireChangeLock SP")]
    public void test_invalidSession()
    {
        //Method to generate a valid Session Id
        int sessionId = src.run_Session_Logon_SP(dataSource, initialCataloge);

        //Generate a random no. and add it to the
        //retrieved sessionId to get an invalid sessionId
        Guid screw = Guid.NewGuid();
        byte[] _bytes = screw.ToByteArray();
        int k = ((int)_bytes[0]) | ((int)_bytes[1] << 8) | ((int)_bytes[2]);
        sessionId += k;

        //List with all the Tables and their Guids in the DB
        lst_objectName_Guid = src.getObjectName_Guid(direct);
        for (int i = 0; i < lst_objectName_Guid.Count; i += 2)
        {
            objectName = lst_objectName_Guid[i];            //Get the objectName values from the Even Indexes
            oGuid = lst_objectName_Guid[i + 1];            //Get the Guid valuees from the Odd Indexes
            final_oGuid = new Guid(oGuid);

            Console.WriteLine(objectName);

            //Method that generate Return Codes
            int code = src.run_AcquireChangeLock_SP(dataSource, initialCataloge, sessionId, objectName, final_oGuid);
            Assert.AreEqual(2, code);
            src.run_ReleaseChangeLock_SP(dataSource, initialCataloge, sessionId, objectName, final_oGuid);
        }
    }

1 个答案:

答案 0 :(得分:0)

您可以在存储过程的开头添加WAITFOR

-- Wait for thirty seconds...
WAITFOR DELAY '00:30'