Пример #1
0
        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>());
            }
        }
Пример #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);
        }
Пример #3
0
 public async Task <string> AuthenticationToken()
 {
     return(await _localStorageService.GetItemAsStringAsync("token"));
 }