开发者

how to test a failed moq

I have used a happy test to create a method and now i am using a null test on it.

I need to change the assert in the test method but i have no clue how to go about it. i did some searches but i can seem to only find happy path test开发者_StackOverflow社区s or returns in the main method. is there a way to do a moq and test for not excecuting or is the only way having the method return a variable (a Boolean in this case)

the method

    public void Upload(Data.RPADataEntity RPADataEntity)
    {
        if (RPADataEntity != null)
        {
            //Give RPA the first status and then insert it into the database it.
            RPADataEntity.RPAStatusID = Convert.ToInt32(Enum.RPAStatusEnum.RPAStatus.FileInputDataUploaded);
            _IRPADataLayer.InsertRpaData(RPADataEntity);
        }
    }

the test method

    [TestMethod]
    public void TestUploadRPAEntityNull()
    {
        //Arange
        var fileinputtest = new FileInput();
        RPADataEntity RPADataEntity = null;

        //Act
        fileinputtest.Upload(RPADataEntity);

        //Assert
        _mockRepository.Verify(x => x.InsertRpaData(RPADataEntity));
    }


This should do it:

_mockRepository.Verify(x => x.InsertRpaData(RPADataEntity), Times.Never());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜