Exemplo n.º 1
0
        public void GetFirstForCity_CallsDataStore()
        {
            var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose);

            var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose);

            var repository = new ZipCodesRepository(
                dataStoreMock.Object,
                locationServiceMock.Object
                );

            // act
            var result = repository.GetFirstForCity(0);

            // assert
            dataStoreMock.Verify(mock => mock.FirstOrDefault(It.IsAny <Expression <Func <ZipCodeModel, bool> > >()), Times.Once());
        }
Exemplo n.º 2
0
        public void GetFirstForCity_ReturnsCorrectData()
        {
            // arrange
            var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose);

            dataStoreMock.Setup(mock => mock.FirstOrDefault(It.IsAny <Expression <Func <ZipCodeModel, bool> > >()))
            .Returns(new ZipCodeModel {
                Id = 1
            });

            var locationServiceMock = new Mock <ILocationService>(MockBehavior.Loose);

            var repository = new ZipCodesRepository(
                dataStoreMock.Object,
                locationServiceMock.Object
                );

            // act
            var result = repository.GetFirstForCity(0);

            // assert
            Assert.AreEqual(1, result.Id);
        }