I'd like to do fast tests of my C# CustomAction functions for WiX Installer. i.e. call them from my C# WinForms application.
As it known function has the format ActionResult MyAction(Session s)
But how to create a session parameter to pass it to the function?
Like this
Session session = ? <--- no constructor
session["VAR"]="123";
ActionResult = MyAction(session);
Session object is initialized by Windows Installer and is populated with values at run time. But you don't have to depend on that. Try to restructure your code so that its functional part can be tested independently.
Your custom action might look like this:
public ActionResult MyAction(Session s)
{
var param1 = session["VAR1"];
var param2 = session["VAR2"];
return new CustomActionsRunner().MyAction(param1, param2);
}
Where CustomActionRunner
is just a class which encapsulates the methods to be called from custom actions:
public class CustomActionRunner
{
public ActionResult MyAction(string s1, string s2)
{
// here comes all the logic of your CA
return ActionResult.Success;
}
}
Thus, you can focus on unit testing your CustomActionRunner
, which doesn't depend on some specific objects like Session
, which are difficult to mock. Hope you get the idea.