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

Converting Rhino Mock code to JustMock

1 Answer 78 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel Brownell
Top achievements
Rank 1
Daniel Brownell asked on 22 Aug 2010, 07:16 PM
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();
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 23 Aug 2010, 10:02 AM
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
Tags
General Discussions
Asked by
Daniel Brownell
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or