I'm not sure how the random number comes into play here ... what this
test does is upon accessing the UserName property a "random" number is
returned, instead of the actual name. So just to be certain are you
expecting this behaviour?
I also believe that since you are using the same seed value for
Random, each call will result in the same "random" (hence the quotes)
number being generated -I've been kown to be wrong before so pleasse
forgive me if my information with regards to Random is wrong (hence my
saying that I believe it to be the case, I guess I could test it out
before replying, but that would be too easy)
Now, if it is the case that a new random number is generated every
time, I still think you will not get the result you are looking for
because of the call to .Repeat.Times(5), because my understanding of
the functionality there is that the exact same call is expected to be
made five times.
It apears to me that the random numbers are only serving as five
different user names. Looking at the code you've supplied, it looks to
me as if you are trying to test whether the test passes when you run
it five times using five different user names, personally I would
write something like the follwing (using RhinoMock and nUnit) to
achieve that test, but really you only need to supply one names, since
after all it works for that, it will work for as many as you can throw
at it ...
[Test]
[TestCase("Name one")]
[TestCase("Name two")]
[TestCase("Name three")]
[TestCase("Name four")]
[TestCase("Name five")]
public void
WhenIsValidUserIsPassedAnIUserWithBothAUserNameAndPassword_ShouldReturnTrue
(string name)
{
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);
}
Or, are you expecting that when the call is made to IsValidUser, the
IUser interface implementation sets the UserName to a random number? -
if that's the case, I would seriously suggest changing the name of
your method, because this method only says to me that it is to be
called in order to test the validity of a user object.
Am I barking up completely the wrong tree?
On Oct 22, 3:22 pm, hitechnical <[email protected]> wrote:
> Ok, I replaced Expect.On to SetupResult.For method and it worked fine.
> Now, I am doing this --
>
> SetupResult.For(userToTest.UserName).Return(new
> System.Random(10).Next().ToString()).Repeat.Times(5);
> SetupResult.For(userToTest.Password).Return("Password");
>
> My expectation is to get 5 different random numbers each time I call
> validationService.IsValidUser method
>
> for(int i =1;i<=5;i++)
> validationService.IsValidUser(userToTest);
>
> Am I doing something silly?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---