Repeat.Times() does not make any calls, it is an expectation
imagine that the Random number generates the value 25. Your orignal
code then becomes
SetupResult.For(userToTest.UserName).Return("25").Repeat.Times(5);
which says that you are expecting userToTest.UserName to be called
five times and return the value "25" each time
your test will fail with the error
Rhino.Mocks.Exceptions.ExpectationViolationException:
IUser.get_UserName(); Expected #5, Actual #1.
As I mentioned in my previous post, to test the same method with
different sets of variables, I would use nUnit's TestCaseAttribute()
to pass in a range of values, I guess to use real random numbers you
might be able to do the following...
[TestCase(System.Random(DateTime.Now.Ticks).Next().ToString())]
[TestCase(System.Random(DateTime.Now.Ticks).Next().ToString())]
[TestCase(System.Random(DateTime.Now.Ticks).Next().ToString())]
[TestCase(System.Random(DateTime.Now.Ticks).Next().ToString())]
[TestCase(System.Random(DateTime.Now.Ticks).Next().ToString())]
WhenIsValidUserIsPassedAnIUserWithBothAUserNameAndPassword_ShouldReturnTrue
(string name)
{
const string password = "password";
var user = MockRepository.GenerateStub<IUSer>();
user.Stub(u=>u.UserName).Return(name);
user.Stub(u=>u.Password).Return(password);
var service = new UserValidationService();
var actual = service.IsValidUser(user);
Assert.That(actual, Is.True);
}
but all you are doing is creating a mock IUser implementation, setting
the value returned by UserName and then making sure that the mock is
valid (as prescribed by your business rule of "a user is valid if it
has a username and a password")
This test is testing that when presented with a valid IUser, does the
UserValidationService recognise it as a valid user, it should be
obvious that if the test passes with one properly instantiated IUser,
then it will pass with all, so only the first attempt is required. You
do however need to supply another unit test to ensure that when the
service is passed an incorrectly instantiated IUser that the call to
IsValid does not return true.
On Oct 26, 6:28 am, hitechnical <[email protected]> wrote:
> Bill, you're completely correct. Thanks for your time to reply in much
> detail. The idea was to understand how the Repeat.Times() calls the
> enclosed statements (which is System.Random in this case), but as you
> mentioned the seed will be same for every call, you are completely
> right. In finance industry, we used to get such type of scenarios
> where we need to pass in some random numbers as samples in order to
> test the logic. How to achieve this sort of scenarios?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---