public void CreatesWithMountainAreas()
        {
            var service = new Mock<IMountainWeatherService>();
            var navigator = new Mock<INavigator>();
            var dialogProvder = new Mock<IDialogProvider>();
            var forecastReportViewModel = new Mock<ForecastReportViewModel>();

            Func<Location, MountainAreaViewModel> locationFactory = location => 
                new MountainAreaViewModel(location, navigator.Object, x => forecastReportViewModel.Object);

            var areas = new Location[]
                {
                    new Location { Id = 100, Name = "Area 1" },
                    new Location { Id = 101, Name = "Area 2" },
                    new Location { Id = 102, Name = "Area 3" }
                };

            service.Setup(x => x.GetAreas()).ReturnsAsync(areas);

            var viewModel = new MountainAreasViewModel(service.Object, locationFactory, dialogProvder.Object);

            service.Verify(x => x.GetAreas());

            Assert.That(viewModel.Areas, Is.Not.Null);
            Assert.That(viewModel.Areas.Count(), Is.EqualTo(areas.Length));
        }
        public MountainAreaViewModel(
            Location location, 
            INavigator navigator,
            Func<Location, ForecastReportViewModel> forecastReportViewModelFactory)
        {
            _location = location;
            _navigator = navigator;
            _forecastReportViewModel = forecastReportViewModelFactory(_location);

            ShowForecastCommand = new Command(ShowForecast);
        }
        public ForecastReportViewModel(
            Location location,
            IDialogProvider dialogProvider,
            IMountainWeatherService mountainWeatherService)
        {
            _location = location;
            _dialogProvider = dialogProvider;
            _mountainWeatherService = mountainWeatherService;

            Title = location.Name;
            LoadForecast();
        }
        public void CreatesWithForecast()
        {
            var location = new Location { Id = 100, Name = "Area 1" };
            var service = new MockMountainWeatherService();
            var dialogProvder = new Mock<IDialogProvider>();

            var viewModel = new ForecastReportViewModel(location, dialogProvder.Object, service);
            viewModel.LoadForecast();


            Assert.That(viewModel.Items, Is.Not.Null);
            Assert.That(viewModel.Items.Count(), Is.EqualTo(5));
        }
        public void ShowsForecastWhenShowForecastCommandExecutes()
        {
            var location = new Location { Id = 100, Name = "Area 1" };
            var navigator = new Mock<INavigator>();
            var forecastReportViewModel = new Mock<ForecastReportViewModel>();

            var viewModel = new MountainAreaViewModel(location, navigator.Object, x => forecastReportViewModel.Object);

            Assert.That(viewModel.Name, Is.EqualTo(location.Name));

            viewModel.ShowForecastCommand.Execute(null);

            // add verifications..

        }
        public async Task<IEnumerable<Location>> GetAreas()
        {
//            string result;

//            try
//            {
//                Debug.WriteLine("Getting Locations from DataPoint Service...");
//                result = await Get("txt/wxfcs/mountainarea/json/sitelist");   
//            }
//            catch (Exception ex)
//            {
//                throw new Exception("Failed to get locations from service provider. The service maybe down. Retry or try again later.", ex);
//            }

//            Location[] locations

//            try
//            {                
//                var locationToken = JObject.Parse(result)["Locations"]["Location"];
//
//                locations = locationToken.Select(location => new Location()
//                    { 
//                        Id = (int)location["@id"], 
//                        Name = (string)location["@name"] 
//                    }).ToArray();
//            }
//            catch (Exception ex)
//            {
//                throw new Exception("Failed to format the mountain areas site list.", ex);
//            }

            Location[] locations = new Location[7]
                {
                    new Location { Id = 100, Name = "Brecon Beacons" },
                    new Location { Id = 101, Name = "East Highland" },
                    new Location { Id = 102, Name = "Lake District" },
                    new Location { Id = 103, Name = "Peak District" },
                    new Location { Id = 104, Name = "Snowdonia" },
                    new Location { Id = 105, Name = "West Highland" },
                    new Location { Id = 106, Name = "Yorkshire Dales" }
                };

            return locations;
        }