Assert() and Arrange()

2 posts, 0 answers
  1. Jeroen Speldekamp
    Jeroen Speldekamp avatar
    30 posts
    Member since:
    Mar 2005

    Posted 15 Oct 2010 Link to this post

    Hello,

    I got a question or sort of functionallity request.
    After a little while working with JustMock, I found out that the Assert(action) communicates with Arrange(action).

    I will show you a sample of how the code works how it is now

    //Arrange
    Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting1.Name)).Returns(moduleSetting1.Value).MustBeCalled();
    Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting2.Name)).Returns(moduleSetting2.Value).MustBeCalled();
    Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting3.Name)).Returns(moduleSetting3.Value).MustBeCalled();
      
    //Act
    _presenter.Load();
      
    //Assert
    Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting1.Name), Occurs.Exactly(1));
    Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting2.Name), Occurs.Exactly(1));
    Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting3.Name), Occurs.Exactly(1));

    Well in the sample I got 3 module settings but in the real code i got like 12. Now I want to validate how much times it is cast with 1 code rule not 12. I thougth about the below solution but it always says it has been called once.

    //Arrange
    Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting1.Name)).Returns(moduleSetting1.Value).MustBeCalled();
    Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting2.Name)).Returns(moduleSetting2.Value).MustBeCalled();
    Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting3.Name)).Returns(moduleSetting3.Value).MustBeCalled();
      
    //Act
    _presenter.Load();
      
    //Assert
    Mock.Assert(() => _mock.ThisIsAMethod(module, Arg.AnyString), Occurs.Exactly(3));

    This woulth be a good solution because it saves me a lot of code. Hope this is possible some how or will be possible in the next update.

    Thanks in advance,
    Jeroen Speldekamp
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 18 Oct 2010 Link to this post

    Hi Jeroen,

    Thanks for the great feature suggestion. I have already added that to the backlog and hopefully it will be included in coming release.

    You can further monitor the progress of the task using the following PITS entry:
    http://www.telerik.com/support/pits.aspx#/public/justmock/3749

    Kind Regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top