public async Task TestRecentLocationUnavailable() { Mock <IWeatherLocationProvider> locationProvider = new Mock <IWeatherLocationProvider>(); Mock <IWeatherProvider> weatherProvider = new Mock <IWeatherProvider>(); WeatherViewModelProvider dataProvider = new WeatherViewModelProvider( locationProvider.Object, weatherProvider.Object); locationProvider.Setup(x => x.GetLastLocation()) .ReturnsAsync(Maybe <WeatherLocation> .None); locationProvider.Setup(x => x.GetLocationUpdates(It.IsAny <System.Action <WeatherLocation> >(), It.IsAny <System.Action>())) .Callback <System.Action <WeatherLocation>, System.Action> ((callback, error) => callback(new WeatherLocation(0.0, 0.0))); weatherProvider.Setup(x => x.GetWeather(It.IsAny <WeatherLocation>())) .ReturnsAsync(new Weather.Weather("Kyiv", null, null)); var weather = await dataProvider.GetWeather(); Assert.AreEqual("Kyiv", weather.Name); Mock.Get(locationProvider.Object).Verify(x => x.GetLastLocation(), Times.Exactly(1)); Mock.Get(locationProvider.Object).Verify(x => x.GetLocationUpdates(It.IsAny <System.Action <WeatherLocation> >(), It.IsAny <System.Action>()), Times.Exactly(1)); Mock.Get(locationProvider.Object).Verify(x => x.CancelLocationUpdates(), Times.Exactly(1)); Mock.Get(weatherProvider.Object).Verify(x => x.GetWeather(It.IsAny <WeatherLocation>()), Times.Exactly(1)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); var iconView = FindViewById <ImageView>(Resource.Id.icon); var nameView = FindViewById <TextView>(Resource.Id.name); var temperatureView = FindViewById <TextView>(Resource.Id.temperature); locationProvider = LocationServices.GetFusedLocationProviderClient(this); var provider = new WeatherViewModelProvider(new LocationProvider(locationProvider), new DefaultWeatherProvider()); var iconConverter = new WeatherIconConverter(); viewModel = new WeatherViewModel(provider, iconConverter); viewModel.DataChanged += data => { nameView.Text = data.Name; temperatureView.Text = $"{Convert.ToInt32(data.Temp)}\u2103"; Drawable icon = null; switch (data.IconType) { case WeatherIcon.CLEAR_SKY_DAY: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.d01, null); break; case WeatherIcon.CLEAR_SKY_NIGHT: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.n01, null); break; case WeatherIcon.FEW_CLOUDS_DAY: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.d02, null); break; case WeatherIcon.FEW_CLOUDS_NIGHT: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.n02, null); break; case WeatherIcon.SCATTERED_CLOUDS: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m03, null); break; case WeatherIcon.BROKEN_CLOUDS: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m04, null); break; case WeatherIcon.SHOWER_RAIN: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m09, null); break; case WeatherIcon.RAIN_DAY: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.d10, null); break; case WeatherIcon.RAIN_NIGHT: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.n10, null); break; case WeatherIcon.THUNDERSTORM: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m11, null); break; case WeatherIcon.SNOW: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m13, null); break; case WeatherIcon.MIST: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m50, null); break; } iconView.SetImageDrawable(icon); }; }