Ejemplo n.º 1
0
        internal City GetById(int id)
        {
            var data = _repo.GetById(id);

            if (data == null)
            {
                throw new Exception("Invalid Id");
            }
            return(data);
        }
Ejemplo n.º 2
0
        public ActionResult <City> GetById(Guid id)
        {
            var city = _cities.GetById(id);

            if (city == null)
            {
                return(NotFound());
            }
            return(Ok(city));
        }
Ejemplo n.º 3
0
        public ActionResult <string> Get(Guid id)
        {
            var poi = repository.GetById(id);

            if (poi != null)
            {
                var city = citiesRepository.GetById(poi.CityId);
                if (city != null)
                {
                    return(Ok(poi));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 4
0
        public void GetById_ReturnsCorrectData()
        {
            // arrange
            var model = new CityModel
            {
                Id   = 1,
                Name = "1"
            };

            var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose);

            dataStoreMock.Setup(mock => mock.GetById <CityModel, int>(It.IsAny <int>()))
            .Returns(model);

            var repository = new CitiesRepository(
                dataStoreMock.Object
                );

            // act
            var item = repository.GetById(1);

            // assert
            Assert.AreEqual(1, item.Id);
        }
Ejemplo n.º 5
0
        public void GetById_CallsDataStore()
        {
            // arrange
            var model = new CityModel
            {
                Id   = 1,
                Name = "1"
            };

            var dataStoreMock = new Mock <IDataStore>(MockBehavior.Loose);

            dataStoreMock.Setup(mock => mock.GetById <CityModel, int>(It.IsAny <int>()))
            .Returns(model);

            var repository = new CitiesRepository(
                dataStoreMock.Object
                );

            // act
            repository.GetById(1);

            // assert
            dataStoreMock.Verify(mock => mock.GetById <CityModel, int>(It.Is <int>(item => item == 1)), Times.Once());
        }