Skip to content

Instantly share code, notes, and snippets.

@stimms
Created August 24, 2011 22:52
Show Gist options
  • Save stimms/1169508 to your computer and use it in GitHub Desktop.
Save stimms/1169508 to your computer and use it in GitHub Desktop.
Test using a container to get the late binding of IResolvers
[Test]
public void The_database_should_be_called()
{
ContainerBuilder builder = new ContainerBuilder();
var mockDrivingAlertRepository = new Mock<IDrivingAlertRepository>();
mockDrivingAlertRepository.Setup(x => x.GetDrivingTimeAlertByAlertID(It.IsAny<int>())).Returns(new CustomerEntities.DrivingTimeAlert());
builder.RegisterInstance<IDrivingAlertRepository>(mockDrivingAlertRepository.Object);
var handler = new Alerting.Handlers.DrivingTimeHandler(null, null, null, null, builder.Build());
handler.GetDrivingTimeForAlert(1, 2);
mockDrivingAlertRepository.Verify(x => x.GetDrivingTimeAlertByAlertID(1), Times.Once());
}
////////////////
public class DrivingTimeHandler
{
//...
internal virtual int GetDrivingTimeForAlert(int alertID, int customerID)
{
return _container.Resolve<IDrivingAlertRepository>(new NamedParameter("customerID", customerID)).GetDrivingTimeAlertByAlertID(alertID).MinutesAllowedBeforeStop;
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment