How to Moq Setting an Indexed property

后端 未结 1 1706
一整个雨季
一整个雨季 2020-12-20 16:06

I\'m trying to use mock to verify that an index property has been set. Here\'s a moq-able object with an index:

public class Index
{
    IDictionary

        
相关标签:
1条回答
  • 2020-12-20 16:08

    This should work

    [Test]
    public void MoqUsingSetup()
    {
        //arrange
        var index = new Mock();
        index.SetupSet(o => o["Key"] = "Value").Verifiable();
        // act
        index.Object["Key"] = "Value";
        //assert
        index.Verify();
    }

    You can just treat it like a normal property setter.

    0 讨论(0)
提交回复
热议问题