UnitTesting ViewModels that use IResult

Nov 8, 2010 at 6:35 AM


Does anyone have any good advice on how to unit test viewmodels that make use of IResult and Coroutines?

My viewmodel has a method with the following signature

public IEnumerable<IResult> DoSomething()

My typical unit tests have the following pattern: 

var result =  this.viewModel.DoSomething().FirstOrDefault();

result.Execute(new ActionExecutionContext());

I might do some additional work with the result object depending on the test case.

Is this the recommended approach?



Nov 8, 2010 at 11:24 AM

Have you already had a look at http://caliburnmicro.codeplex.com/wikipage?title=Testing%20Coroutines&referringTitle=Documentation ?

The recommended approach is to don't actually execute IResult, just check that they are correctly configured.

Nov 8, 2010 at 11:37 AM

Thanks for the info, but in this case I am showing a dialog to the user and using some input in another method.

All the execute is doing is hooking up to a completed event and showing a dialog.

The magic happens in the completed event handler where I pull the user input from the dialog viewmodel and pass it to another method.

I suppose I should really look for another way of calling my callback method with specified user input, bypassing the coroutine as suggested.