How can I check the CustomAction functions from the application?
I would like to do quick tests of my C # CustomAction functions for the WiX installer. that is, call them from my C # WinForms application.
As you know, the function has the format ActionResult MyAction(Session s)
But how do you create a session parameter to pass it to a function?
Like this
Session session = ? <--- no constructor
session["VAR"]="123";
ActionResult = MyAction(session);
source to share
The session object is initialized by Windows Installer and populated with values ββat run time. But you shouldn't depend on it. Try to rebuild your code so that functionality can be independently tested.
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 that encapsulates methods 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;
}
}
This way you can focus on unit testing yours CustomActionRunner
, which is independent of some specific objects, such as those Session
that are difficult to fake. Hope you get the idea.
source to share