Exemplo n.º 1
0
        public void Compare()
        {
            var comparer = ComparisonComparer <DateTime> .Create((a, b) => a.Date.Month.CompareTo(b.Date.Month));

            var x = new DateTime(2006, 10, 31);
            var y = new DateTime(2006, 11, 1);

            Assert.IsTrue(comparer.Compare(x, y) < 0);
            Assert.IsTrue(comparer.Compare(y, x) > 0);
            Assert.IsTrue(comparer.Compare(x, x) == 0);
            Assert.ThrowsException <ArgumentNullException>(() => ComparisonComparer <string> .Create(null));
        }
Exemplo n.º 2
0
        public void GetDirectories2()
        {
            string        path = Path.GetTempPath();
            DirectoryInfo di   = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            DirectoryInfo[] actual   = edi.GetDirectories("*", SearchOption.TopDirectoryOnly);
            DirectoryInfo[] expected = di.GetDirectories("*", SearchOption.TopDirectoryOnly);

            CollectionAssert.AreEqual(expected, actual, ComparisonComparer <DirectoryInfo> .Create((a, b) => a.FullName.CompareTo(b.FullName)));

            foreach (DirectoryInfo d in actual)
            {
                Assert.IsTrue(Array.Exists(expected,
                                           delegate(DirectoryInfo o)
                {
                    return(d.FullName == o.FullName);
                }));
            }
        }