This is a migrated thread and some comments may be shown as answers.

Behavior.Strict OccursNever instead of throwing an exception?

1 Answer 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Micah
Top achievements
Rank 1
Micah asked on 20 Aug 2013, 09:15 PM
We have some mission critical code that catches all exceptions and recovers from them in various ways.  I would like to be able to use Mock.Create<MyClass>(Behavior.Strict) so that I can know that none of the methods on MyClass are being called besides the ones I explicitly Mock.Arrange.  However, this results in the methods throwing exceptions which are then caught by my application and recovered from so I never see them.

I would like something like this, but where I didn't have to manually arrange every method on the class and instead have some Behavior that I could give to Mock.Create that would result in all of the arranges being auto-generated.  I could then manually arrange anything I didn't want to have OccursNever on, just like you can override the exceptions thrown by Behavior.Strict.
class MyClass
{
    public void Method1() { }
    public void Method2() { }
    public void Method3() { }
}
 
class ClassUnderTest
{
    public void DoSomething(MyClass myClass)
    {
        myClass.Method3();
    }
}
 
[Test]
void MyClass_methods_are_never_called()
{
    // ARRANGE
    var myClass = Mock.Create<MyClass>();
    Mock.Arrange(() => myClass.Method1()).OccursNever();
    Mock.Arrange(() => myClass.Method2()).OccursNever();
    Mock.Arrange(() => myClass.Method3()).OccursNever();
 
    // ACT
    var classUnderTest = new ClassUnderTest();
    classUnderTest.DoSomething(myClass);
 
    // ASSERT
    Mock.Assert(myClass); // this will fail
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Kaloyan
Telerik team
answered on 21 Aug 2013, 08:52 AM
Hello Micah,

Thank you for the feedback.

As currently, it is not possible to achieve such mock behavior without manually arranging the mock functions to OccursNever with JustMock, I have added this into our backlog for future implementation. Please, visit our Ideas and Feedback portal to vote for the features faster implementation. You can find it here.

P.S. I have granted you some Telerik points for pointing this out.

Regards,
Kaloyan
Telerik
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Micah
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or