RhinoMocks - Not specifying all parameters in AssertWasCalled

17,374

You can specify the 2nd argument as Arg<T>.Is.Anything, then the actual value gets ignored.

However note that using this you need to use Arg for all arguments. Which means you need to use on the first argument: Arg<int>.Is.Equal(123).

Share:
17,374
stiank81
Author by

stiank81

System Developer mainly living in the .Net-world. Coding in C#, Javascript, html, css, ..

Updated on July 22, 2022

Comments

  • stiank81
    stiank81 almost 2 years

    I am using RhinoMocks. Now I want to assert that some function was called, but I only care about one of the arguments. Can I do a AssertWasCalled where I only specify one argument?

    In the following example I'd like the ignore what was sent to the second argument of SomeOtherFunction(). I.e. I want to check that SomeOtherFunction was called with first parameter 123 and I don't care what the second parameter was.

    [Test]
    public void SomeTest()
    {
        var myMock = MockRepository.GenerateMock<ISomeInterface>();    
        var myObj = new MyClass(myMock); 
        myObj.foo()
    
        myMock.AssertWasCalled(factory => factory.SomeOtherFunction(123, null));  
    }
    
  • Ama
    Ama almost 3 years
    Where do you use Arg<T> exactly? like this? factory.SomeOtherFunction(Arg<int>.Is.Equal(123), Arg<T>.Is.Anything)