How to write a unit test which checks a VM calls TryClose?

Apr 22, 2011 at 2:09 PM

Hello all,

Given this VM:

public class StartingPlayersViewModel : Screen
{
	public StartingPlayersViewModel()
	{
		Cancelled = true;
	}

	public bool Cancelled { get; set; }

	public void Validate()
	{
		Cancelled = false;

		TryClose(true);
	}

	public void Cancel()
	{
		TryClose(false);
	}
}

How would you write a unit test which checks that TryClose has been called?

Currently, Caliburn is complaining that: TryClose requires a parent IConductor or a view with a Close method or IsOpen property.

Thanks!

Mike

Coordinator
Apr 22, 2011 at 3:50 PM

Try creating a Fake with a Close method (does not need to be a real view). Call AttachView and pass your fake in. Proceed with your test.

Apr 24, 2011 at 4:23 AM

I have an IResult which calls TryClose for me, I can then write a simple test which checks this is returned.