예제 #1
0
        public void ProjectionToAnAnonymousType()
        {
            // Required due to defect in MSTest that has the current directory
            // set to the MSTest executable directory, rather than the
            // assembly directory.
            Directory.SetCurrentDirectory(Path.GetDirectoryName(
                                              typeof(Program).GetTypeInfo().Assembly.Location));

            string expectedPattern   = "{ FileName = *, Size = * }";
            int    expectedItemCount = Directory.EnumerateFiles(
                Directory.GetCurrentDirectory(), "*").Count();

            string output = ConsoleAssert.Execute(null, () =>
            {
                Program.Main();
            });

            IEnumerable <string> outputItems = output.Split(
                new string [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.AreEqual(expectedItemCount, outputItems.Count());
            foreach (string item in outputItems)
            {
                Assert.IsTrue(item.IsLike(expectedPattern),
                              $"{item} is not like {expectedPattern}");
            }
        }
        public void Listing14_15_Test()
        {
            // Required due to defect in MSTest that has the current directory
            // set to the MSTest executable directory, rather than the
            // assembly directory.
            Directory.SetCurrentDirectory(Path.GetDirectoryName(
                                              typeof(Program).GetTypeInfo().Assembly.Location));

            //string expectedPattern = $@"{ Directory.GetCurrentDirectory() }{Path.DirectorySeparatorChar}*";
            string expectedPattern   = $@"{ Directory.GetCurrentDirectory() }{ 
                $"{Path.DirectorySeparatorChar}"}*";
            int    expectedItemCount = Directory.EnumerateFiles(
                Directory.GetCurrentDirectory(), "*").Count();
            string output = ConsoleAssert.Execute(null, () =>
            {
                Program.Main();
            });

            IEnumerable <string> outputItems = output.Split(
                new string[] { Environment.NewLine }, StringSplitOptions.None);

            Assert.AreEqual <int>(
                expectedItemCount, outputItems.Count());
            foreach (string item in outputItems)
            {
                Assert.IsTrue(item.IsLike(expectedPattern, '?'));
            }
        }
예제 #3
0
        public void ProjectionWithLinqsSelect()
        {
            string expectedPattern = "{ FileName = *, Size = ";

            string output = ConsoleAssert.Execute(null, () =>
            {
                Program.ChapterMain();
            });

            IEnumerable <string> outputItems = output.Split('\n');

            Assert.AreEqual(14, outputItems.Count());
            foreach (string item in outputItems)
            {
                Assert.IsTrue(item.IsLike(expectedPattern));
            }
        }
        public void ProjectionWithLinqsSelect()
        {
            string expectedPattern   = "{ FileName = *, Size = * }";
            int    expectedItemCount = Directory.EnumerateFiles(
                Directory.GetCurrentDirectory(), "*").Count();
            string output = ConsoleAssert.Execute(null, () =>
            {
                Program.Main();
            });

            IEnumerable <string> outputItems = output.Split(
                new string[] { Environment.NewLine }, StringSplitOptions.None);

            Assert.AreEqual(expectedItemCount, outputItems.Count());
            foreach (string item in outputItems)
            {
                Assert.IsTrue(item.IsLike(expectedPattern),
                              $"{item} is not like {expectedPattern}");
            }
        }