I am using C#. I have created a Wix installer and a custom action to support the wix installer. Now I am trying to create a unit test the CustomAction only, without LUX.
I have tried in many different ways, but I am unable to Mock the Microsoft.Deployment.WindowsInstaller Session. Any idea or pointers. I am using Moq.
It's not pretty, but I created a simple wrapper for the session. Something like:
public class MockSession
{
private readonly Session _session = null;
private readonly Dictionary<string, string> _properties;
public MockSession()
{
_properties = new Dictionary<string, string>();
}
public MockSession(Session session)
{
_session = session;
}
public string this[string property]
{
get
{
if (_session)
return _session[property];
else
return _properties[property];
}
set
{
if (_session)
_session[property] = value;
else
_properties[property] = value;
}
}
}
Each CustomAction method is a stub which wraps the session:
[CustomAction]
public static ActionResult Method(Session session)
{
var mockSession = new MockSession(session);
return MethodMock(mockSession);
}
public static ActionResult MethodMock(MockSession session)
{
// ... The real work here is testable
}
Not ideal, but it works in a pinch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With