Asserting that a method is called exactly one time

后端 未结 7 1349
无人共我
无人共我 2021-02-05 03:16

I want to assert that a method is called exactly one time. I\'m using RhinoMocks 3.5.

Here\'s what I thought would work:



        
7条回答
  •  名媛妹妹
    2021-02-05 04:04

    Here is what I just did (as recommended by Ray Houston). I would still appreciate a more elegant solution...

    [Test]
    public void just_once()
    {
        var key = "id_of_something";
    
        var source = MockRepository.GenerateStub();
    
        // set a positive expectation
        source.Expect(x => x.GetSomethingThatTakesALotOfResources(key))
            .Return(new Something())
            .Repeat.Once();
    
        var client = new Client(soure);
    
        client.GetMeMyThing(key);
    
        // set a negative expectation
        source.Expect(x => x.GetSomethingThatTakesALotOfResources(key))
            .Return(new Something())
            .Repeat.Never();
    
        client.GetMeMyThing(key);
    }
    

提交回复
热议问题