예제 #1
0
        public void GetById_Should_NotReturnCity_IfThereIsNoCityYolo()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            mockedRepository.Setup(rep => rep.GetById(0)).Returns(() => null);

            Assert.IsNull(cityService.GetById(0));
        }
예제 #2
0
        public void GetById_ShouldThrowNullReferenceException_IfCityIsNull()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            Mock <City> cityWithIdNull = null;

            Assert.Throws <NullReferenceException>(() => cityService.GetById(cityWithIdNull.Object.Id));
        }
예제 #3
0
        public void GetById_Should_Work_IfCalledWithValidParams()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            var cityWithId = new Mock <City>();

            mockedRepository.Setup(rep => rep.GetById(cityWithId.Object.Id)).Returns(() => cityWithId.Object);

            Assert.AreEqual(cityService.GetById(cityWithId.Object.Id), cityWithId.Object);
        }
예제 #4
0
        public void GetById_Should_ReturnTheProperCityWithId_IfCalled()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            var cityWithId = new Mock <City>();

            mockedRepository.Setup(rep => rep.GetById(cityWithId.Object.Id)).Returns(() => cityWithId.Object);

            Assert.IsInstanceOf <City>(cityService.GetById(cityWithId.Object.Id));
        }
예제 #5
0
        public void GetById_Should_BeCalledOnce_IfParamsAreValid()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            var city = new Mock <City>();

            cityService.GetById(city.Object.Id);

            mockedRepository.Verify(rep => rep.GetById(city.Object.Id), Times.Once);
        }
예제 #6
0
        public void GetById_Should_ReturnTheCorrectCity_IfCalled()
        {
            var mockedRepository = new Mock <IRepository <City> >();

            var cityService = new CityServices(mockedRepository.Object);

            var city       = new Mock <City>();
            var secondCity = new Mock <City>();

            mockedRepository.Setup(rep => rep.GetById(city.Object.Id)).Returns(() => city.Object);

            Assert.AreNotEqual(cityService.GetById(city.Object.Id), secondCity.Object);
        }
예제 #7
0
        // GET : City/Edit/{id}
        public ActionResult Edit(int id)
        {
            var city = _cityServices.GetById(id);

            if (city != null)
            {
                var viewModel = new CityViewModel
                {
                    Id   = city.Id,
                    Name = city.Name
                };
                ViewBag.Title = _cityServices.GenerateViewBagTitle(id);

                return(View("CityForm", viewModel));
            }

            return(HttpNotFound("Sorry, looks like invalid city id"));
        }