Пример #1
0
        public void FindPdbFile_PATHcontainsInvalidChars_ErrorIsLogged()
        {
            TestResources.LoadTests_ReleaseX86.AsFileInfo().Should().Exist();
            string pdb = Path.ChangeExtension(TestResources.LoadTests_ReleaseX86, ".pdb");

            pdb.AsFileInfo().Should().Exist();
            string renamedPdb = $"{pdb}.bak";

            renamedPdb.AsFileInfo().Should().NotExist();

            string pdbFound;
            var    fakeLogger  = new FakeLogger(() => OutputMode.Verbose);
            var    currentPath = Environment.GetEnvironmentVariable("PATH");

            try
            {
                File.Move(pdb, renamedPdb);
                pdb.AsFileInfo().Should().NotExist();

                Environment.SetEnvironmentVariable("PATH", $"My<Invalid>Path;{currentPath}");
                pdbFound = PdbLocator.FindPdbFile(TestResources.LoadTests_ReleaseX86, "", fakeLogger);
            }
            finally
            {
                Environment.SetEnvironmentVariable("PATH", currentPath);
                File.Move(renamedPdb, pdb);
                pdb.AsFileInfo().Should().Exist();
            }

            pdbFound.Should().BeNull();
            fakeLogger.Warnings
            .Should()
            .Contain(msg => msg.Contains("invalid path"));
        }
Пример #2
0
        public void FindPdbFile_ExeWithoutPdb_AttemptsToFindPdbAreLogged()
        {
            TestResources.LoadTests_ReleaseX86.AsFileInfo().Should().Exist();
            string pdb = Path.ChangeExtension(TestResources.LoadTests_ReleaseX86, ".pdb");

            pdb.AsFileInfo().Should().Exist();
            string renamedPdb = $"{pdb}.bak";

            renamedPdb.AsFileInfo().Should().NotExist();

            string pdbFound;
            var    fakeLogger = new FakeLogger(() => OutputMode.Verbose);

            try
            {
                File.Move(pdb, renamedPdb);
                pdb.AsFileInfo().Should().NotExist();

                pdbFound = PdbLocator.FindPdbFile(TestResources.LoadTests_ReleaseX86, "", fakeLogger);
            }
            finally
            {
                File.Move(renamedPdb, pdb);
                pdb.AsFileInfo().Should().Exist();
            }

            pdbFound.Should().BeNull();
            fakeLogger.Infos
            .Should()
            .Contain(msg => msg.Contains("Attempts to find PDB:"));
        }
Пример #3
0
        public void FindPdbFile_ExeWithPdb_FindsPdb()
        {
            string executable = Path.GetFullPath(TestResources.LoadTests_ReleaseX86);

            executable.AsFileInfo().Should().Exist();
            var fakeLogger = new FakeLogger(() => OutputMode.Verbose);

            string pdbFound = PdbLocator.FindPdbFile(executable, "", fakeLogger);

            string pdb = Path.ChangeExtension(executable, ".pdb");

            pdb.AsFileInfo().Should().Exist();
            pdbFound.Should().Be(pdb);
        }
        private void DoResolveTest(string executable, string filter, int expectedLocations, int expectedErrorMessages, bool disposeResolver = true)
        {
            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger(() => OutputMode.Info);

            string       pdb      = PdbLocator.FindPdbFile(executable, "", fakeLogger);
            IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(executable, pdb, fakeLogger);

            locations.AddRange(resolver.GetFunctions(filter));

            if (disposeResolver)
            {
                resolver.Dispose();
            }

            locations.Should().HaveCountGreaterOrEqualTo(expectedLocations);
            fakeLogger.GetMessages(Severity.Warning, Severity.Error).Should().HaveCountGreaterOrEqualTo(expectedErrorMessages);
        }