コード例 #1
0
        public void Deserialize()
        {
            var json = @"[[""user1"",1000],[""user2"",2000]]";
            var ui   = UserIndex.Deserialize(json);

            Assert.NotNull(ui.Data);
            Assert.Collection(ui.Data,
                              AssertEntry("user1", 1000),
                              AssertEntry("user2", 2000));
        }
コード例 #2
0
        public void DeserializeMalformedJson()
        {
            Assert.ThrowsAny <FormatException>(() =>
                                               UserIndex.Deserialize("}"));

            Assert.ThrowsAny <FormatException>(() =>
                                               UserIndex.Deserialize("["));

            Assert.ThrowsAny <FormatException>(() =>
                                               UserIndex.Deserialize("[[true,1000]]"));

            Assert.ThrowsAny <FormatException>(() =>
                                               UserIndex.Deserialize(@"[[""user1"",false]]"));

            Assert.ThrowsAny <FormatException>(() =>
                                               UserIndex.Deserialize("[3]"));
        }
コード例 #3
0
        public UserIndex GetIndex()
        {
            string data = HandleErrorsAndLock(() => _persistentStore.GetValue(_environmentNamespace, EnvironmentMetadataKey));

            if (data is null)
            {
                return(new UserIndex());
            }
            try
            {
                return(UserIndex.Deserialize(data));
            }
            catch (Exception)
            {
                _log.Warn("Discarding invalid data from persistent store index");
                return(new UserIndex());
            }
        }