Esempio n. 1
0
        // GET: Home
        public ActionResult Index(int userId = 1)
        {
            var profile    = _userRepo.GetUserProfile(userId);
            var conditions = _weatherService.GetWeatherForCityAndCountry(profile.CityName, profile.CountryCode);

            var bgColour = _ffProvider.Toggle("weather-background", userId, profile.Name);

            var viewModel = new PersonalWeatherViewModel
            {
                Name               = profile.Name,
                CityName           = conditions.CityName,
                CountryCode        = conditions.CountryCode,
                Temperature        = Math.Round(conditions.Temperature, 1),
                WeatherDescription = conditions.Description,
                Icon               = conditions.IconId,
                BackgroundColor    = bgColour ? ColorTranslator.ToHtml(profile.FavouriteColor) : "#eee"
            };

            return(View(viewModel));
        }
Esempio n. 2
0
        public void ControllerShouldReturnCorrectWeatherInViewModel()
        {
            var userId         = 1;
            var userRepo       = Substitute.For <IUserRepository>();
            var weatherService = Substitute.For <IWeatherService>();
            var ffProvider     = Substitute.For <IFeatureFlagProvider>();

            var expectedUser = new User
            {
                Id          = userId,
                CityName    = "MyCity",
                CountryCode = "AU"
            };
            var expectedWeather = new WeatherConditions
            {
                CountryCode = "AU",
                CityName    = "MyCity",
                Temperature = 20.36f
            };
            var expectedViewModel = new PersonalWeatherViewModel
            {
                CityName    = expectedUser.CityName,
                CountryCode = expectedWeather.CountryCode,
                Temperature = Math.Round(expectedWeather.Temperature, 1)
            };

            ffProvider.Toggle(Arg.Any <string>(), userId, Arg.Any <string>())
            .Returns(false);
            userRepo.GetUserProfile(1)
            .Returns(expectedUser);
            weatherService.GetWeatherForCityAndCountry(expectedUser.CityName, expectedUser.CountryCode)
            .Returns(expectedWeather);

            var controller = new HomeController(userRepo, weatherService, ffProvider);

            var result    = controller.Index(userId) as ViewResult;
            var viewModel = result.Model as PersonalWeatherViewModel;


            viewModel.Temperature.ShouldBeEquivalentTo(expectedViewModel.Temperature);
        }