How to clear previous expectations on an object?

前端 未结 3 1174
囚心锁ツ
囚心锁ツ 2020-11-29 02:37

I would like to set up a return value

_stubRepository.Stub(Contains(null)).IgnoreArguments().Return(true);

but then in a specific test, ove

3条回答
  •  一生所求
    2020-11-29 03:26

    For these situations, I created a simple RinoMocks extention method to better show the intent of the stub and promote readability.

    public static void OverridePrevious(this IMethodOptions options)
    {
        options.Repeat.Any();
    }
    

    So instead of a cryptic call like the following that may require a comment:

    [SetUp]
    public void Setup()
    {
        carStub.Stub(x => x.Model).Return("Model1");
        carStub.Stub(x => x.Model).Return("Model2");
    }
    
    [Test]
    public void SomeTest()
    {
        //Arrange
        //overrides previous stubs that were setup for the Model property
        carStub.Stub(x => x.Model).Return(null).Repeat.Any();
    
        //Act
        //Assert
    }
    

    You can get a more readable test that better shows the intent of the .Repeat.Any() calls:

    carStub.Stub(x => x.Model).Return(null).OverridePrevious();
    

提交回复
热议问题