Example #1
0
        public void Chaining_Dictionary()
        {
            var dict = new System.Collections.Generic.Dictionary <int, int> {
                [1] = 2, [3] = 4
            };
            var sortedDict = new System.Collections.Generic.SortedDictionary <int, int> {
                [1] = 2, [3] = 4
            };

            System.Collections.Generic.KeyValuePair <int, int> dictKvp = default(System.Collections.Generic.KeyValuePair <int, int>);
            foreach (var kv in dict)
            {
                dictKvp = kv;
                break;
            }

            System.Collections.Generic.KeyValuePair <int, int> sortedDictKvp = default(System.Collections.Generic.KeyValuePair <int, int>);
            foreach (var kv in sortedDict)
            {
                sortedDictKvp = kv;
                break;
            }

            Assert.AreEqual(dictKvp, dict.First());
            Assert.AreEqual(dictKvp, dict.First(x => true));
            Assert.AreEqual(dictKvp, dict.FirstOrDefault());
            Assert.AreEqual(dictKvp, dict.FirstOrDefault(x => true));
            Assert.AreEqual(sortedDictKvp, sortedDict.First());
            Assert.AreEqual(sortedDictKvp, sortedDict.First(x => true));
            Assert.AreEqual(sortedDictKvp, sortedDict.FirstOrDefault());
            Assert.AreEqual(sortedDictKvp, sortedDict.FirstOrDefault(x => true));
        }
Example #2
0
        public void Chaining_Dictionary()
        {
            var dict = new System.Collections.Generic.Dictionary <int, int> {
                [1] = 2, [3] = 4
            };
            var sortedDict = new System.Collections.Generic.SortedDictionary <int, int> {
                [1] = 2, [3] = 4
            };

            Assert.IsTrue(dict.Contains(dict.First()));
            Assert.IsTrue(dict.Contains(dict.First(), null));
            Assert.IsTrue(sortedDict.Contains(sortedDict.First()));
            Assert.IsTrue(sortedDict.Contains(sortedDict.First(), null));
        }
Example #3
0
        public void Errors_Dictionary()
        {
            var dict = new System.Collections.Generic.Dictionary <int, int> {
                [1] = 2, [3] = 4
            };
            var sortedDict = new System.Collections.Generic.SortedDictionary <int, int> {
                [1] = 2, [3] = 4
            };

            try { dict.First(null); Assert.Fail(); }catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
            try { dict.FirstOrDefault(null); Assert.Fail(); } catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
            try { sortedDict.First(null); Assert.Fail(); } catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
            try { sortedDict.FirstOrDefault(null); Assert.Fail(); } catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
        }
Example #4
0
        public void Chaining_Dictionary()
        {
            var dict = new System.Collections.Generic.Dictionary <int, int> {
                [1] = 2, [3] = 4
            };
            var sortedDict = new System.Collections.Generic.SortedDictionary <int, int> {
                [1] = 2, [3] = 4
            };

            Assert.IsTrue(dict.SequenceEqual(dict.DefaultIfEmpty()));
            Assert.IsTrue(dict.SequenceEqual(dict.DefaultIfEmpty(dict.First())));
            Assert.IsTrue(sortedDict.SequenceEqual(sortedDict.DefaultIfEmpty()));
            Assert.IsTrue(sortedDict.SequenceEqual(sortedDict.DefaultIfEmpty(sortedDict.First())));
        }
Example #5
0
        /// <summary>
        /// This Function delivers the first (means: oldest) VALID file in the list (if checkFileValidity is true).
        /// This flag can be changed to false (or removed) if it is assured that only valid files are deployed in the import folder.
        /// </summary>
        /// <param name="files">List of strings with the filenames</param>
        /// <param name="checkFileValidity">bool. if set to true (default) this will perform a simple validity check.</param>
        /// <returns>string with the oldest file.</returns>
        public static string GetOldestFile(List <string> files)
        {
            SortedDictionary <DateTime?, string> sortedFiles = new System.Collections.Generic.SortedDictionary <DateTime?, string>();

            foreach (string file in files)
            {
                DateTime?date = ParseSenderDate(file);
                if (date == null)
                {
                    continue;
                }
                if (Parser.AxisReader2.CheckFileIsValid(file))
                {
                    sortedFiles.Add(date, file);
                }
            }

            return(sortedFiles.Count > 0 ? sortedFiles.First().Value : null);
        }