I am trying to write simple unit test for ServiceStack service, I am going through tests they've online and few threads here. This is the main thread that has most details I am trying to accomplish - Unit Test HTTPRequest Headers with ServiceStack.
However, I am facing problems injecting IDbConnection object into the service. In the webmethod, a dictionary object is populated by using OrmLite's GetDictionary method. But I am unable to mock it since GetDictionary is extension method.
private Mock<IDbConnection> _dbConnectionMock;
private Dictionary<string, string> _nameValuePairs;
[SetUp]
public void SetUp()
{
_dbConnectionMock = new Mock<IDbConnection>();
_nameValuePairs = new Dictionary<string, string>()
{
{"name","test"},
{"Updatedby", "5/23/12 7:00:15 AM"},
{"Address", "212 Adam St."}
};
}
In test method
var service = new CustomerLookupService(_dbConnectionMock.Object);
var response = (HttpResult)service.Any(new CustomerLookup { name = "test" });
//assert statements
If GetDictionary method cannot be mocked, I am even willing to call web method that hits DB, for this do I need to create AppHost.