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)); }
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]")); }
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()); } }