public async Task <IEnumerable <BasketItem> > GetAllBasketProducts()
        {
            try
            {
                await _semaphorePool.WaitAsync();

                Dictionary <int, int> productList = null;

                string productIdsJson = await _localStorageService.GetItemAsStringAsync("productIds");

                if (productIdsJson == null)
                {
                    _semaphorePool.Release();
                    return(Enumerable.Empty <BasketItem>());
                }

                productList = JsonConvert.DeserializeObject <Dictionary <int, int> >(productIdsJson);
                _semaphorePool.Release();

                return(productList.Select(x => new BasketItem()
                {
                    ProductId = x.Key, Amount = x.Value
                }).ToList());
            }
            catch (Exception e)
            {
                return(Enumerable.Empty <BasketItem>());
            }
        }
Exemple #2
0
        public void ThrowsArgumentNullException_When_KeyIsInvalid(string key)
        {
            // arrange / act
            var action = new Func <Task>(async() => await _sut.GetItemAsStringAsync(key));

            // assert
            Assert.ThrowsAsync <ArgumentNullException>(action);
        }
 public async Task <string> AuthenticationToken()
 {
     return(await _localStorageService.GetItemAsStringAsync("token"));
 }