Example #1
0
 /// <summary>
 /// Run-time implementation for getting the identities string from a relationship property.
 /// </summary>
 private static IReadOnlyCollection <object> GetIntIdentitiesFromRelationship(IObjectReader reader, string memberName)
 {
     try
     {
         return(reader.GetIntList(memberName)?.Select(i => ( object )i).ToList( ));
     }
     catch (InvalidCastException)
     {
         throw new ConnectorRequestException(Messages.ExpectedArrayOfIdentities);
     }
 }
        /// <summary>
        /// Read a field that contains a list of integers.
        /// </summary>
        public IReadOnlyList <int> GetIntList(string key)
        {
            try
            {
                if (!_inner.HasKey(key))
                {
                    return(null);
                }

                return(_inner.GetIntList(key));
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
        public void Test_GetIntList(string json, int?expectCount, int expectFirst)
        {
            IObjectReader       reader = GetReader(json);
            IReadOnlyList <int> list   = reader.GetIntList("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_GetIntList_FormatException(string json)
        {
            IObjectReader reader = GetReader(json);

            Assert.Throws <FormatException>(() => reader.GetIntList("a"));
        }