Hi,
I have been waiting to use a mocking framework for a while,
particuarly for mocking the service layer. The attraction being that
the client developers do not need to wait for completion of a service
operation before they can start testing binding in the client code.
This in effect allows parallel development of service and client based
code, allowing the client to get data via a mock service without
having to go via a real service to the db.
After choosing Rhino Mocks as the framework of choice, I successfully
set up some client test code, whereby a mock service operation returns
test data to the client. Below is an example of such code, in which I
have basically mocked a service operation GetAccounts, which returns
IEnumerable<Account>. Account being a simple user object with simple
data types as properties (i.e. ints strings).
My questions regarding this are as follows:
1) Here I am pre populating the data for rhino to return (in the set
up data code region). Is is possible to get Rhino to generate this
data randomly, i.e. a random number of accounts, all with random int
and string properties already populated with random string/int values?
2) If the above is not possible, then I am trying to understand the
point of using rhino in this instance, as surely I could just create a
list of IEnumerable<Account>, without having to additionally exposing
them via a mocked service, thus halving the code below?
I realise that perhaps my example is not the best way to mock services
and so would be very willing to hear any different suggestions, as am
sure can use a lot more of the power in Rhino particuarly with regard
to test data, as I need to get 'buy in' from client development
department and the example given may be seen as verbose and
unecessary?
Kind Regards
Simon
Code is below, which simply creates 5 test accounts and returns them
as part of the mocked service call:
#region setup test data
List<Account> ACV = new
System.Collections.Generic.List<Account>();
Account account = null;
int accountcount = 5;
IEnumerable<Account> accounts = null;
for (int i = 0; i < 5; i++)
{
account = new Account()
{
AccountCode = "",
AccountID = 123,
AccountName = ""
};
ACV.Add(account);
}
accounts = ACV;
#endregion
#region call mock service
MockRepository mocks = new MockRepository();
IAccountService MockAccountService =
mocks.CreateMock<IAccountService>();
using (mocks.Record())
{
Expect.Call(MockAccountService.GetAccount()).Return(accounts);
}
using (mocks.Playback())
{
IEnumerable<Account> ac =
MockAccountService.GetAccount();
Assert.IsTrue(ac.Count() == 5);
}
#endregion
--
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.