How to test this pattern

4 posts, 0 answers
  1. Wray
    Wray avatar
    7 posts
    Member since:
    Aug 2013

    Posted 28 Aug 2013 Link to this post

    Can't figure out a strategy to test the pattern following:

    The problem is to avoid AnotherCall from being called from within VoidCall to isolate VoidCall's implemenation. You can't use IFoo because neither implementation can be called, but the DoNothing doesn't seem to have any effect on avoiding AnotherCall even if you do a foo.AnotherCall(). Also the CallOriginal seems valueless, since without it the method gets called anyway. I don't see the value of it without parameters to VoidCall (but I couldn't even get that to work). As a matter of fact nothing seems any different than not mocking Foo at all. What am I missing in the definition of these Arrange functions.
    [TestClass]
        public class FooTest
        {
            [TestMethod]
            public void SimpleExampleWithDoNothing()
            {
                // Arrange
                var foo = Mock.Create<Foo>();
     
                Mock.Arrange(() => foo.VoidCall()).CallOriginal();
                Mock.Arrange(() => foo.AnotherCall()).DoNothing();
     
                // Act
                foo.VoidCall();
     
                // Assert
                Mock.Assert(foo);
            }
        }
     
        public interface IFoo
        {
            void VoidCall();
     
            void AnotherCall();
        }
     
        public class Foo : IFoo
        {
            public void VoidCall()
            {
                AnotherCall();
            }
     
            public void AnotherCall()
            {
                throw new InvalidOperationException();
            }
        }
  2. Tsvetomir
    Admin
    Tsvetomir avatar
    17 posts

    Posted 29 Aug 2013 Link to this post

    Hi Wray,

    I am sorry that you are experiencing issues using JustMock.

    It seems that you have encountered a bug in JustMock. The sample that you've sent will not work if JustMock's profiler is not enabled, but we failed to show proper exception message. 

    The scenario you've sent us works perfectly with JustMock's profiler enabled. To enable it, go to JustMock menu in Visual Studio and select "Enable Profiler" form the drop-down, see attached screenshot. 

    If it is an option, you make VoidCall() and AnotherCall() virtual in the class Foo. By this you can arrange them without using the profiler. You can see more scenarios with JustMock here:  http://www.telerik.com/help/justmock/basic-usage.html

    Also, in you case 

    Mock.Arrange(() => foo.VoidCall()).CallOriginal();
    is not necessary to used, because 
    Mock.Arrange(() => foo.AnotherCall()).DoNothing();
    will mock every call of foo.AnotherCall() no matter if it is called directly or indirectly. 

    We apologize for the inconvenience caused. As a token of your gratitude I've given you some Telerik points.

    Feel free to ask us if  you have more questions.Best Regards,
    Tsvetomir
    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.
  3. DevCraft R3 2016 release webinar banner
  4. Wray
    Wray avatar
    7 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    I would like to suggest that documentation be improved. In the Basic section under things like CallOriginal, etc, you show mocking of FooBase and Foo without showing the actual classes. It would be beneficial to show differences between JustMock Lite and the commercial version.

    The example for DoNothing is particularly bad because you show mocking an interface and the default is always to do nothing, but by your answer above, it would only have any value if you were mocking a class with virtual methods with JustMock Lite and if you were mocking a class without virtual methods with JustMock commercial and the profiler enabled. This should be very clearly pointed out. DoNothing on an interface shouldn't even be in the documentation except to mention that there is no value in doing that.
  5. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 02 Sep 2013 Link to this post

    Hello Wray,

    Thank you for the feedback.

    The separation of the examples in the documentation to elevated and non-elevated is already inside our backlog for future implementation. However, it is not currently planned in the time.

    About the missing classes/interfaces you have noticed, we will include them with the next official JustMock release.

    I hope this works for you.

    P.S. For the valuable feedback, we have granted you some Telerik points.

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