public void Test_GetObject_NonNull(string json)
        {
            IObjectReader reader = GetReader(json);
            IObjectReader child  = reader.GetObject("a");

            Assert.That(child, Is.Not.Null);
            Assert.That(child, Is.TypeOf <JilDynamicObjectReader>( ));
            Assert.That(child.GetInt("b"), Is.EqualTo(1));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run-time implementation for getting the identity string from a lookup property.
        /// </summary>
        private static IReadOnlyCollection <object> GetIntIdentityFromLookup(IObjectReader reader, string memberName)
        {
            int?value = reader.GetInt(memberName);

            if (value == null)
            {
                return new string [] { }
            }
            ;
            return(new [] { (object)value.Value });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read an integer field.
        /// </summary>
        public int?GetInt(string key)
        {
            try
            {
                if (!_inner.HasKey(key))
                {
                    return(null);
                }

                return(_inner.GetInt(key));
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public void Test_Scenarios(int rowNum)
        {
            var service = GetService( );
            DataFileReaderSettings settings;

            using (Stream stream = SheetTestHelper.GetStream("TestSheet.xlsx"))     // IMPORTANT: Ensure TestRowNumbers has the right number of rows
            {
                settings = SheetTestHelper.GetSettings(stream, "TestSheet");
                settings.FirstDataRowNumber = rowNum;
            }
            using (Stream stream = SheetTestHelper.GetStream("TestSheet.xlsx"))
                using (IObjectsReader reader = service.OpenDataFile(stream, settings))
                {
                    IObjectReader obj = reader.GetObjects().First();

                    string   actualColRef    = "D";
                    string[] expectedColumns = { "E", "G", "I", "K", "M", "O", "Q" };

                    foreach (string expectedColumn in expectedColumns)
                    {
                        string expectedNative = obj.GetString(expectedColumn);

                        if (string.IsNullOrEmpty(expectedNative))
                        {
                            continue;
                        }

                        switch (expectedColumn)
                        {
                        case "E": // String
                            string actualString     = obj.GetString(actualColRef);
                            string actualSingleLine = StringHelpers.ToSingleLine(actualString);
                            Assert.That(actualSingleLine, Is.EqualTo(expectedNative));
                            break;

                        case "G": // Number
                            int?actualNumber   = obj.GetInt(actualColRef);
                            int expectedNumber = int.Parse(expectedNative, CultureInfo.InvariantCulture);
                            Assert.That(actualNumber, Is.EqualTo(expectedNumber));
                            break;

                        case "I": // Decimal
                            decimal?actualDecimal   = obj.GetDecimal(actualColRef);
                            decimal expectedDecimal = decimal.Parse(expectedNative, CultureInfo.InvariantCulture);
                            Assert.That(actualDecimal, Is.EqualTo(expectedDecimal));
                            break;

                        case "K": // Boolean
                            bool?actualBool   = obj.GetBoolean(actualColRef);
                            bool expectedBool = expectedNative == "Yes" || expectedNative != "No" && bool.Parse(expectedNative);
                            Assert.That(actualBool, Is.EqualTo(expectedBool));
                            break;

                        case "M": // DateTime
                            DateTime?actualDateTime   = obj.GetDateTime(actualColRef);
                            DateTime expectedDateTime = DateTime.Parse(expectedNative, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                            Assert.That(actualDateTime, Is.EqualTo(expectedDateTime));
                            break;

                        case "O": // Date
                            DateTime?actualDate   = obj.GetDate(actualColRef);
                            DateTime expectedDate = DateTime.Parse(expectedNative, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                            Assert.That(actualDate, Is.EqualTo(expectedDate));
                            break;

                        case "Q": // Time
                            DateTime?actualTime   = obj.GetTime(actualColRef);
                            DateTime expectedTime = DateTime.Parse(expectedNative, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                            Assert.That(actualTime, Is.EqualTo(expectedTime));
                            break;
                        }
                    }
                }
        }
        public void Test_GetInt(string json, int?expect)
        {
            IObjectReader reader = GetReader(json);

            Assert.That(reader.GetInt("a"), Is.EqualTo(expect));
        }