Moq, SetupGet, Mocking a property

后端 未结 2 921
故里飘歌
故里飘歌 2020-12-13 23:15

I\'m trying to mock a class, called UserInputEntity, which contains a property called ColumnNames: (it does contain other properties, I\'ve just si

2条回答
  •  天涯浪人
    2020-12-13 23:44

    ColumnNames is a property of type List so when you are setting up you need to pass a List in the Returns call as an argument (or a func which return a List)

    But with this line you are trying to return just a string

    input.SetupGet(x => x.ColumnNames).Returns(temp[0]);
    

    which is causing the exception.

    Change it to return whole list:

    input.SetupGet(x => x.ColumnNames).Returns(temp);
    

提交回复
热议问题