public void ProjectSourceFileCache_AllKnownProjects()
        {
            ConsoleLogger logger = new ConsoleLogger();

            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                ProjectSourceFileCache cache = new ProjectSourceFileCache("proj", "breadCrumb", logger, projectFileReader);

                cache["p1"] = new string[] { "a", "b" };
                cache["p2"] = new string[] { "c" };

                IEnumerable <string> projects = cache.GetAllKnownProjects();
                Assert.IsNotNull(projects);
                Assert.AreEqual(2, projects.Count());
                Assert.IsTrue(projects.Contains("p1"));
                Assert.IsTrue(projects.Contains("p2"));
            }
        }
        public void ProjectSourceFileCache_Nonexistent_Project_File_Warns()
        {
            ConsoleLogger logger         = new ConsoleLogger();
            string        badProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".csproj");

            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                try
                {
                    ProjectSourceFileCache cache    = new ProjectSourceFileCache(badProjectPath, "breadCrumb", logger, projectFileReader);
                    IEnumerable <string>   projects = cache.GetAllKnownProjects();

                    string warningMessage = string.Format(CultureInfo.CurrentCulture, Resource.Project_Does_Not_Exist, badProjectPath);

                    TestHelper.AssertContainsWarnings(logger, new string[] { warningMessage });
                }
                finally
                {
                    File.Delete(badProjectPath);
                }
            }
        }
        /// <summary>
        /// Helper class to validate the cache contains what we expect it to
        /// contain after loading the real ServerClassLib project
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="projectPath"></param>
        private void ValidateProjectSourceFileCache(ProjectSourceFileCache cache, string projectPath)
        {
            string serverProjectPath  = CodeGenHelper.ServerClassLibProjectPath(projectPath);
            string server2ProjectPath = CodeGenHelper.ServerClassLib2ProjectPath(projectPath);

            string[] expectedServerFiles  = new string[] { "TestEntity.shared.cs" };
            string[] expectedServer2Files = new string[] { "ServerClassLib2.shared.cs" };

            // Ask cache for all known projects.  It should open the .csproj and find project references
            IEnumerable <string> projects = cache.GetAllKnownProjects();

            Assert.IsNotNull(projects);

            // We expect to find ServerClassLib and ServerClassLib2 in the set of known projects.
            // There may be others due to normal project references, but we don't care about them
            Assert.IsTrue(projects.Contains(serverProjectPath), "Expected to find " + serverProjectPath + " in list of known projects");
            Assert.IsTrue(projects.Contains(server2ProjectPath), "Expected to find " + server2ProjectPath + " in list of known projects");

            IEnumerable <string> serverFiles = cache.GetSourceFilesInProject(serverProjectPath);

            Assert.IsNotNull(serverFiles);
            Assert.IsTrue(serverFiles.Count() >= expectedServerFiles.Length);
            foreach (string file in expectedServerFiles)
            {
                string expectedFile = Path.Combine(Path.GetDirectoryName(serverProjectPath), file);
                Assert.IsTrue(serverFiles.Contains(expectedFile), "Expected to see " + expectedFile + " in list of server files");
            }

            IEnumerable <string> server2Files = cache.GetSourceFilesInProject(server2ProjectPath);

            Assert.IsNotNull(server2Files);
            Assert.IsTrue(server2Files.Count() >= expectedServer2Files.Length);
            foreach (string file in expectedServer2Files)
            {
                string expectedFile = Path.Combine(Path.GetDirectoryName(server2ProjectPath), file);
                Assert.IsTrue(server2Files.Contains(expectedFile), "Expected to see " + expectedFile + " in list of server files");
            }
        }
示例#4
0
        public void ProjectSourceFileCache_Bad_Project_File_Warns()
        {
            ConsoleLogger logger = new ConsoleLogger();

            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                string badProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".csproj");
                File.WriteAllText(badProjectPath, "neener neener");

                try
                {
                    ProjectSourceFileCache cache    = new ProjectSourceFileCache(badProjectPath, "breadCrumb", logger, projectFileReader);
                    IEnumerable <string>   projects = cache.GetAllKnownProjects();

                    // Simulate the exception so we get the exact text
                    string warningMessage = TestHelper.GetFailedToOpenProjectMessage(badProjectPath);
                    TestHelper.AssertContainsWarnings(logger, new string[] { warningMessage });
                }
                finally
                {
                    File.Delete(badProjectPath);
                }
            }
        }
        /// <summary>
        /// Helper class to validate the cache contains what we expect it to
        /// contain after loading the real ServerClassLib project
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="projectPath"></param>
        private void ValidateProjectSourceFileCache(ProjectSourceFileCache cache, string projectPath)
        {
            string serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath);
            string server2ProjectPath = CodeGenHelper.ServerClassLib2ProjectPath(projectPath);

            string[] expectedServerFiles = new string[] { "TestEntity.shared.cs" };
            string[] expectedServer2Files = new string[] { "ServerClassLib2.shared.cs" };

            // Ask cache for all known projects.  It should open the .csproj and find project references
            IEnumerable<string> projects = cache.GetAllKnownProjects();
            Assert.IsNotNull(projects);

            // We expect to find ServerClassLib and ServerClassLib2 in the set of known projects.
            // There may be others due to normal project references, but we don't care about them
            Assert.IsTrue(projects.Contains(serverProjectPath), "Expected to find " + serverProjectPath + " in list of known projects");
            Assert.IsTrue(projects.Contains(server2ProjectPath), "Expected to find " + server2ProjectPath + " in list of known projects");

            IEnumerable<string> serverFiles = cache.GetSourceFilesInProject(serverProjectPath);
            Assert.IsNotNull(serverFiles);
            Assert.IsTrue(serverFiles.Count() >= expectedServerFiles.Length);
            foreach (string file in expectedServerFiles)
            {
                string expectedFile = Path.Combine(Path.GetDirectoryName(serverProjectPath), file);
                Assert.IsTrue(serverFiles.Contains(expectedFile), "Expected to see " + expectedFile + " in list of server files");
            }

            IEnumerable<string> server2Files = cache.GetSourceFilesInProject(server2ProjectPath);
            Assert.IsNotNull(server2Files);
            Assert.IsTrue(server2Files.Count() >= expectedServer2Files.Length);
            foreach (string file in expectedServer2Files)
            {
                string expectedFile = Path.Combine(Path.GetDirectoryName(server2ProjectPath), file);
                Assert.IsTrue(server2Files.Contains(expectedFile), "Expected to see " + expectedFile + " in list of server files");
            }

        }
        public void ProjectSourceFileCache_Bad_Project_File_Warns()
        {
            ConsoleLogger logger = new ConsoleLogger();
            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                string badProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".csproj");
                File.WriteAllText(badProjectPath, "neener neener");

                try
                {
                    ProjectSourceFileCache cache = new ProjectSourceFileCache(badProjectPath, "breadCrumb", logger, projectFileReader);
                    IEnumerable<string> projects = cache.GetAllKnownProjects();

                    // Simulate the exception so we get the exact text
                    string warningMessage = null;
                    try
                    {
                        Engine engine = new Engine();
                        Project project = new Project(engine);
                        project.Load(badProjectPath);

                    }
                    catch (InvalidProjectFileException ipfe)
                    {
                        warningMessage = string.Format(CultureInfo.CurrentCulture, Resource.Failed_To_Open_Project, badProjectPath, ipfe.Message);
                    }

                    TestHelper.AssertContainsWarnings(logger, new string[] { warningMessage });

                }
                finally
                {
                    File.Delete(badProjectPath);
                }
            }
        }
        public void ProjectSourceFileCache_Nonexistent_Project_File_Warns()
        {
            ConsoleLogger logger = new ConsoleLogger();
            string badProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".csproj");
            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                try
                {
                    ProjectSourceFileCache cache = new ProjectSourceFileCache(badProjectPath, "breadCrumb", logger, projectFileReader);
                    IEnumerable<string> projects = cache.GetAllKnownProjects();

                    string warningMessage = string.Format(CultureInfo.CurrentCulture, Resource.Project_Does_Not_Exist, badProjectPath);

                    TestHelper.AssertContainsWarnings(logger, new string[] { warningMessage });

                }
                finally
                {
                    File.Delete(badProjectPath);
                }
            }
        }
        public void ProjectSourceFileCache_AllKnownProjects()
        {
            ConsoleLogger logger = new ConsoleLogger();
            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                ProjectSourceFileCache cache = new ProjectSourceFileCache("proj", "breadCrumb", logger, projectFileReader);

                cache["p1"] = new string[] { "a", "b" };
                cache["p2"] = new string[] { "c" };

                IEnumerable<string> projects = cache.GetAllKnownProjects();
                Assert.IsNotNull(projects);
                Assert.AreEqual(2, projects.Count());
                Assert.IsTrue(projects.Contains("p1"));
                Assert.IsTrue(projects.Contains("p2"));
            }
        }