Beispiel #1
0
        public void Startup()
        {
            _mockMapperService = new Mock <IMapperService>();

            _mockMapperService
            .Setup(x =>
                   x.Map <IEnumerable <CitySearchResultApiModel> >(It.IsAny <IEnumerable <CitySearchResultDomainModel> >()))
            .Returns(new List <CitySearchResultApiModel>
            {
                new CitySearchResultApiModel
                {
                    Id       = 0,
                    CityName = "Lupeni"
                }
            });


            _mockCitySearchDomainService = new Mock <ICitySearchDomainService>();

            _mockCitySearchDomainService.Setup(x => x.Search("Lupeni"))
            .Returns(new List <CitySearchResultDomainModel>
            {
                new CitySearchResultDomainModel()
                {
                    Id       = 0,
                    CityName = "Lupeni"
                }
            });


            _sutCityController =
                new CitySearchController(_mockMapperService.Object, _mockCitySearchDomainService.Object);
        }
        private void BeforeScenario()
        {
            _exampleCityEntities = new List <City>();

            _mapperService = new MapperService();

            _mockUnitOfWork = new Mock <IUnitOfWork>();
            _mockUnitOfWork.Setup(x => x.Complete()).Verifiable();

            _mockCityRepository = new Mock <IRepository <CityWeatherContainer, City> >();
            _mockCityRepository.Setup(x => x.Read()).Returns(_exampleCityEntities);

            /* todo: check if this would be okay for the specs.
             * thought about mocking this, but I don't think a quick REST call is a problem here;
             * besides specs can be longer running tests that also test integration unlike unit tests.
             * if the 3rd party API changed and broke our system it would be nice to know about it.
             * assuming the tests will be run on a machine with an internet connection. :/
             * in reality I'd check this with the client.
             */

            _countryService = new CountryRestService();
            _weatherService = new WeatherRestService();

            _cityDataService = new CityDataService(_mockCityRepository.Object, _mockUnitOfWork.Object, _mapperService);

            _citySearchDomainService =
                new CitySearchDomainService(_mapperService, _cityDataService, _weatherService, _countryService);

            _citySearchController = new CitySearchController(_mapperService, _citySearchDomainService);
        }