Exemplo n.º 1
0
        public async Task <MovieDetails> GetMovie(long id)
        {
            var          key   = String.Format("movie{0}", id);
            MovieDetails movie = _cacheService.Get <MovieDetails>(key);

            if (movie == null)
            {
                if (_connectivity.EnsureInternetAccess())
                {
                    var uri = ResourceIdentifier.MovieUri(id);
                    try
                    {
                        var responseString = await _httpService.Get(uri);

                        movie = (MovieDetails)_jsonConverter.DeserializeObject(responseString, typeof(MovieDetails));
                        _cacheService.Set(key, movie, CacheExpiry(15.0));
                    }
                    catch
                    {
                        ShowGetFailedNotification();
                        return(new MovieDetails());
                    }
                }
                else
                {
                    ShowConnectionNotification();
                    return(new MovieDetails());
                }
            }

            return(movie);
        }
Exemplo n.º 2
0
        public void MovieUriReturnsProperMovieUri(long id)
        {
            var expectedRegexPattern = @"https://epertuar.azurewebsites.net/api/Movie/\d+";
            var actual = ResourceIdentifier.MovieUri(id);

            Assert.Matches(expectedRegexPattern, actual);
        }
Exemplo n.º 3
0
        public async Task <Movie> GetMovie(long id)
        {
            Movie  movie = null;
            string uri   = ResourceIdentifier.MovieUri(id);

            try
            {
                string dataString = await _httpService.Get(uri);

                movie = (Movie)_converter.FromJson(dataString, typeof(Movie));
            }
            catch
            {
                return(new Movie());
            }

            return(movie);
        }