Created
August 24, 2011 22:52
-
-
Save stimms/1169508 to your computer and use it in GitHub Desktop.
Test using a container to get the late binding of IResolvers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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