示例#1
0
        /// <summary>
        /// Creates a new CreateClientFilesTask instance to use to generate code
        /// </summary>
        /// <param name="relativeTestDir"></param>
        /// <param name="includeClientOutputAssembly">if <c>true</c> include clients own output assembly in analysis</param>
        /// <returns>A new task instance that can be invoked to do code gen</returns>
        public static CreateClientFilesTask CreateClientFilesTaskInstance_CopyClientProjectToOutput(string relativeTestDir, bool includeClientOutputAssembly)
        {
            string deploymentDir = Path.GetDirectoryName(typeof(CodeGenHelper).Assembly.Location);
            string projectPath   = null;
            string outputPath    = null;

            TestHelper.GetProjectPaths(relativeTestDir, out projectPath, out outputPath);

            Assert.IsTrue(File.Exists(projectPath), "Could not locate " + projectPath + " necessary for test.");
            string serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath);
            string clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath);

            return(CodeGenHelper.CreateClientFilesTaskInstance_CopyClientProjectToOutput(serverProjectPath, clientProjectPath, includeClientOutputAssembly));
        }
示例#2
0
        public void PdbReader_Finds_Types_Files()
        {
            string projectPath = null;
            string outputPath  = null;

            TestHelper.GetProjectPaths("PDB", out projectPath, out outputPath);
            string        serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath);
            string        clientProjectPath = CodeGenHelper.ClientClassLibProjectPath(projectPath);
            ConsoleLogger logger            = new ConsoleLogger();
            FilenameMap   filenameMap       = new FilenameMap();

            using (SourceFileLocationService locationService = new SourceFileLocationService(new[] { new PdbSourceFileProviderFactory(/*symbolSearchPath*/ null, logger) }, filenameMap))
            {
                List <string> files = new List <string>(locationService.GetFilesForType(typeof(TestEntity)));
                Assert.AreEqual(4, files.Count);

                CodeGenHelper.AssertContainsFiles(files, serverProjectPath, new string[] { "TestEntity.cs", "TestEntity.shared.cs", "TestEntity.linked.cs" });
                CodeGenHelper.AssertContainsFiles(files, clientProjectPath, new string[] { "TestEntity.reverse.linked.cs" });
            }
        }
        /// <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 PdbReader_Finds_Method_Files()
        {
            string projectPath = null;
            string outputPath  = null;

            TestHelper.GetProjectPaths("PDB", out projectPath, out outputPath);

            using (ISourceFileProvider pdbReader = new PdbSourceFileProviderFactory(/*symbolSearchPath*/ null, /*logger*/ null).CreateProvider())
            {
                string serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath);

                Type         testEntityType = typeof(TestEntity);
                PropertyInfo pInfo          = testEntityType.GetProperty("TheKey");
                Assert.IsNotNull(pInfo);

                // Must find TheKey in only TestEntity.cs -- it is readonly and has no setter
                string actualFile   = pdbReader.GetFileForMember(pInfo.GetGetMethod());
                string expectedFile = Path.Combine(Path.GetDirectoryName(serverProjectPath), "TestEntity.cs");
                Assert.AreEqual(expectedFile.ToUpperInvariant(), actualFile.ToUpperInvariant());

                // Must find TheValue in only TestEntity.cs
                pInfo        = testEntityType.GetProperty("TheValue");
                actualFile   = pdbReader.GetFileForMember(pInfo.GetGetMethod());
                expectedFile = Path.Combine(Path.GetDirectoryName(serverProjectPath), "TestEntity.cs");

                // Must find TheSharedValue in only TestEntity.shared.cs -- validates we locate shared files
                pInfo        = testEntityType.GetProperty("TheSharedValue");
                actualFile   = pdbReader.GetFileForMember(pInfo.GetGetMethod());
                expectedFile = Path.Combine(Path.GetDirectoryName(serverProjectPath), "TestEntity.shared.cs");

                // Must find ServerAndClientValue in only TestEntity.linked.cs -- validates we locate linked files
                pInfo        = testEntityType.GetProperty("ServerAndClientValue");
                actualFile   = pdbReader.GetFileForMember(pInfo.GetGetMethod());
                expectedFile = Path.Combine(Path.GetDirectoryName(serverProjectPath), "TestEntity.linked.cs");
            }
        }
        public void ProjectSourceFileCache_Loads_Real_Project()
        {
            string projectPath = null;
            string outputPath  = null;

            TestHelper.GetProjectPaths("SSFC", out projectPath, out outputPath);
            string        serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath);
            string        breadCrumbFile    = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".txt");
            ConsoleLogger logger            = new ConsoleLogger();

            using (ProjectFileReader projectFileReader = new ProjectFileReader(logger))
            {
                try
                {
                    // Instantiate the cache.
                    ProjectSourceFileCache cache = new ProjectSourceFileCache(serverProjectPath, breadCrumbFile, logger, projectFileReader);

                    // Initially, it will not have loaded anything
                    Assert.AreEqual(0, cache.SourceFilesByProject.Count);

                    // -------------------------------------------------------------
                    // Validate cache is loaded correctly from .csproj files
                    // -------------------------------------------------------------
                    this.ValidateProjectSourceFileCache(cache, projectPath);

                    // Ask to write out the breadcrumb file
                    Assert.IsFalse(File.Exists(breadCrumbFile));
                    bool success = cache.SaveCacheToFile();
                    Assert.IsTrue(success);
                    Assert.IsTrue(File.Exists(breadCrumbFile));

                    // Clear the cache and force it to read from breadcrumb
                    cache.SourceFilesByProject.Clear();

                    success = cache.LoadCacheFromFile();
                    Assert.IsTrue(success, "Failed to load from breadCrumb file");
                    Assert.IsTrue(cache.IsFileCacheCurrent, "Loading from file should have marked cache as current with file.");

                    // -------------------------------------------------------------
                    // Validate cache is loaded correctly from breadcrumb file
                    // -------------------------------------------------------------
                    this.ValidateProjectSourceFileCache(cache, projectPath);

                    // Now mark the breadcrumb file as if it had been written before the ServerClassLib project
                    cache.SourceFilesByProject.Clear();

                    DateTime serverLastWriteTime       = File.GetLastWriteTime(serverProjectPath);
                    DateTime beforeServerLastWriteTime = new DateTime(serverLastWriteTime.Ticks - 1000);
                    File.SetLastWriteTime(breadCrumbFile, beforeServerLastWriteTime);

                    // -------------------------------------------------------------
                    // Validate cache is *not* loaded if timestamp is before project's
                    // -------------------------------------------------------------
                    success = cache.LoadCacheFromFile();
                    Assert.IsFalse(success, "Expected breadCrumbFile time stamp to be caught and reject load");
                    Assert.IsFalse(cache.IsFileCacheCurrent, "Failed load from file should have marked cache as *not* current with file.");

                    // Cache should still be empty
                    Assert.AreEqual(0, cache.SourceFilesByProject.Count);

                    // -------------------------------------------------------------
                    // Validate cache loaded in presence of out-of-date breadcrumb
                    // file loads correctly
                    // -------------------------------------------------------------
                    this.ValidateProjectSourceFileCache(cache, projectPath);

                    Assert.IsFalse(cache.IsFileCacheCurrent, "Loading from project should have marked cache as *not* current with file.");
                }
                finally
                {
                    if (File.Exists(breadCrumbFile))
                    {
                        File.Delete(breadCrumbFile);
                    }
                }
            }
        }