Unit testing with mock data on the server

May 6, 2011 at 3:25 PM

What really triggered my interest in this toolkit is the integration of a unit testing project. However my expectations were different. I believe it's too much work to mock the "service agents". Shouldn't be the mocking of data take place at the server side, where it's obviously where the data belong, and find some way to propagate that data to the client side at testing time?

Eric.

Coordinator
May 6, 2011 at 3:34 PM
Welcome to the world of unit testing! :-) I chose not to favor any one mocking tool, but there are several out there, such as Moq or NMock. Check those out any select whichever one you like. Remember that unit test should not depend on a database or service for the data.

Cheers,
Tony
Sent from my iPhone

On May 6, 2011, at 11:25 AM, "ericdes"<notifications@codeplex.com> wrote:

From: ericdes

What really triggered my interest in this toolkit is the integration of a unit testing project. However my expectations were different. I believe it's too much work to mock the "service agents". Shouldn't be the mocking of data take place at the server side, where it's obviously where the data belong, and find some way to propagate that data to the client side at testing time?

Eric.

May 6, 2011 at 3:46 PM

Hi Tony,

My question was not really about a specific mocking tool. I just think it would be so much easier to create a set of mock-data rather than mocking what you call the service agents. And since the data belong to the server, an ideal place to put that repository of mocked data would be on the server side (that the toolkit would 'magically' propagate to the client's unit test project...) Maybe it's just a wish...

Eric.

May 6, 2011 at 4:23 PM

I have this example where my data providers, 'live', or 'offline' for testing purposes, both implement IRepository and my domain service on the server is initialized like this:

public ProductDomainService(IRepository repository = null)
{
    // Take the testing data rather going live if a set of data
    // is provided in repository:
    if (repository != null) _repository = repository;
}

Now, by building this solution with the testing data repository, we should get a temporary generated code in the client project that could be used by the tests project... Do you have any thoughts? I'm asking your toolkit goes a long way to wrap the MVVM pattern into the RIA Service framework...

Eric.

Coordinator
May 10, 2011 at 12:51 PM

@ericdes:  I don't see any problem using repository and unit of work patterns with the Simple MVVM Toolkit.  Service agents are abstracted away from ViewModels using an interface, and as such they are acting like repositories.  The ViewModel doesn't know or care where the data is coming from, and it's the job of the locator to supply the appropriate repository to the ViewModel when creating it.  You'll notice that Simple MVVM Toolkit uses MEF to inject the appropriate data provider based on metadata specified with an attribute.