public void SkipShouldTrimDictionary()
        {
            // arrange
            var target = new Dictionary<string, int>()
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 },
                { "Key4", 4 },
                { "Key5", 5 }
            };

            // act
            var actual = target.Skip( "Key2", "Key4" );

            // assert
            Assert.Equal( 3, actual.Count );
            Assert.True( actual.ContainsKey( "Key1" ) );
            Assert.False( actual.ContainsKey( "Key2" ) );
            Assert.True( actual.ContainsKey( "Key3" ) );
            Assert.False( actual.ContainsKey( "Key4" ) );
            Assert.True( actual.ContainsKey( "Key5" ) );
        }
Example #2
0
        public void should_map_non_generic_dictionary_to_generic_enumerable_of_dictionary_entry()
        {
            var results = new Dictionary<string, object>
                {{"oh", 1}, {"hai", 2}}.As<IDictionary>().AsEnumerable();
            results.ShouldTotal(2);

            var result = results.First();
            result.ShouldBeType<DictionaryEntry>();
            result.Key.ShouldEqual("oh");
            result.Value.ShouldEqual(1);

            result = results.Skip(1).First();
            result.ShouldBeType<DictionaryEntry>();
            result.Key.ShouldEqual("hai");
            result.Value.ShouldEqual(2);
        }
Example #3
0
        private static InputFile LoadInputFile(string filePath)
        {
            var fileRowData = new Dictionary<int, IRow>();

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                int index = 0;
                var uploadedExcel = new XSSFWorkbook(fs);
                //get data sheet
                ISheet dataSheet = uploadedExcel.GetSheetAt(0);
                // preload into memory and close the stream
                IEnumerator rowEnumerator = dataSheet.GetEnumerator();
                while (rowEnumerator.MoveNext())
                {
                    fileRowData.Add(index, (IRow) rowEnumerator.Current);
                    index++;
                }
            }
            //take header rows
            List<IRow> header = fileRowData.Take(1).ToList().ConvertAll(x => x.Value);
            //skip header rows
            List<ProductInputRow> productInputRowData =
                fileRowData.Skip(1).ToList().ConvertAll(x => Converter.Convert(x.Value, x.Key, header.Last()))
                    .Where(x => !x.AllStringPropertiesNullOrEmpty())
                    // filter out blanked out data: NPOI reads them as rows
                    .ToList();
            return new InputFile {Header = header, Data = productInputRowData};
        }