Converting Rhino Mock code to JustMock

2 posts, 1 answers
  1. Daniel Brownell
    Daniel Brownell avatar
    3 posts
    Member since:
    May 2010

    Posted 22 Aug 2010 Link to this post

    Could you help me convert this Rhino Mock code to JustMock?

    [Test]
    public void Analyze_TooShortFileName_ErrorLoggedToService()
    {
    MockRepository mocks = new MockRepository();
    IWebService simulatedService =
    MockRespository.DynamicMock<IWebService>();
    using(mocks.Record())
    {
    //we expected "Filename too short:abc.ext"
    simulatedService.LogError("bad string");
    }
    LogAnalyzer log = new LogAnalyzer(simulatedService);
    string tooShortFileName="abc.ext";
    log.Analyze(tooShortFileName);
    mocks.VerifyAll();
    }
  2. Answer
    Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 23 Aug 2010 Link to this post

    Hello Daniel,

    Thanks for your question. Regarding converting the specified Rhino mocks test code to JustMock, here it goes:

    [Test]
    public void Analyze_TooShortFileName_ErrorLoggedToService()
    {
     
    var simulatedService = Mock.Create<IWebService>();
     
     
    // arrange
    Mock.Arrange(() => simulatedService.LogError("bad string").MustBeCalled();
     
    LogAnalyzer log = new LogAnalyzer(simulatedService);
    string tooShortFileName="abc.ext";
    log.Analyze(tooShortFileName);
     
    Mock.Asssert(simulatedService);
     
    }

    Now, in case you don't know what string will be passed into LogError method. You can additionally, write it with matcher string:

    [Test]
    public void Analyze_TooShortFileName_ErrorLoggedToService()
    {
     
    var simulatedService = Mock.Create<IWebService>();
     
    // arrange
    Mock.Arrange(() => simulatedService.LogError(Arg.AnyString).MustBeCalled();
     
    LogAnalyzer log = new LogAnalyzer(simulatedService);
    string tooShortFileName="abc.ext";
    log.Analyze(tooShortFileName);
     
    Mock.Asssert(simulatedService);
     
    }


    Hope the information was helpful.

    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