コード例 #1
0
        public void GetAllCities_Should_BeCalledOnce_IfParamsAreValid()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            cityService.GetAllCities();

            mockedRepository.Verify(rep => rep.All(), Times.Once);
        }
コード例 #2
0
        public void GetAllCities_Should_ThrowArgumentNullException_IfPassedAdvertsAreNull()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            IEnumerable <City> expectedCitiesResult = null;

            mockedRepository.Setup(rep => rep.All()).Returns(() => expectedCitiesResult.AsQueryable());

            Assert.Throws <ArgumentNullException>(() => cityService.GetAllCities());
        }
コード例 #3
0
        public void GetAllCities_Should_ReturnEmptyCollection_IfThereAreNoCitiesAdded()
        {
            var mockedRepository = new Mock <IRepository <City> >();
            var cityService      = new CityServices(mockedRepository.Object);

            IEnumerable <City> expectedCitiesResult = new List <City>();

            mockedRepository.Setup(rep => rep.All()).Returns(() => expectedCitiesResult.AsQueryable());

            Assert.IsEmpty(cityService.GetAllCities());
        }
コード例 #4
0
        public void GetAllCities_Should_DoItsJobCorrectly_IfCalled()
        {
            var mockedRepository = new Mock <IRepository <City> >();

            var cityService = new CityServices(mockedRepository.Object);

            IEnumerable <City> expectedCitiesResult = new List <City>()
            {
                new City(), new City()
            };

            mockedRepository.Setup(rep => rep.All()).Returns(() => expectedCitiesResult.AsQueryable());

            Assert.AreEqual(cityService.GetAllCities(), expectedCitiesResult);
        }