public void ThrowsArgumentNullException_When_KeyIsInvalid(string key) { // arrange / act const string data = "Data"; var action = new Action(() => _sut.SetItem(key, data)); // assert Assert.Throws <ArgumentNullException>(action); }
public void ReturnsDeserializedDataFromStore <T>(string key, T data) { // Arrange _sut.SetItem(key, data); // Act var result = _sut.GetItem <T>(key); // Assert Assert.Equal(data, result); }
public void ClearsAnyItemsInTheStore() { // Arrange var item1 = new TestObject(1, "Jane Smith"); var item2 = new TestObject(2, "John Smith"); _sut.SetItem("Item1", item1); _sut.SetItem("Item2", item2); // Act _sut.Clear(); // Assert Assert.Equal(0, _storageProvider.Length()); }
public void ReturnsNumberOfItemsInStore() { // Arrange var item1 = new TestObject(1, "Jane Smith"); var item2 = new TestObject(2, "John Smith"); _sut.SetItem("Item1", item1); _sut.SetItem("Item2", item2); // Act var itemCount = _sut.Length(); // Assert Assert.Equal(2, itemCount); }
public void 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"); _sut.SetItem(key1, item1); _sut.SetItem(key2, item2); // Act var keyName = _sut.Key(1); // Assert Assert.Equal(key2, keyName); }
protected async override Task HandleAsync(LoginAction action, IDispatcher dispatcher) { var userInfo = await api.PostAsyncUnauthorized <UserInfo, LoginInfo>("api/users/login", action.LoginInfo); if (userInfo != null) { await localStorage.SetItem("branch.name", userInfo.BranchName); await localStorage.SetItem("user.name", userInfo.UserName); await localStorage.SetItem("token", userInfo.Token); api.BranchId = new JwToken(userInfo.Token).BranchId; dispatcher.Dispatch(new LoginSuccessAction(userInfo)); uriHelper.NavigateTo("/"); } else { dispatcher.Dispatch(new LoginFailedAction("email or password is incorrect")); } }
public void ReturnsKeysAsync() { // Arrange const string key1 = "TestKey1"; const string key2 = "TestKey2"; _sut.Clear(); var item1 = new TestObject(1, "Jane Smith"); var item2 = new TestObject(2, "John Smith"); _sut.SetItem(key1, item1); _sut.SetItem(key2, item2); // Act var keyNames = _sut.KeysAsync().Result.ToList(); // Assert Assert.Collection(keyNames, item => Assert.Equal(key1, item), item => Assert.Equal(key2, item)); }
public void RemovesItemFromStoreIfExists() { // Arrange var data = new TestObject(2, "Jane Smith"); _sut.SetItem(Key, data); // Act _sut.RemoveItem(Key); // Assert Assert.Equal(0, _storageProvider.Length()); }
public void ReturnsTrue_When_KeyExistsInStore() { // Arrange const string key = "TestKey"; var item1 = new TestObject(1, "Jane Smith"); _sut.SetItem(key, item1); // Act var containsKey = _sut.ContainKey(key); // Assert Assert.True(containsKey); }
public void Should_OverwriteExistingValue() { // Arrange string existingValue = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJBZG1pbmlzdHJhdG9yIiwiZXhwIjoxNTg1NjYwNzEyLCJpc3MiOiJDb2RlUmVkQm9va2luZy5TZXJ2ZXIiLCJhdWQiOiJDb2RlUmVkQm9va2luZy5DbGllbnRzIn0.JhK1M1H7NLCFexujJYCDjTn9La0HloGYADMHXGCFksU"; string newValue = "6QLE0LL7iw7tHPAwold31qUENt3lVTUZxDGqeXQFx38="; _mockJSRuntime.Setup(x => x.Invoke <string>("localStorage.getItem", new[] { _key })) .Returns(() => existingValue); _mockJSRuntime.Setup(x => x.InvokeVoid("localStorage.setItem", new[] { _key, newValue })); // Act _sut.SetItem(_key, newValue); // Assert _mockJSRuntime.Verify(); }
public async ValueTask SetItem(string key, string content) { LocalStorageService.SetItem(key, content); await Task.Delay(1); }