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

            // act
            var actual = target.Take( StringComparer.Ordinal, "Key2", "Key4" );

            // assert
            Assert.Equal( 2, actual.Count );
            Assert.False( actual.ContainsKey( "Key1" ) );
            Assert.True( actual.ContainsKey( "Key2" ) );
            Assert.False( actual.ContainsKey( "Key3" ) );
            Assert.True( actual.ContainsKey( "Key4" ) );
            Assert.False( actual.ContainsKey( "Key5" ) );
        }
Example #2
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};
        }
Example #3
0
        static void CreateMetrics()
        {
            int idx = 1;
            string[] units = new string[] { "psi", "gpm", "rpm", "in/min" };
            Dictionary<string, string> tags = new Dictionary<string, string>();
            tags.Add("tag1", "value1");
            tags.Add("tag2", "value2");
            tags.Add("tag3", "value3");
            tags.Add("tag4", "value4");
            tags.Add("tag5", "value5");

            foreach (ServerEnvironment e in _environments)
            {
                foreach (ServerGroup g in e.groups)
                {
                    foreach (ServerItem item in g.items)
                    {
                        Metric metric = new Metric();
                        metric.name = "metric_" + idx;
                        metric.env = e.name;
                        metric.group = g.name;
                        metric.item = item.name;
                        metric.type = item.type;
                        metric.unit = units[new Random().Next(0, units.Length - 1)];
                        metric.persist = new Random().NextDouble() * 100 > 50 ? "true" : "false";

                        metric.tags = tags.Take(new Random().Next(1, tags.Count)).ToDictionary(pair => pair.Key, pair => pair.Value);

                        _metrics.Add(metric);
                        System.Threading.Thread.Sleep(10);

                        idx++;
                    }
                }
            }
        }