public void GetAllForCity_CallsDataStore() { // arrange var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose); var repository = new ZipCodesRepository( dataStoreMock.Object, locationServiceMock.Object ); // act var items = repository.GetAll().ToList(); // assert dataStoreMock.Verify(mock => mock.GetAll <ZipCodeModel>(), Times.Once()); }
public void GetAll_ReturnsCorrectData() { // arrange var models = new[] { new ZipCodeModel { Id = 1, Zip = 1 }, new ZipCodeModel { Id = 3, Zip = 3 }, new ZipCodeModel { Id = 2, Zip = 2 } }; var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); dataStoreMock.Setup(mock => mock.GetAll <ZipCodeModel>()) .Returns(models.AsQueryable()); var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose); var repository = new ZipCodesRepository( dataStoreMock.Object, locationServiceMock.Object ); // act var items = repository.GetAll().ToList(); // assert Assert.AreEqual(3, items.Count); Assert.AreEqual(1, items[0].Id); Assert.AreEqual(2, items[2].Id); Assert.AreEqual(3, items[1].Id); }
public void GetAll_CallsDataStore() { // arrange var models = new[] { new ZipCodeModel { Id = 1, Zip = 1 }, new ZipCodeModel { Id = 3, Zip = 3 }, new ZipCodeModel { Id = 2, Zip = 2 } }; var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose); dataStoreMock.Setup(mock => mock.GetAll <ZipCodeModel>()) .Returns(models.AsQueryable()); var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose); var repository = new ZipCodesRepository( dataStoreMock.Object, locationServiceMock.Object ); // act var items = repository.GetAll().ToList(); // assert dataStoreMock.Verify(mock => mock.GetAll <ZipCodeModel>(), Times.Once()); }