public async Task <bool> CreateBasketProductAsync(int productId, int amount) { await _semaphorePool.WaitAsync(); Dictionary <int, int> productList = null; string productIdsJson = await _localStorageService.GetItemAsStringAsync("productIds"); if (productIdsJson == null) { productList = new Dictionary <int, int>(); productList.Add(productId, amount); await _localStorageService.SetItemAsync("productIds", JsonConvert.SerializeObject(productList)); _semaphorePool.Release(); return(true); } productList = JsonConvert.DeserializeObject <Dictionary <int, int> >(productIdsJson); if (productList.ContainsKey(productId)) { productList.Remove(productId); } productList.Add(productId, amount); await _localStorageService.SetItemAsync("productIds", JsonConvert.SerializeObject(productList)); _semaphorePool.Release(); return(true); }
public void ThrowsArgumentNullException_When_KeyIsInvalid(string key) { // arrange / act const string data = "Data"; var action = new Func <Task>(async() => await _sut.SetItemAsync(key, data)); // assert Assert.ThrowsAsync <ArgumentNullException>(action); }
public async Task ReturnsDeserializedDataFromStore <T>(string key, T data) { // Arrange await _sut.SetItemAsync(key, data); // Act var result = await _sut.GetItemAsync <T>(key); // Assert Assert.Equal(data, result); }
public async Task ClearsAnyItemsInTheStore() { // Arrange var item1 = new TestObject(1, "Jane Smith"); var item2 = new TestObject(2, "John Smith"); await _sut.SetItemAsync("Item1", item1); await _sut.SetItemAsync("Item2", item2); // Act await _sut.ClearAsync(); // Assert Assert.Equal(0, await _storageProvider.LengthAsync()); }
public async Task ReturnsNumberOfItemsInStore() { // Arrange var item1 = new TestObject(1, "Jane Smith"); var item2 = new TestObject(2, "John Smith"); await _sut.SetItemAsync("Item1", item1); await _sut.SetItemAsync("Item2", item2); // Act var itemCount = await _sut.LengthAsync(); // Assert Assert.Equal(2, itemCount); }
private async Task LoadAuthors() { var authors = (await BookStoreService.GetAllAsync("authors")); authors = null; if (authors == null) { var accessToken = await LocalStorageService.GetItemAsync <string>("accessToken"); var refreshToken = await LocalStorageService.GetItemAsync <string>("refreshToken"); var refreshRequest = new RefreshRequest { AccessToken = accessToken, RefreshToken = refreshToken }; var user = (await UserService.RefreshAccessTokenAsync(refreshRequest)) as UserWithToken; if (user != null) { await LocalStorageService.SetItemAsync("accessToken", user.AccessToken); authors = (await BookStoreService.GetAllAsync("authors")); } } Authors = authors != null?authors.OrderByDescending(a => a.AuthorId).ToList() : new List <Author>(); StateHasChanged(); }
protected async Task <string> LoginUser(UserForLoginDto userForLoginDto) { var result = await UserService.LoginAsync(userForLoginDto); var s = result.EnsureSuccessStatusCode(); if (result.StatusCode == System.Net.HttpStatusCode.OK) { try { var content = result.Content.ReadFromJsonAsync <UserForDetailedDto>(); await LocalStorageService.SetItemAsync("User", await content); UserForDetailed = (await content); return(UserForDetailed.Username); var something = System.Text.Json.JsonSerializer.Serialize(content); return(something); } catch (Exception ex) { return(ex.Message); } return("OK"); } else { return(result.StatusCode.ToString()); } }
public async Task Calculate() { if (Result != " ") { _firstnumber = double.Parse(Result); Result = " "; switch (_operand) { case "+": Result = (_secondnumber + _firstnumber).ToString(); break; case "-": Result = (_secondnumber - _firstnumber).ToString(); break; case "*": Result = (_secondnumber * _firstnumber).ToString(); break; case "/": Result = (_secondnumber / _firstnumber).ToString(); break; } } await LocalStorageService.SetItemAsync("Result", Result); await Task.Delay(100); toastService.ShowSuccess("saved Result"); }
public async Task PerformCustomOperation(CustomOperations operation) { if (Result == "" || Result == " ") { return; } double operandmath = double.Parse(Result); switch (operation) { case CustomOperations.Sqrt: Result = Math.Sqrt(operandmath).ToString(); break; case CustomOperations.Sin: Result = Math.Sin(operandmath).ToString(); break; case CustomOperations.Cos: Result = Math.Cos(operandmath).ToString(); break; case CustomOperations.Tan: Result = Math.Tan(operandmath).ToString(); break; case CustomOperations.Log: Result = Math.Log(operandmath).ToString(); break; } await LocalStorageService.SetItemAsync("Result", Result); }
private async Task Prihlasit(OsobaDto neprihlaseny) { // pokud kliknu na přihlášení a následně na změnu termínu, dojde // - ke spuštění volání API pro přihlášení // - k nastavení State.Prihlaseni na null // - a k spuštění volní API pro načtení detailů termínu. // Pokud dojde k dokončení přihlášení před načtením termínu, je již State.Prihlaseni a State.Neprihlaseni null. // Pokud dokde k dokončení přihlášení po načtení termíu, jsou ve State.Prihlaseni a State.Neprihlaseni hodnoty nového termínu. // Takže nemůžeme volat Add/Remove nad State.Prihlaseni. Potřebujeme je volat nad kolekcemi platnými před spuštěním přihlašování. var prihlaseni = State.Prihlaseni; var neprihlaseni = State.Neprihlaseni; await Progress.ExecuteInProgressAsync(async() => await TerminWebApiClient.PrihlasitAsync(State.AktualniTerminId.Value, neprihlaseny.Id)); if (!prihlaseni.Contains(neprihlaseny)) { prihlaseni.Add(neprihlaseny); } neprihlaseni.Remove(neprihlaseny); Toaster.Success($"{neprihlaseny.PrijmeniJmeno} přihlášen(a)."); await LocalStorageService.SetItemAsync("PrefferedOsobaId", neprihlaseny.Id); PrefferedOsobaId = neprihlaseny.Id; }
public async Task ReturnsNameOfKeyAtIndex_When_KeyExistsInStore() { // Arrange const string key1 = "TestKey1"; const string key2 = "TestKey2"; var item1 = new TestObject(1, "Jane Smith"); var item2 = new TestObject(2, "John Smith"); await _sut.SetItemAsync(key1, item1); await _sut.SetItemAsync(key2, item2); // Act var keyName = await _sut.KeyAsync(1); // Assert Assert.Equal(key2, keyName); }
/// <summary> /// Stores the current user token /// </summary> public static async Task StoreToken(LocalStorageService storage) { LocalToken tokenObj = new LocalToken() { Token = UserSecretToken }; await storage.SetItemAsync("token", tokenObj); Console.WriteLine("Stored user token in local storage."); }
public async Task RemovesItemFromStoreIfExists() { // Arrange var data = new TestObject(2, "Jane Smith"); await _sut.SetItemAsync(Key, data); // Act await _sut.RemoveItemAsync(Key); // Assert Assert.Equal(0, await _storageProvider.LengthAsync()); }
public async Task ReturnsTrue_When_KeyExistsInStore() { // Arrange const string key = "TestKey"; var item1 = new TestObject(1, "Jane Smith"); await _sut.SetItemAsync(key, item1); // Act var containsKey = await _sut.ContainKeyAsync(key); // Assert Assert.True(containsKey); }
public async Task Should_OverwriteExistingValue() { // Arrange string existingValue = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJBZG1pbmlzdHJhdG9yIiwiZXhwIjoxNTg1NjYwNzEyLCJpc3MiOiJDb2RlUmVkQm9va2luZy5TZXJ2ZXIiLCJhdWQiOiJDb2RlUmVkQm9va2luZy5DbGllbnRzIn0.JhK1M1H7NLCFexujJYCDjTn9La0HloGYADMHXGCFksU"; string newValue = "6QLE0LL7iw7tHPAwold31qUENt3lVTUZxDGqeXQFx38="; _mockJSRuntime.Setup(x => x.InvokeAsync <string>("localStorage.getItem", new[] { _key })) .Returns(() => new ValueTask <string>(existingValue)); _mockJSRuntime.Setup(x => x.InvokeVoidAsync("localStorage.setItem", new[] { _key, newValue })); // Act await _sut.SetItemAsync(_key, newValue); // Assert _mockJSRuntime.Verify(); }
public async Task <bool> Login(string email, string password) { var loginRequest = new RestRequest(ApiRoutes.Authentication.Login, Method.POST) .AddQueryParameter("Username", email) .AddQueryParameter("Password", password); var response = await client.ExecuteAsync <Response <string> >(loginRequest); if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine(response.Content); return(false); } await _localStorageService.SetItemAsync("token", response.Data.Data); return(true); }
protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (firstRender) { DateTime lastVisit = DateTime.Today.AddDays(-14); if (await LocalStorageService.ContainKeyAsync("LastVisit")) // JS Interop - musíme až do AfterRender { lastVisit = await LocalStorageService.GetItemAsync <DateTime>("LastVisit"); } if ((await NastenkaWebApiClient.GetVzkazyAsync()).Vzkazy.Any(vzkaz => vzkaz.DatumVlozeni > lastVisit)) { ShowNastenkaLink = true; StateHasChanged(); } await LocalStorageService.SetItemAsync("LastVisit", DateTime.Now); await JSRuntime.InvokeVoidAsync("setTitle", "Volejbal - Přihlašování"); } }
public async Task Persist <TState>(TState state) { await LocalStorageService.SetItemAsync(state.GetType().Name, state); }
protected async Task JoinTable() { await LocalStorageService.SetItemAsync("currentTable", Table.Id); NavigationManager.NavigateTo("/Game"); }