I'm using JustMock and Entity Framework to try to write unit tests for a service. In the service, I have this method:
List<Log> GetLogType(string type)
{
using (var db = new LogContext())
{
return db.Logs.Where(x => x.Type == type).ToList();
}
}
And I have a test:
[TestMethod]
public void GetLogTypeTest()
{
IList<Log> logs = new List<Log>
{
new Log() {
Id = 1,
Type = "Debug",
Message = "Test Message"
}
};
var logContext = Mock.Create<LogContext>(Constructor.Mocked).PrepareMock();
logContext.Logs.Bind(logs);
var service = new LogService();
var debugs = service.GetLogType("Debug");
Assert.AreEqual(1, debugs.Count());
}
How do I get the service to use my mocked context? Right now it is trying to connect to the database, and thus erroring.