Behavior.Strict OccursNever instead of throwing an exception?

2 posts, 1 answers
  1. Micah
    Micah avatar
    4 posts
    Member since:
    Aug 2013

    Posted 20 Aug 2013 Link to this post

    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)
    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();
        // ASSERT
        Mock.Assert(myClass); // this will fail
  2. Answer
    Kaloyan avatar
    880 posts

    Posted 21 Aug 2013 Link to this post

    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.

    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.
Back to Top