public void GetById_ReturnsCorrectData() { // arrange var model = new ZipCodeModel { Id = 1, Zip = 1 }; var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); dataStoreMock.Setup(mock => mock.GetById <ZipCodeModel, int>(It.IsAny <int>())) .Returns(model); var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose); var repository = new ZipCodesRepository( dataStoreMock.Object, locationServiceMock.Object ); // act var item = repository.GetById(1); // assert Assert.AreEqual(1, item.Id); }
public void GetById_CallsDataStore() { // arrange var model = new ZipCodeModel { Id = 1, Zip = 1 }; var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); dataStoreMock.Setup(mock => mock.GetById <ZipCodeModel, int>(It.IsAny <int>())) .Returns(model); var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose); var repository = new ZipCodesRepository( dataStoreMock.Object, locationServiceMock.Object ); // act repository.GetById(1); // assert dataStoreMock.Verify(mock => mock.GetById <ZipCodeModel, int>(It.Is <int>(item => item == 1)), Times.Once()); }