Example #1
0
        public void RemoveKeysAsync()
        {
            // Arrange
            const string key1 = "TestKey1";
            const string key2 = "TestKey2";
            const string key3 = "TestKey3";

            _sut.Clear();

            var item1 = new TestObject(1, "Jane Smith");
            var item2 = new TestObject(2, "John Smith");
            var item3 = new TestObject(3, "Jade Smith");

            _sut.SetItem(key1, item1);
            _sut.SetItem(key2, item2);
            _sut.SetItem(key3, item3);

            // Act
            var keyNames = new string[] { key1, key2 };

            _sut.RemoveItemsAsync(keyNames).AsTask().Wait();

            // Assert
            Assert.Equal(1, _sut.Length());
            Assert.NotNull(_sut.GetItem <TestObject>(key3));
        }
Example #2
0
        public void ThrowsArgumentNullException_When_KeyIsInvalid(string key)
        {
            // arrange / act
            var action = new Action(() => _sut.GetItem <object>(key));

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
Example #3
0
        protected async override Task HandleAsync(CheckLoginAction action, IDispatcher dispatcher)
        {
            var token = await localStorage.GetItem("token");

            if (token != null)
            {
                var jwt = new JwToken(token);
                api.BranchId = jwt.BranchId;
                var branch = await localStorage.GetItem("branch.name");

                var user = await localStorage.GetItem("user.name");

                var userInfo = new UserInfo {
                    Token = token, UserName = user, BranchName = branch
                };

                dispatcher.Dispatch(new LoginSuccessAction(userInfo));
            }
            else
            {
                uriHelper.NavigateTo("/login");
            }
        }
Example #4
0
        public void Should_DeserialiseToCorrectType <T>(T value)
        {
            // Arrange
            var serialisedData = "";

            if (typeof(T) == typeof(string))
            {
                serialisedData = value.ToString();
            }
            else
            {
                serialisedData = JsonSerializer.Serialize(value, _jsonOptions);
            }

            _mockJSRuntime.Setup(x => x.Invoke <string>("localStorage.getItem", new[] { _key }))
            .Returns(() => serialisedData);

            // Act
            var result = _sut.GetItem <T>(_key);

            // Assert
            Assert.Equal(value, result);
            _mockJSRuntime.Verify();
        }