/// <summary> /// Run-time implementation for getting the identities string from a relationship property. /// </summary> private static IReadOnlyCollection <object> GetStringIdentitiesFromRelationship(IObjectReader reader, string memberName) { try { return(reader.GetStringList(memberName)); } catch (InvalidCastException) { throw new ConnectorRequestException(Messages.ExpectedArrayOfIdentities); } }
/// <summary> /// Read a field that contains a list of strings. /// </summary> public IReadOnlyList <string> GetStringList(string key) { try { if (!_inner.HasKey(key)) { return(null); } return(_inner.GetStringList(key)); } catch (NullReferenceException) { return(null); } }
public void Test_GetStringList(string json, int?expectCount, string expectFirst) { IObjectReader reader = GetReader(json); IReadOnlyList <string> list = reader.GetStringList("a"); if (expectCount == null) { Assert.That(list, Is.Null); return; } else { Assert.That(list.Count, Is.EqualTo(expectCount)); if (expectCount > 0) { Assert.That(list[0], Is.EqualTo(expectFirst)); } } }
public void Test_GetStringList_FormatException(string json) { IObjectReader reader = GetReader(json); Assert.Throws <FormatException>(() => reader.GetStringList("a")); }